From: Olivier Lamy Date: Mon, 2 Jul 2012 07:37:52 +0000 (+0000) Subject: add the new module X-Git-Tag: archiva-1.4-M3~577 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b66f289d2b2798f23b3ae7d0151a1c187a62890a;p=archiva.git add the new module git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1356093 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-testutil/pom.xml b/archiva-testutil/pom.xml new file mode 100644 index 000000000..829385fb8 --- /dev/null +++ b/archiva-testutil/pom.xml @@ -0,0 +1,51 @@ + + + + + + org.apache.archiva + archiva + 1.4-M3-SNAPSHOT + + 4.0.0 + archiva-testutil + Archiva :: Test Utility + + + org.springframework + spring-test + + + junit + junit + compile + + + xmlunit + xmlunit + compile + + + org.slf4j + slf4j-simple + compile + + + diff --git a/archiva-testutil/src/main/java/org/apache/archiva/test/ArchivaBlockJUnit4ClassRunner.java b/archiva-testutil/src/main/java/org/apache/archiva/test/ArchivaBlockJUnit4ClassRunner.java new file mode 100644 index 000000000..4a6a2bb23 --- /dev/null +++ b/archiva-testutil/src/main/java/org/apache/archiva/test/ArchivaBlockJUnit4ClassRunner.java @@ -0,0 +1,43 @@ +package org.apache.archiva.test; + +/* + * Copyright 2012 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; + +import java.util.List; + +/** + * @author Eric + */ +public class ArchivaBlockJUnit4ClassRunner + extends BlockJUnit4ClassRunner +{ + + public ArchivaBlockJUnit4ClassRunner( Class klass ) + throws InitializationError + { + super( klass ); + } + + @Override + protected List computeTestMethods() + { + return ListGenerator.getShuffleList( super.computeTestMethods() ); + } +} diff --git a/archiva-testutil/src/main/java/org/apache/archiva/test/ArchivaSpringJUnit4ClassRunner.java b/archiva-testutil/src/main/java/org/apache/archiva/test/ArchivaSpringJUnit4ClassRunner.java new file mode 100644 index 000000000..7dbdebe71 --- /dev/null +++ b/archiva-testutil/src/main/java/org/apache/archiva/test/ArchivaSpringJUnit4ClassRunner.java @@ -0,0 +1,45 @@ +package org.apache.archiva.test; + +/* + * Copyright 2012 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.List; + +/** + * @author Eric + */ +public class ArchivaSpringJUnit4ClassRunner + extends SpringJUnit4ClassRunner +{ + + public ArchivaSpringJUnit4ClassRunner( Class clazz ) + throws InitializationError + { + super( clazz ); + } + + @Override + protected List computeTestMethods() + { + return ListGenerator.getShuffleList( super.computeTestMethods() ); + } + + +} diff --git a/archiva-testutil/src/main/java/org/apache/archiva/test/ListGenerator.java b/archiva-testutil/src/main/java/org/apache/archiva/test/ListGenerator.java new file mode 100644 index 000000000..69ee4e77f --- /dev/null +++ b/archiva-testutil/src/main/java/org/apache/archiva/test/ListGenerator.java @@ -0,0 +1,77 @@ +package org.apache.archiva.test; + +/* + * Copyright 2012 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.junit.runners.model.FrameworkMethod; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * @author Eric + */ +public class ListGenerator +{ + private static int MAXROUND = 1; + + private ListGenerator() + { + } + + static List getShuffleList( List computeTestMethods ) + { + String javaSpecVersion = System.getProperty( "java.specification.version" ); + // 1.6 1.5 version not shuffled to allow build + if ( javaSpecVersion.equals( "1.6" ) || javaSpecVersion.equals( "1.5" ) ) + { + return computeTestMethods; + } + if ( computeTestMethods == null ) + { + return null; + } + List generated = new ArrayList( computeTestMethods ); + + Collections.sort( generated, new FrameworkMethodComparator() ); + + // 1.7 and more generated shuffled list + // double test method to have more change of failure + /*for ( int i = 0; i < MAXROUND; i++ ) + { + Collections.shuffle( computeTestMethods ); + generated.addAll( computeTestMethods ); + }*/ + //generated.add( computeTestMethods.get( 0 ) ); + + //Collections.shuffle( computeTestMethods ); + //generated.addAll( computeTestMethods ); + + return generated; + } + + private static class FrameworkMethodComparator + implements Comparator + { + public int compare( FrameworkMethod frameworkMethod, FrameworkMethod frameworkMethod1 ) + { + return frameworkMethod.getName().compareTo( frameworkMethod1.getName() ); + } + } + +}