diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver')
9 files changed, 865 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java new file mode 100644 index 00000000..aeacfb81 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolutionExceptionTest.java @@ -0,0 +1,64 @@ +package org.apache.maven.artifact.resolver; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +/** + * Test the artifact resolution exception message + * + * @author Mauro Talevi + */ +public class ArtifactResolutionExceptionTest + extends TestCase +{ + private static final String LS = System.getProperty( "line.separator" ); + + public void testMissingArtifactMessageFormat() + { + String message = "Missing artifact"; + String indentation = " "; + String groupId = "aGroupId"; + String artifactId = "anArtifactId"; + String version = "aVersion"; + String type = "jar"; + String classifier = "aClassifier"; + String downloadUrl = "http://somewhere.com/download"; + List path = Arrays.asList( "dependency1", "dependency2" ); + String expected = + "Missing artifact" + LS + LS + " Try downloading the file manually from: " + LS + + " http://somewhere.com/download" + LS + LS + " Then, install it using the command: " + LS + + " mvn install:install-file -DgroupId=aGroupId -DartifactId=anArtifactId -Dversion=aVersion " + + "-Dclassifier=aClassifier -Dpackaging=jar -Dfile=/path/to/file" + LS + LS + + " Alternatively, if you host your own repository you can deploy the file there: " + LS + + " mvn deploy:deploy-file -DgroupId=aGroupId -DartifactId=anArtifactId" + + " -Dversion=aVersion -Dclassifier=aClassifier -Dpackaging=jar -Dfile=/path/to/file" + + " -Durl=[url] -DrepositoryId=[id]" + LS + LS + " Path to dependency: " + LS + " \t1) dependency1" + + LS + " \t2) dependency2" + LS + LS; + String actual = + AbstractArtifactResolutionException.constructMissingArtifactMessage( message, indentation, groupId, + artifactId, version, type, classifier, + downloadUrl, path ); + assertEquals( expected, actual ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java new file mode 100644 index 00000000..117c0e22 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -0,0 +1,283 @@ +package org.apache.maven.artifact.resolver; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.AbstractArtifactComponentTestCase; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; +import org.codehaus.plexus.component.repository.ComponentDescriptor; + +// It would be cool if there was a hook that i could use to setup a test environment. +// I want to setup a local/remote repositories for testing but i don't want to have +// to change them when i change the layout of the repositories. So i want to generate +// the structure i want to test by using the artifact handler manager which dictates +// the layout used for a particular artifact type. + +/** + * @author Jason van Zyl + */ +public class ArtifactResolverTest + extends AbstractArtifactComponentTestCase +{ + private DefaultArtifactResolver artifactResolver; + + private Artifact projectArtifact; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class ); + + projectArtifact = createLocalArtifact( "project", "3.0" ); + } + + @Override + protected void tearDown() + throws Exception + { + artifactFactory = null; + projectArtifact = null; + super.tearDown(); + } + + @Override + protected String component() + { + return "resolver"; + } + + public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() + throws Exception + { + Artifact a = createLocalArtifact( "a", "1.0" ); + + artifactResolver.resolve( a, remoteRepositories(), localRepository() ); + + assertLocalArtifactPresent( a ); + } + + public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository() + throws Exception + { + Artifact b = createRemoteArtifact( "b", "1.0-SNAPSHOT" ); + deleteLocalArtifact( b ); + artifactResolver.resolve( b, remoteRepositories(), localRepository() ); + assertLocalArtifactPresent( b ); + } + + @Override + protected Artifact createArtifact( String groupId, String artifactId, String version, String type ) + throws Exception + { + // for the anonymous classes + return super.createArtifact( groupId, artifactId, version, type ); + } + + public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() + throws Exception + { + Artifact g = createLocalArtifact( "g", "1.0" ); + + Artifact h = createLocalArtifact( "h", "1.0" ); + + ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( g ), projectArtifact, remoteRepositories(), localRepository(), null ); + + printErrors( result ); + + assertEquals( 2, result.getArtifacts().size() ); + + assertTrue( result.getArtifacts().contains( g ) ); + + assertTrue( result.getArtifacts().contains( h ) ); + + assertLocalArtifactPresent( g ); + + assertLocalArtifactPresent( h ); + } + + public void testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository() + throws Exception + { + Artifact i = createRemoteArtifact( "i", "1.0-SNAPSHOT" ); + deleteLocalArtifact( i ); + + Artifact j = createRemoteArtifact( "j", "1.0-SNAPSHOT" ); + deleteLocalArtifact( j ); + + ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( i ), projectArtifact, remoteRepositories(), localRepository(), null ); + + printErrors( result ); + + assertEquals( 2, result.getArtifacts().size() ); + + assertTrue( result.getArtifacts().contains( i ) ); + + assertTrue( result.getArtifacts().contains( j ) ); + + assertLocalArtifactPresent( i ); + + assertLocalArtifactPresent( j ); + } + + public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository() + throws Exception + { + Artifact k = createArtifact( "k", "1.0" ); + + try + { + artifactResolver.resolve( k, remoteRepositories(), localRepository() ); + fail( "Resolution succeeded when it should have failed" ); + } + catch ( ArtifactNotFoundException expected ) + { + assertTrue( true ); + } + } + + public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() + throws Exception + { + Artifact l = createRemoteArtifact( "l", "1.0-SNAPSHOT" ); + deleteLocalArtifact( l ); + + List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>(); + repositories.add( remoteRepository() ); + repositories.add( badRemoteRepository() ); + + artifactResolver.resolve( l, repositories, localRepository() ); + + assertLocalArtifactPresent( l ); + } + + public void testTransitiveResolutionOrder() + throws Exception + { + Artifact m = createLocalArtifact( "m", "1.0" ); + + Artifact n = createLocalArtifact( "n", "1.0" ); + + ArtifactMetadataSource mds = new ArtifactMetadataSource() + { + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactMetadataRetrievalException + { + Set dependencies = new HashSet(); + + return new ResolutionGroup( artifact, dependencies, remoteRepositories ); + } + + public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, + ArtifactRepository localRepository, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactMetadataRetrievalException + { + throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); + } + + public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( + Artifact artifact, + ArtifactRepository localRepository, + ArtifactRepository remoteRepository ) + throws ArtifactMetadataRetrievalException + { + throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); + } + + public ResolutionGroup retrieve( MetadataResolutionRequest request ) + throws ArtifactMetadataRetrievalException + { + return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() ); + } + + public List<ArtifactVersion> retrieveAvailableVersions( MetadataResolutionRequest request ) + throws ArtifactMetadataRetrievalException + { + return retrieveAvailableVersions( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() ); + } + }; + + ArtifactResolutionResult result = null; + + Set set = new LinkedHashSet(); + set.add( n ); + set.add( m ); + + result = + artifactResolver.resolveTransitively( set, projectArtifact, remoteRepositories(), localRepository(), mds ); + + printErrors( result ); + + Iterator i = result.getArtifacts().iterator(); + assertEquals( "n should be first", n, i.next() ); + assertEquals( "m should be second", m, i.next() ); + + // inverse order + set = new LinkedHashSet(); + set.add( m ); + set.add( n ); + + result = + artifactResolver.resolveTransitively( set, projectArtifact, remoteRepositories(), localRepository(), mds ); + + printErrors( result ); + + i = result.getArtifacts().iterator(); + assertEquals( "m should be first", m, i.next() ); + assertEquals( "n should be second", n, i.next() ); + } + + private void printErrors( ArtifactResolutionResult result ) + { + if ( result.hasMissingArtifacts() ) + { + for ( Artifact artifact : result.getMissingArtifacts() ) + { + System.err.println( "Missing: " + artifact ); + } + } + + if ( result.hasExceptions() ) + { + for ( Exception e : result.getExceptions() ) + { + e.printStackTrace(); + } + } + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java new file mode 100644 index 00000000..914d9d1c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactResolverTest.java @@ -0,0 +1,111 @@ +package org.apache.maven.artifact.resolver; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.Collections; + +import org.apache.maven.artifact.AbstractArtifactComponentTestCase; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator; + +public class DefaultArtifactResolverTest + extends AbstractArtifactComponentTestCase +{ + private DefaultArtifactResolver artifactResolver; + + private Artifact projectArtifact; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class ); + + projectArtifact = createLocalArtifact( "project", "3.0" ); + } + + @Override + protected void tearDown() + throws Exception + { + artifactFactory = null; + projectArtifact = null; + super.tearDown(); + } + + @Override + protected String component() + { + return "resolver"; + } + + public void testMNG4738() + throws Exception + { + Artifact g = createLocalArtifact( "g", "1.0" ); + createLocalArtifact( "h", "1.0" ); + artifactResolver.resolveTransitively( Collections.singleton( g ), projectArtifact, remoteRepositories(), + localRepository(), null ); + + // we want to see all top-level thread groups + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + while ( tg.getParent() == null ) + { + tg = tg.getParent(); + } + + ThreadGroup[] tgList = new ThreadGroup[tg.activeGroupCount()]; + tg.enumerate( tgList ); + + boolean seen = false; + + for ( ThreadGroup aTgList : tgList ) + { + if ( !aTgList.getName().equals( DaemonThreadCreator.THREADGROUP_NAME ) ) + { + continue; + } + + seen = true; + + tg = aTgList; + Thread[] ts = new Thread[tg.activeCount()]; + tg.enumerate( ts ); + + for ( Thread active : ts ) + { + String name = active.getName(); + boolean daemon = active.isDaemon(); + assertTrue( name + " is no daemon Thread.", daemon ); + } + + } + + assertTrue( "Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME, seen ); + } + + public void testLookup() + throws Exception + { + ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/TestFileWagon.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/TestFileWagon.java new file mode 100644 index 00000000..c78c1901 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/TestFileWagon.java @@ -0,0 +1,94 @@ +package org.apache.maven.artifact.resolver; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.io.File; +import java.io.InputStream; + +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.apache.maven.wagon.events.TransferListener; +import org.apache.maven.wagon.providers.file.FileWagon; +import org.apache.maven.wagon.resource.Resource; + +/** + * Wagon used for test cases that annotates some methods. Note that this is not a thread-safe implementation. + */ +public class TestFileWagon + extends FileWagon +{ + private TestTransferListener testTransferListener; + private boolean insideGet; + + protected void getTransfer( Resource resource, + File destination, + InputStream input, + boolean closeInput, + int maxSize ) + throws TransferFailedException + { + addTransfer( "getTransfer " + resource.getName() ); + super.getTransfer( resource, destination, input, closeInput, maxSize ); + } + + public void get( String resourceName, File destination ) + throws TransferFailedException, + ResourceDoesNotExistException, + AuthorizationException + { + addTransfer( "get " + resourceName ); + + insideGet = true; + + super.get( resourceName, destination ); + + insideGet = false; + } + + private void addTransfer( String resourceName ) + { + if ( testTransferListener != null ) + { + testTransferListener.addTransfer( resourceName ); + } + } + + public boolean getIfNewer( String resourceName, File destination, long timestamp ) + throws TransferFailedException, + ResourceDoesNotExistException, + AuthorizationException + { + if ( !insideGet ) + { + addTransfer( "getIfNewer " + resourceName ); + } + return super.getIfNewer( resourceName, destination, timestamp ); + } + + public void addTransferListener( TransferListener listener ) + { + if ( listener instanceof TestTransferListener ) + { + testTransferListener = (TestTransferListener) listener; + } + super.addTransferListener( listener ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/TestTransferListener.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/TestTransferListener.java new file mode 100644 index 00000000..afec3ef5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/TestTransferListener.java @@ -0,0 +1,43 @@ +package org.apache.maven.artifact.resolver; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.ArrayList; +import java.util.List; + +import org.apache.maven.wagon.observers.AbstractTransferListener; + +public class TestTransferListener + extends AbstractTransferListener +{ + + private final List<String> transfers = new ArrayList<String>(); + + public List<String> getTransfers() + { + return transfers; + } + + public void addTransfer( String name ) + { + transfers.add( name ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java new file mode 100644 index 00000000..bca112b8 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/AndArtifactFilterTest.java @@ -0,0 +1,62 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.Arrays; + +import org.apache.maven.artifact.Artifact; + +import junit.framework.TestCase; + +/** + * Tests {@link AndArtifactFilter}. + * + * @author Benjamin Bentmann + */ +public class AndArtifactFilterTest + extends TestCase +{ + + private ArtifactFilter newSubFilter() + { + return new ArtifactFilter() + { + public boolean include( Artifact artifact ) + { + return false; + } + }; + } + + public void testEquals() + { + AndArtifactFilter filter1 = new AndArtifactFilter(); + + AndArtifactFilter filter2 = new AndArtifactFilter( Arrays.asList( newSubFilter() ) ); + + assertFalse( filter1.equals( null ) ); + assertTrue( filter1.equals( filter1 ) ); + assertEquals( filter1.hashCode(), filter1.hashCode() ); + + assertFalse( filter1.equals( filter2 ) ); + assertFalse( filter2.equals( filter1 ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java new file mode 100644 index 00000000..fb465663 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/FilterHashEqualsTest.java @@ -0,0 +1,50 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +/** + * @author Igor Fedorenko + */ +public class FilterHashEqualsTest + extends TestCase +{ + + public void testIncludesExcludesArtifactFilter() + { + List<String> patterns = Arrays.asList( "c", "d", "e" ); + + IncludesArtifactFilter f1 = new IncludesArtifactFilter( patterns ); + + IncludesArtifactFilter f2 = new IncludesArtifactFilter( patterns ); + + assertTrue( f1.equals(f2) ); + assertTrue( f2.equals(f1) ); + assertTrue( f1.hashCode() == f2.hashCode() ); + + IncludesArtifactFilter f3 = new IncludesArtifactFilter( Arrays.asList( "d", "c", "e" ) ); + assertTrue( f1.equals( f3 ) ); + assertTrue( f1.hashCode() == f3.hashCode() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java new file mode 100644 index 00000000..e161437f --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/OrArtifactFilterTest.java @@ -0,0 +1,62 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 java.util.Arrays; + +import org.apache.maven.artifact.Artifact; + +import junit.framework.TestCase; + +/** + * Tests {@link OrArtifactFilter}. + * + * @author Benjamin Bentmann + */ +public class OrArtifactFilterTest + extends TestCase +{ + + private ArtifactFilter newSubFilter() + { + return new ArtifactFilter() + { + public boolean include( Artifact artifact ) + { + return false; + } + }; + } + + public void testEquals() + { + OrArtifactFilter filter1 = new OrArtifactFilter(); + + OrArtifactFilter filter2 = new OrArtifactFilter( Arrays.asList( newSubFilter() ) ); + + assertFalse( filter1.equals( null ) ); + assertTrue( filter1.equals( filter1 ) ); + assertEquals( filter1.hashCode(), filter1.hashCode() ); + + assertFalse( filter1.equals( filter2 ) ); + assertFalse( filter2.equals( filter1 ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java new file mode 100644 index 00000000..1a65eca0 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilterTest.java @@ -0,0 +1,96 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; + +import junit.framework.TestCase; + +/** + * Tests {@link ScopeArtifactFilter}. + * + * @author Benjamin Bentmann + */ +public class ScopeArtifactFilterTest + extends TestCase +{ + + private Artifact newArtifact( String scope ) + { + return new DefaultArtifact( "g", "a", "1.0", scope, "jar", "", null ); + } + + public void testInclude_Compile() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE ); + + assertTrue( filter.include( newArtifact( Artifact.SCOPE_COMPILE ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_SYSTEM ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_PROVIDED ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_RUNTIME ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); + } + + public void testInclude_CompilePlusRuntime() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE_PLUS_RUNTIME ); + + assertTrue( filter.include( newArtifact( Artifact.SCOPE_COMPILE ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_SYSTEM ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_PROVIDED ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_RUNTIME ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); + } + + public void testInclude_Runtime() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + + assertTrue( filter.include( newArtifact( Artifact.SCOPE_COMPILE ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_SYSTEM ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_PROVIDED ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_RUNTIME ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); + } + + public void testInclude_RuntimePlusSystem() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM ); + + assertTrue( filter.include( newArtifact( Artifact.SCOPE_COMPILE ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_SYSTEM ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_PROVIDED ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_RUNTIME ) ) ); + assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); + } + + public void testInclude_Test() + { + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_TEST ); + + assertTrue( filter.include( newArtifact( Artifact.SCOPE_COMPILE ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_SYSTEM ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_PROVIDED ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_RUNTIME ) ) ); + assertTrue( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) ); + } + +} |