http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java deleted file mode 100644 index b78838a..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDependencyCollectorTest.java +++ /dev/null @@ -1,569 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.ArtifactProperties; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.collection.CollectResult; -import org.eclipse.aether.collection.DependencyCollectionContext; -import org.eclipse.aether.collection.DependencyCollectionException; -import org.eclipse.aether.collection.DependencyManagement; -import org.eclipse.aether.collection.DependencyManager; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyCycle; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.graph.Exclusion; -import org.eclipse.aether.impl.ArtifactDescriptorReader; -import org.eclipse.aether.internal.test.util.DependencyGraphParser; -import org.eclipse.aether.internal.test.util.TestLoggerFactory; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactDescriptorException; -import org.eclipse.aether.resolution.ArtifactDescriptorRequest; -import org.eclipse.aether.resolution.ArtifactDescriptorResult; -import org.eclipse.aether.util.artifact.ArtifactIdUtils; -import org.eclipse.aether.util.graph.manager.ClassicDependencyManager; -import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; -import org.eclipse.aether.util.graph.version.HighestVersionFilter; -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class DefaultDependencyCollectorTest -{ - - private DefaultDependencyCollector collector; - - private DefaultRepositorySystemSession session; - - private DependencyGraphParser parser; - - private RemoteRepository repository; - - private IniArtifactDescriptorReader newReader( String prefix ) - { - return new IniArtifactDescriptorReader( "artifact-descriptions/" + prefix ); - } - - private Dependency newDep( String coords ) - { - return newDep( coords, "" ); - } - - private Dependency newDep( String coords, String scope ) - { - return new Dependency( new DefaultArtifact( coords ), scope ); - } - - @Before - public void setup() - throws IOException - { - session = TestUtils.newSession(); - - collector = new DefaultDependencyCollector(); - collector.setArtifactDescriptorReader( newReader( "" ) ); - collector.setVersionRangeResolver( new StubVersionRangeResolver() ); - collector.setRemoteRepositoryManager( new StubRemoteRepositoryManager() ); - collector.setLoggerFactory( new TestLoggerFactory() ); - - parser = new DependencyGraphParser( "artifact-descriptions/" ); - - repository = new RemoteRepository.Builder( "id", "default", "file:///" ).build(); - } - - private static void assertEqualSubtree( DependencyNode expected, DependencyNode actual ) - { - assertEqualSubtree( expected, actual, new LinkedList<DependencyNode>() ); - } - - private static void assertEqualSubtree( DependencyNode expected, DependencyNode actual, - LinkedList<DependencyNode> parents ) - { - assertEquals( "path: " + parents, expected.getDependency(), actual.getDependency() ); - - if ( actual.getDependency() != null ) - { - Artifact artifact = actual.getDependency().getArtifact(); - for ( DependencyNode parent : parents ) - { - if ( parent.getDependency() != null && artifact.equals( parent.getDependency().getArtifact() ) ) - { - return; - } - } - } - - parents.addLast( expected ); - - assertEquals( "path: " + parents + ", expected: " + expected.getChildren() + ", actual: " - + actual.getChildren(), expected.getChildren().size(), actual.getChildren().size() ); - - Iterator<DependencyNode> iterator1 = expected.getChildren().iterator(); - Iterator<DependencyNode> iterator2 = actual.getChildren().iterator(); - - while ( iterator1.hasNext() ) - { - assertEqualSubtree( iterator1.next(), iterator2.next(), parents ); - } - - parents.removeLast(); - } - - private Dependency dep( DependencyNode root, int... coords ) - { - return path( root, coords ).getDependency(); - } - - private DependencyNode path( DependencyNode root, int... coords ) - { - try - { - DependencyNode node = root; - for ( int coord : coords ) - { - node = node.getChildren().get( coord ); - } - - return node; - } - catch ( IndexOutOfBoundsException e ) - { - throw new IllegalArgumentException( "Illegal coordinates for child", e ); - } - catch ( NullPointerException e ) - { - throw new IllegalArgumentException( "Illegal coordinates for child", e ); - } - } - - @Test - public void testSimpleCollection() - throws IOException, DependencyCollectionException - { - Dependency dependency = newDep( "gid:aid:ext:ver", "compile" ); - CollectRequest request = new CollectRequest( dependency, Arrays.asList( repository ) ); - CollectResult result = collector.collectDependencies( session, request ); - - assertEquals( 0, result.getExceptions().size() ); - - DependencyNode root = result.getRoot(); - Dependency newDependency = root.getDependency(); - - assertEquals( dependency, newDependency ); - assertEquals( dependency.getArtifact(), newDependency.getArtifact() ); - - assertEquals( 1, root.getChildren().size() ); - - Dependency expect = newDep( "gid:aid2:ext:ver", "compile" ); - assertEquals( expect, root.getChildren().get( 0 ).getDependency() ); - } - - @Test - public void testMissingDependencyDescription() - throws IOException - { - CollectRequest request = - new CollectRequest( newDep( "missing:description:ext:ver" ), Arrays.asList( repository ) ); - try - { - collector.collectDependencies( session, request ); - fail( "expected exception" ); - } - catch ( DependencyCollectionException e ) - { - CollectResult result = e.getResult(); - assertSame( request, result.getRequest() ); - assertNotNull( result.getExceptions() ); - assertEquals( 1, result.getExceptions().size() ); - - assertTrue( result.getExceptions().get( 0 ) instanceof ArtifactDescriptorException ); - - assertEquals( request.getRoot(), result.getRoot().getDependency() ); - } - } - - @Test - public void testDuplicates() - throws IOException, DependencyCollectionException - { - Dependency dependency = newDep( "duplicate:transitive:ext:dependency" ); - CollectRequest request = new CollectRequest( dependency, Arrays.asList( repository ) ); - - CollectResult result = collector.collectDependencies( session, request ); - - assertEquals( 0, result.getExceptions().size() ); - - DependencyNode root = result.getRoot(); - Dependency newDependency = root.getDependency(); - - assertEquals( dependency, newDependency ); - assertEquals( dependency.getArtifact(), newDependency.getArtifact() ); - - assertEquals( 2, root.getChildren().size() ); - - Dependency dep = newDep( "gid:aid:ext:ver", "compile" ); - assertEquals( dep, dep( root, 0 ) ); - - dep = newDep( "gid:aid2:ext:ver", "compile" ); - assertEquals( dep, dep( root, 1 ) ); - assertEquals( dep, dep( root, 0, 0 ) ); - assertEquals( dep( root, 1 ), dep( root, 0, 0 ) ); - } - - @Test - public void testEqualSubtree() - throws IOException, DependencyCollectionException - { - DependencyNode root = parser.parseResource( "expectedSubtreeComparisonResult.txt" ); - Dependency dependency = root.getDependency(); - CollectRequest request = new CollectRequest( dependency, Arrays.asList( repository ) ); - - CollectResult result = collector.collectDependencies( session, request ); - assertEqualSubtree( root, result.getRoot() ); - } - - @Test - public void testCyclicDependencies() - throws Exception - { - DependencyNode root = parser.parseResource( "cycle.txt" ); - CollectRequest request = new CollectRequest( root.getDependency(), Arrays.asList( repository ) ); - CollectResult result = collector.collectDependencies( session, request ); - assertEqualSubtree( root, result.getRoot() ); - } - - @Test - public void testCyclicDependenciesBig() - throws Exception - { - CollectRequest request = new CollectRequest( newDep( "1:2:pom:5.50-SNAPSHOT" ), Arrays.asList( repository ) ); - collector.setArtifactDescriptorReader( newReader( "cycle-big/" ) ); - CollectResult result = collector.collectDependencies( session, request ); - assertNotNull( result.getRoot() ); - // we only care about the performance here, this test must not hang or run out of mem - } - - @Test - public void testCyclicProjects() - throws Exception - { - CollectRequest request = new CollectRequest( newDep( "test:a:2" ), Arrays.asList( repository ) ); - collector.setArtifactDescriptorReader( newReader( "versionless-cycle/" ) ); - CollectResult result = collector.collectDependencies( session, request ); - DependencyNode root = result.getRoot(); - DependencyNode a1 = path( root, 0, 0 ); - assertEquals( "a", a1.getArtifact().getArtifactId() ); - assertEquals( "1", a1.getArtifact().getVersion() ); - for ( DependencyNode child : a1.getChildren() ) - { - assertFalse( "1".equals( child.getArtifact().getVersion() ) ); - } - - assertEquals( 1, result.getCycles().size() ); - DependencyCycle cycle = result.getCycles().get( 0 ); - assertEquals( Arrays.asList(), cycle.getPrecedingDependencies() ); - assertEquals( Arrays.asList( root.getDependency(), path( root, 0 ).getDependency(), a1.getDependency() ), - cycle.getCyclicDependencies() ); - } - - @Test - public void testCyclicProjects_ConsiderLabelOfRootlessGraph() - throws Exception - { - Dependency dep = newDep( "gid:aid:ver", "compile" ); - CollectRequest request = - new CollectRequest().addDependency( dep ).addRepository( repository ).setRootArtifact( dep.getArtifact() ); - CollectResult result = collector.collectDependencies( session, request ); - DependencyNode root = result.getRoot(); - DependencyNode a1 = root.getChildren().get( 0 ); - assertEquals( "aid", a1.getArtifact().getArtifactId() ); - assertEquals( "ver", a1.getArtifact().getVersion() ); - DependencyNode a2 = a1.getChildren().get( 0 ); - assertEquals( "aid2", a2.getArtifact().getArtifactId() ); - assertEquals( "ver", a2.getArtifact().getVersion() ); - - assertEquals( 1, result.getCycles().size() ); - DependencyCycle cycle = result.getCycles().get( 0 ); - assertEquals( Arrays.asList(), cycle.getPrecedingDependencies() ); - assertEquals( Arrays.asList( new Dependency( dep.getArtifact(), null ), a1.getDependency() ), - cycle.getCyclicDependencies() ); - } - - @Test - public void testPartialResultOnError() - throws IOException - { - DependencyNode root = parser.parseResource( "expectedPartialSubtreeOnError.txt" ); - - Dependency dependency = root.getDependency(); - CollectRequest request = new CollectRequest( dependency, Arrays.asList( repository ) ); - - CollectResult result; - try - { - result = collector.collectDependencies( session, request ); - fail( "expected exception " ); - } - catch ( DependencyCollectionException e ) - { - result = e.getResult(); - - assertSame( request, result.getRequest() ); - assertNotNull( result.getExceptions() ); - assertEquals( 1, result.getExceptions().size() ); - - assertTrue( result.getExceptions().get( 0 ) instanceof ArtifactDescriptorException ); - - assertEqualSubtree( root, result.getRoot() ); - } - } - - @Test - public void testCollectMultipleDependencies() - throws IOException, DependencyCollectionException - { - Dependency root1 = newDep( "gid:aid:ext:ver", "compile" ); - Dependency root2 = newDep( "gid:aid2:ext:ver", "compile" ); - List<Dependency> dependencies = Arrays.asList( root1, root2 ); - CollectRequest request = new CollectRequest( dependencies, null, Arrays.asList( repository ) ); - CollectResult result = collector.collectDependencies( session, request ); - - assertEquals( 0, result.getExceptions().size() ); - assertEquals( 2, result.getRoot().getChildren().size() ); - assertEquals( root1, dep( result.getRoot(), 0 ) ); - - assertEquals( 1, path( result.getRoot(), 0 ).getChildren().size() ); - assertEquals( root2, dep( result.getRoot(), 0, 0 ) ); - - assertEquals( 0, path( result.getRoot(), 1 ).getChildren().size() ); - assertEquals( root2, dep( result.getRoot(), 1 ) ); - } - - @Test - public void testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion() - throws Exception - { - RemoteRepository repo2 = new RemoteRepository.Builder( "test", "default", "file:///" ).build(); - - final List<RemoteRepository> repos = new ArrayList<RemoteRepository>(); - - collector.setArtifactDescriptorReader( new ArtifactDescriptorReader() - { - public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session, - ArtifactDescriptorRequest request ) - throws ArtifactDescriptorException - { - repos.addAll( request.getRepositories() ); - return new ArtifactDescriptorResult( request ); - } - } ); - - List<Dependency> dependencies = Arrays.asList( newDep( "verrange:parent:jar:1[1,)", "compile" ) ); - CollectRequest request = new CollectRequest( dependencies, null, Arrays.asList( repository, repo2 ) ); - CollectResult result = collector.collectDependencies( session, request ); - - assertEquals( 0, result.getExceptions().size() ); - assertEquals( 2, repos.size() ); - assertEquals( "id", repos.get( 0 ).getId() ); - assertEquals( "test", repos.get( 1 ).getId() ); - } - - @Test - public void testManagedVersionScope() - throws IOException, DependencyCollectionException - { - Dependency dependency = newDep( "managed:aid:ext:ver" ); - CollectRequest request = new CollectRequest( dependency, Arrays.asList( repository ) ); - - session.setDependencyManager( new ClassicDependencyManager() ); - - CollectResult result = collector.collectDependencies( session, request ); - - assertEquals( 0, result.getExceptions().size() ); - - DependencyNode root = result.getRoot(); - - assertEquals( dependency, dep( root ) ); - assertEquals( dependency.getArtifact(), dep( root ).getArtifact() ); - - assertEquals( 1, root.getChildren().size() ); - Dependency expect = newDep( "gid:aid:ext:ver", "compile" ); - assertEquals( expect, dep( root, 0 ) ); - - assertEquals( 1, path( root, 0 ).getChildren().size() ); - expect = newDep( "gid:aid2:ext:managedVersion", "managedScope" ); - assertEquals( expect, dep( root, 0, 0 ) ); - } - - @Test - public void testDependencyManagement() - throws IOException, DependencyCollectionException - { - collector.setArtifactDescriptorReader( newReader( "managed/" ) ); - - DependencyNode root = parser.parseResource( "expectedSubtreeComparisonResult.txt" ); - TestDependencyManager depMgmt = new TestDependencyManager(); - depMgmt.add( dep( root, 0 ), "managed", null, null ); - depMgmt.add( dep( root, 0, 1 ), "managed", "managed", null ); - depMgmt.add( dep( root, 1 ), null, null, "managed" ); - session.setDependencyManager( depMgmt ); - - // collect result will differ from expectedSubtreeComparisonResult.txt - // set localPath -> no dependency traversal - CollectRequest request = new CollectRequest( dep( root ), Arrays.asList( repository ) ); - CollectResult result = collector.collectDependencies( session, request ); - - DependencyNode node = result.getRoot(); - assertEquals( "managed", dep( node, 0, 1 ).getArtifact().getVersion() ); - assertEquals( "managed", dep( node, 0, 1 ).getScope() ); - - assertEquals( "managed", dep( node, 1 ).getArtifact().getProperty( ArtifactProperties.LOCAL_PATH, null ) ); - assertEquals( "managed", dep( node, 0, 0 ).getArtifact().getProperty( ArtifactProperties.LOCAL_PATH, null ) ); - } - - @Test - public void testDependencyManagement_VerboseMode() - throws Exception - { - String depId = "gid:aid2:ext"; - TestDependencyManager depMgmt = new TestDependencyManager(); - depMgmt.version( depId, "managedVersion" ); - depMgmt.scope( depId, "managedScope" ); - depMgmt.optional( depId, Boolean.TRUE ); - depMgmt.path( depId, "managedPath" ); - depMgmt.exclusions( depId, new Exclusion( "gid", "aid", "*", "*" ) ); - session.setDependencyManager( depMgmt ); - session.setConfigProperty( DependencyManagerUtils.CONFIG_PROP_VERBOSE, Boolean.TRUE ); - - CollectRequest request = new CollectRequest().setRoot( newDep( "gid:aid:ver" ) ); - CollectResult result = collector.collectDependencies( session, request ); - DependencyNode node = result.getRoot().getChildren().get( 0 ); - assertEquals( DependencyNode.MANAGED_VERSION | DependencyNode.MANAGED_SCOPE | DependencyNode.MANAGED_OPTIONAL - | DependencyNode.MANAGED_PROPERTIES | DependencyNode.MANAGED_EXCLUSIONS, node.getManagedBits() ); - assertEquals( "ver", DependencyManagerUtils.getPremanagedVersion( node ) ); - assertEquals( "compile", DependencyManagerUtils.getPremanagedScope( node ) ); - assertEquals( Boolean.FALSE, DependencyManagerUtils.getPremanagedOptional( node ) ); - } - - @Test - public void testVersionFilter() - throws Exception - { - session.setVersionFilter( new HighestVersionFilter() ); - CollectRequest request = new CollectRequest().setRoot( newDep( "gid:aid:1" ) ); - CollectResult result = collector.collectDependencies( session, request ); - assertEquals( 1, result.getRoot().getChildren().size() ); - } - - static class TestDependencyManager - implements DependencyManager - { - - private Map<String, String> versions = new HashMap<String, String>(); - - private Map<String, String> scopes = new HashMap<String, String>(); - - private Map<String, Boolean> optionals = new HashMap<String, Boolean>(); - - private Map<String, String> paths = new HashMap<String, String>(); - - private Map<String, Collection<Exclusion>> exclusions = new HashMap<String, Collection<Exclusion>>(); - - public void add( Dependency d, String version, String scope, String localPath ) - { - String id = toKey( d ); - version( id, version ); - scope( id, scope ); - path( id, localPath ); - } - - public void version( String id, String version ) - { - versions.put( id, version ); - } - - public void scope( String id, String scope ) - { - scopes.put( id, scope ); - } - - public void optional( String id, Boolean optional ) - { - optionals.put( id, optional ); - } - - public void path( String id, String path ) - { - paths.put( id, path ); - } - - public void exclusions( String id, Exclusion... exclusions ) - { - this.exclusions.put( id, exclusions != null ? Arrays.asList( exclusions ) : null ); - } - - public DependencyManagement manageDependency( Dependency d ) - { - String id = toKey( d ); - DependencyManagement mgmt = new DependencyManagement(); - mgmt.setVersion( versions.get( id ) ); - mgmt.setScope( scopes.get( id ) ); - mgmt.setOptional( optionals.get( id ) ); - String path = paths.get( id ); - if ( path != null ) - { - mgmt.setProperties( Collections.singletonMap( ArtifactProperties.LOCAL_PATH, path ) ); - } - mgmt.setExclusions( exclusions.get( id ) ); - return mgmt; - } - - private String toKey( Dependency dependency ) - { - return ArtifactIdUtils.toVersionlessId( dependency.getArtifact() ); - } - - public DependencyManager deriveChildManager( DependencyCollectionContext context ) - { - return this; - } - - } - -}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDeployerTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDeployerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDeployerTest.java deleted file mode 100644 index 9465e87..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultDeployerTest.java +++ /dev/null @@ -1,385 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositoryEvent; -import org.eclipse.aether.RepositoryEvent.EventType; -import org.eclipse.aether.RepositoryException; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.deployment.DeployRequest; -import org.eclipse.aether.deployment.DeploymentException; -import org.eclipse.aether.internal.impl.DefaultDeployer; -import org.eclipse.aether.internal.test.util.TestFileProcessor; -import org.eclipse.aether.internal.test.util.TestFileUtils; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.eclipse.aether.metadata.DefaultMetadata; -import org.eclipse.aether.metadata.MergeableMetadata; -import org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.metadata.Metadata.Nature; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.spi.connector.ArtifactDownload; -import org.eclipse.aether.spi.connector.ArtifactUpload; -import org.eclipse.aether.spi.connector.MetadataDownload; -import org.eclipse.aether.spi.connector.MetadataUpload; -import org.eclipse.aether.spi.connector.RepositoryConnector; -import org.eclipse.aether.transfer.MetadataNotFoundException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class DefaultDeployerTest -{ - - private Artifact artifact; - - private DefaultMetadata metadata; - - private DefaultRepositorySystemSession session; - - private StubRepositoryConnectorProvider connectorProvider; - - private DefaultDeployer deployer; - - private DeployRequest request; - - private RecordingRepositoryConnector connector; - - private RecordingRepositoryListener listener; - - @Before - public void setup() - throws IOException - { - artifact = new DefaultArtifact( "gid", "aid", "jar", "ver" ); - artifact = artifact.setFile( TestFileUtils.createTempFile( "artifact" ) ); - metadata = - new DefaultMetadata( "gid", "aid", "ver", "type", Nature.RELEASE_OR_SNAPSHOT, - TestFileUtils.createTempFile( "metadata" ) ); - - session = TestUtils.newSession(); - connectorProvider = new StubRepositoryConnectorProvider(); - - deployer = new DefaultDeployer(); - deployer.setRepositoryConnectorProvider( connectorProvider ); - deployer.setRemoteRepositoryManager( new StubRemoteRepositoryManager() ); - deployer.setRepositoryEventDispatcher( new StubRepositoryEventDispatcher() ); - deployer.setUpdateCheckManager( new StaticUpdateCheckManager( true ) ); - deployer.setFileProcessor( new TestFileProcessor() ); - deployer.setSyncContextFactory( new StubSyncContextFactory() ); - deployer.setOfflineController( new DefaultOfflineController() ); - - request = new DeployRequest(); - request.setRepository( new RemoteRepository.Builder( "id", "default", "file:///" ).build() ); - connector = new RecordingRepositoryConnector( session ); - connectorProvider.setConnector( connector ); - - listener = new RecordingRepositoryListener(); - session.setRepositoryListener( listener ); - } - - @After - public void teardown() - throws Exception - { - if ( session.getLocalRepository() != null ) - { - TestFileUtils.deleteFile( session.getLocalRepository().getBasedir() ); - } - session = null; - listener = null; - connector = null; - connectorProvider = null; - deployer = null; - } - - @Test - public void testSuccessfulDeploy() - throws DeploymentException - { - - connector.setExpectPut( artifact ); - connector.setExpectPut( metadata ); - - request.addArtifact( artifact ); - request.addMetadata( metadata ); - - deployer.deploy( session, request ); - - connector.assertSeenExpected(); - } - - @Test( expected = DeploymentException.class ) - public void testNullArtifactFile() - throws DeploymentException - { - request.addArtifact( artifact.setFile( null ) ); - deployer.deploy( session, request ); - } - - @Test( expected = DeploymentException.class ) - public void testNullMetadataFile() - throws DeploymentException - { - request.addArtifact( artifact.setFile( null ) ); - deployer.deploy( session, request ); - } - - @Test - public void testSuccessfulArtifactEvents() - throws DeploymentException - { - request.addArtifact( artifact ); - - deployer.deploy( session, request ); - - List<RepositoryEvent> events = listener.getEvents(); - assertEquals( 2, events.size() ); - - RepositoryEvent event = events.get( 0 ); - assertEquals( EventType.ARTIFACT_DEPLOYING, event.getType() ); - assertEquals( artifact, event.getArtifact() ); - assertNull( event.getException() ); - - event = events.get( 1 ); - assertEquals( EventType.ARTIFACT_DEPLOYED, event.getType() ); - assertEquals( artifact, event.getArtifact() ); - assertNull( event.getException() ); - } - - @Test - public void testFailingArtifactEvents() - { - connector.fail = true; - - request.addArtifact( artifact ); - - try - { - deployer.deploy( session, request ); - fail( "expected exception" ); - } - catch ( DeploymentException e ) - { - List<RepositoryEvent> events = listener.getEvents(); - assertEquals( 2, events.size() ); - - RepositoryEvent event = events.get( 0 ); - assertEquals( EventType.ARTIFACT_DEPLOYING, event.getType() ); - assertEquals( artifact, event.getArtifact() ); - assertNull( event.getException() ); - - event = events.get( 1 ); - assertEquals( EventType.ARTIFACT_DEPLOYED, event.getType() ); - assertEquals( artifact, event.getArtifact() ); - assertNotNull( event.getException() ); - } - } - - @Test - public void testSuccessfulMetadataEvents() - throws DeploymentException - { - request.addMetadata( metadata ); - - deployer.deploy( session, request ); - - List<RepositoryEvent> events = listener.getEvents(); - assertEquals( 2, events.size() ); - - RepositoryEvent event = events.get( 0 ); - assertEquals( EventType.METADATA_DEPLOYING, event.getType() ); - assertEquals( metadata, event.getMetadata() ); - assertNull( event.getException() ); - - event = events.get( 1 ); - assertEquals( EventType.METADATA_DEPLOYED, event.getType() ); - assertEquals( metadata, event.getMetadata() ); - assertNull( event.getException() ); - } - - @Test - public void testFailingMetdataEvents() - { - connector.fail = true; - - request.addMetadata( metadata ); - - try - { - deployer.deploy( session, request ); - fail( "expected exception" ); - } - catch ( DeploymentException e ) - { - List<RepositoryEvent> events = listener.getEvents(); - assertEquals( 2, events.size() ); - - RepositoryEvent event = events.get( 0 ); - assertEquals( EventType.METADATA_DEPLOYING, event.getType() ); - assertEquals( metadata, event.getMetadata() ); - assertNull( event.getException() ); - - event = events.get( 1 ); - assertEquals( EventType.METADATA_DEPLOYED, event.getType() ); - assertEquals( metadata, event.getMetadata() ); - assertNotNull( event.getException() ); - } - } - - @Test - public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() - throws Exception - { - MergeableMetadata metadata = new MergeableMetadata() - { - - public Metadata setFile( File file ) - { - return this; - } - - public String getVersion() - { - return ""; - } - - public String getType() - { - return "test.properties"; - } - - public Nature getNature() - { - return Nature.RELEASE; - } - - public String getGroupId() - { - return "org"; - } - - public File getFile() - { - return null; - } - - public String getArtifactId() - { - return "aether"; - } - - public Metadata setProperties( Map<String, String> properties ) - { - return this; - } - - public Map<String, String> getProperties() - { - return Collections.emptyMap(); - } - - public String getProperty( String key, String defaultValue ) - { - return defaultValue; - } - - public void merge( File current, File result ) - throws RepositoryException - { - Properties props = new Properties(); - - try - { - if ( current.isFile() ) - { - TestFileUtils.readProps( current, props ); - } - - props.setProperty( "new", "value" ); - - TestFileUtils.writeProps( result, props ); - } - catch ( IOException e ) - { - throw new RepositoryException( e.getMessage(), e ); - } - } - - public boolean isMerged() - { - return false; - } - }; - - connectorProvider.setConnector( new RepositoryConnector() - { - - public void put( Collection<? extends ArtifactUpload> artifactUploads, - Collection<? extends MetadataUpload> metadataUploads ) - { - } - - public void get( Collection<? extends ArtifactDownload> artifactDownloads, - Collection<? extends MetadataDownload> metadataDownloads ) - { - if ( metadataDownloads != null ) - { - for ( MetadataDownload download : metadataDownloads ) - { - download.setException( new MetadataNotFoundException( download.getMetadata(), null, null ) ); - } - } - } - - public void close() - { - } - } ); - - request.addMetadata( metadata ); - - File metadataFile = - new File( session.getLocalRepository().getBasedir(), - session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, request.getRepository(), - "" ) ); - Properties props = new Properties(); - props.setProperty( "old", "value" ); - TestFileUtils.writeProps( metadataFile, props ); - - deployer.deploy( session, request ); - - props = new Properties(); - TestFileUtils.readProps( metadataFile, props ); - assertNull( props.toString(), props.get( "old" ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java deleted file mode 100644 index 3f8ab5e..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultFileProcessorTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicInteger; - -import org.eclipse.aether.internal.impl.DefaultFileProcessor; -import org.eclipse.aether.internal.test.util.TestFileUtils; -import org.eclipse.aether.spi.io.FileProcessor.ProgressListener; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class DefaultFileProcessorTest -{ - - private File targetDir; - - private DefaultFileProcessor fileProcessor; - - @Before - public void setup() - throws IOException - { - targetDir = TestFileUtils.createTempDir( getClass().getSimpleName() ); - fileProcessor = new DefaultFileProcessor(); - } - - @After - public void teardown() - throws Exception - { - TestFileUtils.deleteFile( targetDir ); - fileProcessor = null; - } - - @Test - public void testCopy() - throws IOException - { - String data = "testCopy\nasdf"; - File file = TestFileUtils.createTempFile( data ); - File target = new File( targetDir, "testCopy.txt" ); - - fileProcessor.copy( file, target ); - - assertEquals( data, TestFileUtils.readString( file ) ); - - file.delete(); - } - - @Test - public void testOverwrite() - throws IOException - { - String data = "testCopy\nasdf"; - File file = TestFileUtils.createTempFile( data ); - - for ( int i = 0; i < 5; i++ ) - { - File target = new File( targetDir, "testCopy.txt" ); - fileProcessor.copy( file, target ); - assertEquals( data, TestFileUtils.readString( file ) ); - } - - file.delete(); - } - - @Test - public void testCopyEmptyFile() - throws IOException - { - File file = TestFileUtils.createTempFile( "" ); - File target = new File( targetDir, "testCopyEmptyFile" ); - target.delete(); - fileProcessor.copy( file, target ); - assertTrue( "empty file was not copied", target.exists() && target.length() == 0 ); - target.delete(); - } - - @Test - public void testProgressingChannel() - throws IOException - { - File file = TestFileUtils.createTempFile( "test" ); - File target = new File( targetDir, "testProgressingChannel" ); - target.delete(); - final AtomicInteger progressed = new AtomicInteger(); - ProgressListener listener = new ProgressListener() - { - public void progressed( ByteBuffer buffer ) - throws IOException - { - progressed.addAndGet( buffer.remaining() ); - } - }; - fileProcessor.copy( file, target, listener ); - assertTrue( "file was not created", target.isFile() ); - assertEquals( "file was not fully copied", 4, target.length() ); - assertEquals( "listener not called", 4, progressed.intValue() ); - target.delete(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java deleted file mode 100644 index 99d57bc..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java +++ /dev/null @@ -1,414 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.List; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositoryEvent; -import org.eclipse.aether.RepositoryEvent.EventType; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.installation.InstallRequest; -import org.eclipse.aether.installation.InstallResult; -import org.eclipse.aether.installation.InstallationException; -import org.eclipse.aether.internal.impl.DefaultFileProcessor; -import org.eclipse.aether.internal.impl.DefaultInstaller; -import org.eclipse.aether.internal.test.util.TestFileProcessor; -import org.eclipse.aether.internal.test.util.TestFileUtils; -import org.eclipse.aether.internal.test.util.TestLocalRepositoryManager; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.eclipse.aether.metadata.DefaultMetadata; -import org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.metadata.Metadata.Nature; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class DefaultInstallerTest -{ - - private Artifact artifact; - - private Metadata metadata; - - private DefaultRepositorySystemSession session; - - private String localArtifactPath; - - private String localMetadataPath; - - private DefaultInstaller installer; - - private InstallRequest request; - - private RecordingRepositoryListener listener; - - private File localArtifactFile; - - private TestLocalRepositoryManager lrm; - - @Before - public void setup() - throws IOException - { - artifact = new DefaultArtifact( "gid", "aid", "jar", "ver" ); - artifact = artifact.setFile( TestFileUtils.createTempFile( "artifact".getBytes(), 1 ) ); - metadata = - new DefaultMetadata( "gid", "aid", "ver", "type", Nature.RELEASE_OR_SNAPSHOT, - TestFileUtils.createTempFile( "metadata".getBytes(), 1 ) ); - - session = TestUtils.newSession(); - localArtifactPath = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact ); - localMetadataPath = session.getLocalRepositoryManager().getPathForLocalMetadata( metadata ); - - localArtifactFile = new File( session.getLocalRepository().getBasedir(), localArtifactPath ); - - installer = new DefaultInstaller(); - installer.setFileProcessor( new TestFileProcessor() ); - installer.setRepositoryEventDispatcher( new StubRepositoryEventDispatcher() ); - installer.setSyncContextFactory( new StubSyncContextFactory() ); - request = new InstallRequest(); - listener = new RecordingRepositoryListener(); - session.setRepositoryListener( listener ); - - lrm = (TestLocalRepositoryManager) session.getLocalRepositoryManager(); - - TestFileUtils.deleteFile( session.getLocalRepository().getBasedir() ); - } - - @After - public void teardown() - throws Exception - { - TestFileUtils.deleteFile( session.getLocalRepository().getBasedir() ); - } - - @Test - public void testSuccessfulInstall() - throws InstallationException, UnsupportedEncodingException, IOException - { - File artifactFile = - new File( session.getLocalRepositoryManager().getRepository().getBasedir(), localArtifactPath ); - File metadataFile = - new File( session.getLocalRepositoryManager().getRepository().getBasedir(), localMetadataPath ); - - artifactFile.delete(); - metadataFile.delete(); - - request.addArtifact( artifact ); - request.addMetadata( metadata ); - - InstallResult result = installer.install( session, request ); - - assertTrue( artifactFile.exists() ); - assertEquals( "artifact", TestFileUtils.readString( artifactFile ) ); - - assertTrue( metadataFile.exists() ); - assertEquals( "metadata", TestFileUtils.readString( metadataFile ) ); - - assertEquals( result.getRequest(), request ); - - assertEquals( result.getArtifacts().size(), 1 ); - assertTrue( result.getArtifacts().contains( artifact ) ); - - assertEquals( result.getMetadata().size(), 1 ); - assertTrue( result.getMetadata().contains( metadata ) ); - - assertEquals( 1, lrm.getMetadataRegistration().size() ); - assertTrue( lrm.getMetadataRegistration().contains( metadata ) ); - assertEquals( 1, lrm.getArtifactRegistration().size() ); - assertTrue( lrm.getArtifactRegistration().contains( artifact ) ); - } - - @Test( expected = InstallationException.class ) - public void testNullArtifactFile() - throws InstallationException - { - InstallRequest request = new InstallRequest(); - request.addArtifact( artifact.setFile( null ) ); - - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testNullMetadataFile() - throws InstallationException - { - InstallRequest request = new InstallRequest(); - request.addMetadata( metadata.setFile( null ) ); - - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testNonExistentArtifactFile() - throws InstallationException - { - InstallRequest request = new InstallRequest(); - request.addArtifact( artifact.setFile( new File( "missing.txt" ) ) ); - - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testNonExistentMetadataFile() - throws InstallationException - { - InstallRequest request = new InstallRequest(); - request.addMetadata( metadata.setFile( new File( "missing.xml" ) ) ); - - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testArtifactExistsAsDir() - throws InstallationException - { - String path = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact ); - File file = new File( session.getLocalRepository().getBasedir(), path ); - assertFalse( file.getAbsolutePath() + " is a file, not directory", file.isFile() ); - assertFalse( file.getAbsolutePath() + " already exists", file.exists() ); - assertTrue( "failed to setup test: could not create " + file.getAbsolutePath(), - file.mkdirs() || file.isDirectory() ); - - request.addArtifact( artifact ); - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testMetadataExistsAsDir() - throws InstallationException - { - String path = session.getLocalRepositoryManager().getPathForLocalMetadata( metadata ); - assertTrue( "failed to setup test: could not create " + path, - new File( session.getLocalRepository().getBasedir(), path ).mkdirs() ); - - request.addMetadata( metadata ); - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testArtifactDestinationEqualsSource() - throws Exception - { - String path = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact ); - File file = new File( session.getLocalRepository().getBasedir(), path ); - artifact = artifact.setFile( file ); - TestFileUtils.writeString( file, "test" ); - - request.addArtifact( artifact ); - installer.install( session, request ); - } - - @Test( expected = InstallationException.class ) - public void testMetadataDestinationEqualsSource() - throws Exception - { - String path = session.getLocalRepositoryManager().getPathForLocalMetadata( metadata ); - File file = new File( session.getLocalRepository().getBasedir(), path ); - metadata = metadata.setFile( file ); - TestFileUtils.writeString( file, "test" ); - - request.addMetadata( metadata ); - installer.install( session, request ); - } - - @Test - public void testSuccessfulArtifactEvents() - throws InstallationException - { - InstallRequest request = new InstallRequest(); - request.addArtifact( artifact ); - - installer.install( session, request ); - checkEvents( "Repository Event problem", artifact, false ); - } - - @Test - public void testSuccessfulMetadataEvents() - throws InstallationException - { - InstallRequest request = new InstallRequest(); - request.addMetadata( metadata ); - - installer.install( session, request ); - checkEvents( "Repository Event problem", metadata, false ); - } - - @Test - public void testFailingEventsNullArtifactFile() - { - checkFailedEvents( "null artifact file", this.artifact.setFile( null ) ); - } - - @Test - public void testFailingEventsNullMetadataFile() - { - checkFailedEvents( "null metadata file", this.metadata.setFile( null ) ); - } - - @Test - public void testFailingEventsArtifactExistsAsDir() - { - String path = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact ); - assertTrue( "failed to setup test: could not create " + path, - new File( session.getLocalRepository().getBasedir(), path ).mkdirs() ); - checkFailedEvents( "target exists as dir", artifact ); - } - - @Test - public void testFailingEventsMetadataExistsAsDir() - { - String path = session.getLocalRepositoryManager().getPathForLocalMetadata( metadata ); - assertTrue( "failed to setup test: could not create " + path, - new File( session.getLocalRepository().getBasedir(), path ).mkdirs() ); - checkFailedEvents( "target exists as dir", metadata ); - } - - private void checkFailedEvents( String msg, Metadata metadata ) - { - InstallRequest request = new InstallRequest().addMetadata( metadata ); - msg = "Repository events problem (case: " + msg + ")"; - - try - { - installer.install( session, request ); - fail( "expected exception" ); - } - catch ( InstallationException e ) - { - checkEvents( msg, metadata, true ); - } - - } - - private void checkEvents( String msg, Metadata metadata, boolean failed ) - { - List<RepositoryEvent> events = listener.getEvents(); - assertEquals( msg, 2, events.size() ); - RepositoryEvent event = events.get( 0 ); - assertEquals( msg, EventType.METADATA_INSTALLING, event.getType() ); - assertEquals( msg, metadata, event.getMetadata() ); - assertNull( msg, event.getException() ); - - event = events.get( 1 ); - assertEquals( msg, EventType.METADATA_INSTALLED, event.getType() ); - assertEquals( msg, metadata, event.getMetadata() ); - if ( failed ) - { - assertNotNull( msg, event.getException() ); - } - else - { - assertNull( msg, event.getException() ); - } - } - - private void checkFailedEvents( String msg, Artifact artifact ) - { - InstallRequest request = new InstallRequest().addArtifact( artifact ); - msg = "Repository events problem (case: " + msg + ")"; - - try - { - installer.install( session, request ); - fail( "expected exception" ); - } - catch ( InstallationException e ) - { - checkEvents( msg, artifact, true ); - } - } - - private void checkEvents( String msg, Artifact artifact, boolean failed ) - { - List<RepositoryEvent> events = listener.getEvents(); - assertEquals( msg, 2, events.size() ); - RepositoryEvent event = events.get( 0 ); - assertEquals( msg, EventType.ARTIFACT_INSTALLING, event.getType() ); - assertEquals( msg, artifact, event.getArtifact() ); - assertNull( msg, event.getException() ); - - event = events.get( 1 ); - assertEquals( msg, EventType.ARTIFACT_INSTALLED, event.getType() ); - assertEquals( msg, artifact, event.getArtifact() ); - if ( failed ) - { - assertNotNull( msg + " > expected exception", event.getException() ); - } - else - { - assertNull( msg + " > " + event.getException(), event.getException() ); - } - } - - @Test - public void testDoNotUpdateUnchangedArtifact() - throws InstallationException - { - request.addArtifact( artifact ); - installer.install( session, request ); - - installer.setFileProcessor( new DefaultFileProcessor() - { - @Override - public long copy( File src, File target, ProgressListener listener ) - throws IOException - { - throw new IOException( "copy called" ); - } - } ); - - request = new InstallRequest(); - request.addArtifact( artifact ); - installer.install( session, request ); - } - - @Test - public void testSetArtifactTimestamps() - throws InstallationException - { - artifact.getFile().setLastModified( artifact.getFile().lastModified() - 60000 ); - - request.addArtifact( artifact ); - - installer.install( session, request ); - - assertEquals( "artifact timestamp was not set to src file", artifact.getFile().lastModified(), - localArtifactFile.lastModified() ); - - request = new InstallRequest(); - - request.addArtifact( artifact ); - - artifact.getFile().setLastModified( artifact.getFile().lastModified() - 60000 ); - - installer.install( session, request ); - - assertEquals( "artifact timestamp was not set to src file", artifact.getFile().lastModified(), - localArtifactFile.lastModified() ); - } -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java deleted file mode 100644 index d977a78..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultMetadataResolverTest.java +++ /dev/null @@ -1,256 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.internal.impl.DefaultMetadataResolver; -import org.eclipse.aether.internal.test.util.TestFileUtils; -import org.eclipse.aether.internal.test.util.TestLocalRepositoryManager; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.eclipse.aether.metadata.DefaultMetadata; -import org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.repository.LocalMetadataRegistration; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.MetadataRequest; -import org.eclipse.aether.resolution.MetadataResult; -import org.eclipse.aether.spi.connector.ArtifactDownload; -import org.eclipse.aether.spi.connector.MetadataDownload; -import org.eclipse.aether.transfer.MetadataNotFoundException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class DefaultMetadataResolverTest -{ - - private DefaultMetadataResolver resolver; - - private StubRepositoryConnectorProvider connectorProvider; - - private RemoteRepository repository; - - private DefaultRepositorySystemSession session; - - private Metadata metadata; - - private RecordingRepositoryConnector connector; - - private TestLocalRepositoryManager lrm; - - @Before - public void setup() - throws Exception - { - session = TestUtils.newSession(); - lrm = (TestLocalRepositoryManager) session.getLocalRepositoryManager(); - connectorProvider = new StubRepositoryConnectorProvider(); - resolver = new DefaultMetadataResolver(); - resolver.setUpdateCheckManager( new StaticUpdateCheckManager( true ) ); - resolver.setRepositoryEventDispatcher( new StubRepositoryEventDispatcher() ); - resolver.setRepositoryConnectorProvider( connectorProvider ); - resolver.setRemoteRepositoryManager( new StubRemoteRepositoryManager() ); - resolver.setSyncContextFactory( new StubSyncContextFactory() ); - resolver.setOfflineController( new DefaultOfflineController() ); - repository = - new RemoteRepository.Builder( "test-DMRT", "default", - TestFileUtils.createTempDir().toURI().toURL().toString() ).build(); - metadata = new DefaultMetadata( "gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT ); - connector = new RecordingRepositoryConnector(); - connectorProvider.setConnector( connector ); - } - - @After - public void teardown() - throws Exception - { - TestFileUtils.deleteFile( new File( new URI( repository.getUrl() ) ) ); - TestFileUtils.deleteFile( session.getLocalRepository().getBasedir() ); - } - - @Test - public void testNoRepositoryFailing() - { - MetadataRequest request = new MetadataRequest( metadata, null, "" ); - List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); - - assertEquals( 1, results.size() ); - - MetadataResult result = results.get( 0 ); - assertSame( request, result.getRequest() ); - assertNotNull( "" + ( result.getMetadata() != null ? result.getMetadata().getFile() : result.getMetadata() ), - result.getException() ); - assertEquals( MetadataNotFoundException.class, result.getException().getClass() ); - - assertNull( result.getMetadata() ); - } - - @Test - public void testResolve() - throws IOException - { - connector.setExpectGet( metadata ); - - // prepare "download" - File file = - new File( session.getLocalRepository().getBasedir(), - session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, repository, "" ) ); - - TestFileUtils.writeString( file, file.getAbsolutePath() ); - - MetadataRequest request = new MetadataRequest( metadata, repository, "" ); - List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); - - assertEquals( 1, results.size() ); - - MetadataResult result = results.get( 0 ); - assertSame( request, result.getRequest() ); - assertNull( result.getException() ); - assertNotNull( result.getMetadata() ); - assertNotNull( result.getMetadata().getFile() ); - - assertEquals( file, result.getMetadata().getFile() ); - assertEquals( metadata, result.getMetadata().setFile( null ) ); - - connector.assertSeenExpected(); - Set<Metadata> metadataRegistration = - ( (TestLocalRepositoryManager) session.getLocalRepositoryManager() ).getMetadataRegistration(); - assertTrue( metadataRegistration.contains( metadata ) ); - assertEquals( 1, metadataRegistration.size() ); - } - - @Test - public void testRemoveMetadataIfMissing() - throws IOException - { - connector = new RecordingRepositoryConnector() - { - - @Override - public void get( Collection<? extends ArtifactDownload> artifactDownloads, - Collection<? extends MetadataDownload> metadataDownloads ) - { - super.get( artifactDownloads, metadataDownloads ); - for ( MetadataDownload d : metadataDownloads ) - { - d.setException( new MetadataNotFoundException( metadata, repository ) ); - } - } - - }; - connectorProvider.setConnector( connector ); - - File file = - new File( session.getLocalRepository().getBasedir(), - session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, repository, "" ) ); - TestFileUtils.writeString( file, file.getAbsolutePath() ); - metadata.setFile( file ); - - MetadataRequest request = new MetadataRequest( metadata, repository, "" ); - request.setDeleteLocalCopyIfMissing( true ); - - List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); - assertEquals( 1, results.size() ); - MetadataResult result = results.get( 0 ); - - assertNotNull( result.getException() ); - assertEquals( false, file.exists() ); - } - - @Test - public void testOfflineSessionResolveMetadataMissing() - { - session.setOffline( true ); - MetadataRequest request = new MetadataRequest( metadata, repository, "" ); - List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); - - assertEquals( 1, results.size() ); - - MetadataResult result = results.get( 0 ); - assertSame( request, result.getRequest() ); - assertNotNull( result.getException() ); - assertNull( result.getMetadata() ); - - connector.assertSeenExpected(); - } - - @Test - public void testOfflineSessionResolveMetadata() - throws IOException - { - session.setOffline( true ); - - String path = session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, repository, "" ); - File file = new File( session.getLocalRepository().getBasedir(), path ); - TestFileUtils.writeString( file, file.getAbsolutePath() ); - - // set file to use in TestLRM find() - metadata = metadata.setFile( file ); - - MetadataRequest request = new MetadataRequest( metadata, repository, "" ); - List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); - - assertEquals( 1, results.size() ); - MetadataResult result = results.get( 0 ); - assertSame( request, result.getRequest() ); - assertNull( String.valueOf( result.getException() ), result.getException() ); - assertNotNull( result.getMetadata() ); - assertNotNull( result.getMetadata().getFile() ); - - assertEquals( file, result.getMetadata().getFile() ); - assertEquals( metadata.setFile( null ), result.getMetadata().setFile( null ) ); - - connector.assertSeenExpected(); - } - - @Test - public void testFavorLocal() - throws IOException - { - lrm.add( session, new LocalMetadataRegistration( metadata ) ); - String path = session.getLocalRepositoryManager().getPathForLocalMetadata( metadata ); - File file = new File( session.getLocalRepository().getBasedir(), path ); - TestFileUtils.writeString( file, file.getAbsolutePath() ); - - MetadataRequest request = new MetadataRequest( metadata, repository, "" ); - request.setFavorLocalRepository( true ); - resolver.setUpdateCheckManager( new StaticUpdateCheckManager( true, true ) ); - - List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); - - assertEquals( 1, results.size() ); - MetadataResult result = results.get( 0 ); - assertSame( request, result.getRequest() ); - assertNull( String.valueOf( result.getException() ), result.getException() ); - - connector.assertSeenExpected(); - } -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultOfflineControllerTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultOfflineControllerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultOfflineControllerTest.java deleted file mode 100644 index 7e42707..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultOfflineControllerTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.transfer.RepositoryOfflineException; -import org.junit.Before; -import org.junit.Test; - -public class DefaultOfflineControllerTest -{ - - private DefaultOfflineController controller; - - private RepositorySystemSession newSession( boolean offline, String protocols, String hosts ) - { - DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(); - session.setOffline( offline ); - session.setConfigProperty( DefaultOfflineController.CONFIG_PROP_OFFLINE_PROTOCOLS, protocols ); - session.setConfigProperty( DefaultOfflineController.CONFIG_PROP_OFFLINE_HOSTS, hosts ); - return session; - } - - private RemoteRepository newRepo( String url ) - { - return new RemoteRepository.Builder( "central", "default", url ).build(); - } - - @Before - public void setup() - { - controller = new DefaultOfflineController(); - } - - @Test( expected = RepositoryOfflineException.class ) - public void testCheckOffline_Online() - throws Exception - { - controller.checkOffline( newSession( false, null, null ), newRepo( "http://eclipse.org" ) ); - } - - @Test( expected = RepositoryOfflineException.class ) - public void testCheckOffline_Offline() - throws Exception - { - controller.checkOffline( newSession( true, null, null ), newRepo( "http://eclipse.org" ) ); - } - - @Test - public void testCheckOffline_Offline_OfflineProtocol() - throws Exception - { - controller.checkOffline( newSession( true, "file", null ), newRepo( "file://repo" ) ); - controller.checkOffline( newSession( true, "file", null ), newRepo( "FILE://repo" ) ); - controller.checkOffline( newSession( true, " file , classpath ", null ), newRepo( "file://repo" ) ); - controller.checkOffline( newSession( true, " file , classpath ", null ), newRepo( "classpath://repo" ) ); - } - - @Test( expected = RepositoryOfflineException.class ) - public void testCheckOffline_Offline_OnlineProtocol() - throws Exception - { - controller.checkOffline( newSession( true, "file", null ), newRepo( "http://eclipse.org" ) ); - } - - @Test - public void testCheckOffline_Offline_OfflineHost() - throws Exception - { - controller.checkOffline( newSession( true, null, "localhost" ), newRepo( "http://localhost" ) ); - controller.checkOffline( newSession( true, null, "localhost" ), newRepo( "http://LOCALHOST" ) ); - controller.checkOffline( newSession( true, null, " localhost , 127.0.0.1 " ), newRepo( "http://localhost" ) ); - controller.checkOffline( newSession( true, null, " localhost , 127.0.0.1 " ), newRepo( "http://127.0.0.1" ) ); - } - - @Test( expected = RepositoryOfflineException.class ) - public void testCheckOffline_Offline_OnlineHost() - throws Exception - { - controller.checkOffline( newSession( true, null, "localhost" ), newRepo( "http://eclipse.org" ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java deleted file mode 100644 index 8bc50d6..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java +++ /dev/null @@ -1,308 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.impl.UpdatePolicyAnalyzer; -import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager; -import org.eclipse.aether.internal.test.util.TestLoggerFactory; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.eclipse.aether.repository.MirrorSelector; -import org.eclipse.aether.repository.Proxy; -import org.eclipse.aether.repository.ProxySelector; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.repository.RepositoryPolicy; -import org.eclipse.aether.util.repository.AuthenticationBuilder; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * - */ -public class DefaultRemoteRepositoryManagerTest -{ - - private DefaultRepositorySystemSession session; - - private DefaultRemoteRepositoryManager manager; - - @Before - public void setup() - throws Exception - { - session = TestUtils.newSession(); - session.setChecksumPolicy( null ); - session.setUpdatePolicy( null ); - manager = new DefaultRemoteRepositoryManager(); - manager.setUpdatePolicyAnalyzer( new StubUpdatePolicyAnalyzer() ); - manager.setChecksumPolicyProvider( new DefaultChecksumPolicyProvider() ); - manager.setLoggerFactory( new TestLoggerFactory() ); - } - - @After - public void teardown() - throws Exception - { - manager = null; - session = null; - } - - private RemoteRepository.Builder newRepo( String id, String url, boolean enabled, String updates, String checksums ) - { - RepositoryPolicy policy = new RepositoryPolicy( enabled, updates, checksums ); - return new RemoteRepository.Builder( id, "test", url ).setPolicy( policy ); - } - - private void assertEqual( RemoteRepository expected, RemoteRepository actual ) - { - assertEquals( "id", expected.getId(), actual.getId() ); - assertEquals( "url", expected.getUrl(), actual.getUrl() ); - assertEquals( "type", expected.getContentType(), actual.getContentType() ); - assertEqual( expected.getPolicy( false ), actual.getPolicy( false ) ); - assertEqual( expected.getPolicy( true ), actual.getPolicy( true ) ); - } - - private void assertEqual( RepositoryPolicy expected, RepositoryPolicy actual ) - { - assertEquals( "enabled", expected.isEnabled(), actual.isEnabled() ); - assertEquals( "checksums", expected.getChecksumPolicy(), actual.getChecksumPolicy() ); - assertEquals( "updates", expected.getUpdatePolicy(), actual.getUpdatePolicy() ); - } - - @Test - public void testGetPolicy() - { - RepositoryPolicy snapshotPolicy = - new RepositoryPolicy( true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_IGNORE ); - RepositoryPolicy releasePolicy = - new RepositoryPolicy( true, RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); - - RemoteRepository repo = new RemoteRepository.Builder( "id", "type", "http://localhost" ) // - .setSnapshotPolicy( snapshotPolicy ).setReleasePolicy( releasePolicy ).build(); - - RepositoryPolicy effectivePolicy = manager.getPolicy( session, repo, true, true ); - assertEquals( true, effectivePolicy.isEnabled() ); - assertEquals( RepositoryPolicy.CHECKSUM_POLICY_IGNORE, effectivePolicy.getChecksumPolicy() ); - assertEquals( RepositoryPolicy.UPDATE_POLICY_ALWAYS, effectivePolicy.getUpdatePolicy() ); - } - - @Test - public void testAggregateSimpleRepos() - { - RemoteRepository dominant1 = newRepo( "a", "file://", false, "", "" ).build(); - - RemoteRepository recessive1 = newRepo( "a", "http://", true, "", "" ).build(); - RemoteRepository recessive2 = newRepo( "b", "file://", true, "", "" ).build(); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Arrays.asList( dominant1 ), - Arrays.asList( recessive1, recessive2 ), false ); - - assertEquals( 2, result.size() ); - assertEqual( dominant1, result.get( 0 ) ); - assertEqual( recessive2, result.get( 1 ) ); - } - - @Test - public void testAggregateSimpleRepos_MustKeepDisabledRecessiveRepo() - { - RemoteRepository dominant = newRepo( "a", "file://", true, "", "" ).build(); - - RemoteRepository recessive1 = newRepo( "b", "http://", false, "", "" ).build(); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Arrays.asList( dominant ), Arrays.asList( recessive1 ), false ); - - RemoteRepository recessive2 = newRepo( recessive1.getId(), "http://", true, "", "" ).build(); - - result = manager.aggregateRepositories( session, result, Arrays.asList( recessive2 ), false ); - - assertEquals( 2, result.size() ); - assertEqual( dominant, result.get( 0 ) ); - assertEqual( recessive1, result.get( 1 ) ); - } - - @Test - public void testAggregateMirrorRepos_DominantMirrorComplete() - { - RemoteRepository dominant1 = newRepo( "a", "http://", false, "", "" ).build(); - RemoteRepository dominantMirror1 = - newRepo( "x", "file://", false, "", "" ).addMirroredRepository( dominant1 ).build(); - - RemoteRepository recessive1 = newRepo( "a", "https://", true, "", "" ).build(); - RemoteRepository recessiveMirror1 = - newRepo( "x", "http://", true, "", "" ).addMirroredRepository( recessive1 ).build(); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Arrays.asList( dominantMirror1 ), - Arrays.asList( recessiveMirror1 ), false ); - - assertEquals( 1, result.size() ); - assertEqual( dominantMirror1, result.get( 0 ) ); - assertEquals( 1, result.get( 0 ).getMirroredRepositories().size() ); - assertEquals( dominant1, result.get( 0 ).getMirroredRepositories().get( 0 ) ); - } - - @Test - public void testAggregateMirrorRepos_DominantMirrorIncomplete() - { - RemoteRepository dominant1 = newRepo( "a", "http://", false, "", "" ).build(); - RemoteRepository dominantMirror1 = - newRepo( "x", "file://", false, "", "" ).addMirroredRepository( dominant1 ).build(); - - RemoteRepository recessive1 = newRepo( "a", "https://", true, "", "" ).build(); - RemoteRepository recessive2 = newRepo( "b", "https://", true, "", "" ).build(); - RemoteRepository recessiveMirror1 = - newRepo( "x", "http://", true, "", "" ).setMirroredRepositories( Arrays.asList( recessive1, recessive2 ) ).build(); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Arrays.asList( dominantMirror1 ), - Arrays.asList( recessiveMirror1 ), false ); - - assertEquals( 1, result.size() ); - assertEqual( newRepo( "x", "file://", true, "", "" ).build(), result.get( 0 ) ); - assertEquals( 2, result.get( 0 ).getMirroredRepositories().size() ); - assertEquals( dominant1, result.get( 0 ).getMirroredRepositories().get( 0 ) ); - assertEquals( recessive2, result.get( 0 ).getMirroredRepositories().get( 1 ) ); - } - - @Test - public void testMirrorAuthentication() - { - final RemoteRepository repo = newRepo( "a", "http://", true, "", "" ).build(); - final RemoteRepository mirror = - newRepo( "a", "http://", true, "", "" ).setAuthentication( new AuthenticationBuilder().addUsername( "test" ).build() ).build(); - session.setMirrorSelector( new MirrorSelector() - { - public RemoteRepository getMirror( RemoteRepository repository ) - { - return mirror; - } - } ); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Collections.<RemoteRepository> emptyList(), Arrays.asList( repo ), - true ); - - assertEquals( 1, result.size() ); - assertSame( mirror.getAuthentication(), result.get( 0 ).getAuthentication() ); - } - - @Test - public void testMirrorProxy() - { - final RemoteRepository repo = newRepo( "a", "http://", true, "", "" ).build(); - final RemoteRepository mirror = - newRepo( "a", "http://", true, "", "" ).setProxy( new Proxy( "http", "host", 2011, null ) ).build(); - session.setMirrorSelector( new MirrorSelector() - { - public RemoteRepository getMirror( RemoteRepository repository ) - { - return mirror; - } - } ); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Collections.<RemoteRepository> emptyList(), Arrays.asList( repo ), - true ); - - assertEquals( 1, result.size() ); - assertEquals( "http", result.get( 0 ).getProxy().getType() ); - assertEquals( "host", result.get( 0 ).getProxy().getHost() ); - assertEquals( 2011, result.get( 0 ).getProxy().getPort() ); - } - - @Test - public void testProxySelector() - { - final RemoteRepository repo = newRepo( "a", "http://", true, "", "" ).build(); - final Proxy proxy = new Proxy( "http", "host", 2011, null ); - session.setProxySelector( new ProxySelector() - { - public Proxy getProxy( RemoteRepository repository ) - { - return proxy; - } - } ); - session.setMirrorSelector( new MirrorSelector() - { - public RemoteRepository getMirror( RemoteRepository repository ) - { - return null; - } - } ); - - List<RemoteRepository> result = - manager.aggregateRepositories( session, Collections.<RemoteRepository> emptyList(), Arrays.asList( repo ), - true ); - - assertEquals( 1, result.size() ); - assertEquals( "http", result.get( 0 ).getProxy().getType() ); - assertEquals( "host", result.get( 0 ).getProxy().getHost() ); - assertEquals( 2011, result.get( 0 ).getProxy().getPort() ); - } - - private static class StubUpdatePolicyAnalyzer - implements UpdatePolicyAnalyzer - { - - public String getEffectiveUpdatePolicy( RepositorySystemSession session, String policy1, String policy2 ) - { - return ordinalOfUpdatePolicy( policy1 ) < ordinalOfUpdatePolicy( policy2 ) ? policy1 : policy2; - } - - private int ordinalOfUpdatePolicy( String policy ) - { - if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) - { - return 1440; - } - else if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) - { - return 0; - } - else if ( policy != null && policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) - { - String s = policy.substring( RepositoryPolicy.UPDATE_POLICY_INTERVAL.length() + 1 ); - return Integer.valueOf( s ); - } - else - { - // assume "never" - return Integer.MAX_VALUE; - } - } - - public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ) - { - return false; - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositoryEventDispatcherTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositoryEventDispatcherTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositoryEventDispatcherTest.java deleted file mode 100644 index 25e8a87..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositoryEventDispatcherTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.eclipse.aether.internal.impl; - -/* - * 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 static org.junit.Assert.*; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Locale; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositoryEvent; -import org.eclipse.aether.RepositoryListener; -import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher; -import org.eclipse.aether.internal.test.util.TestUtils; -import org.junit.Test; - -/** - */ -public class DefaultRepositoryEventDispatcherTest -{ - - @Test - public void testDispatchHandlesAllEventTypes() - throws Exception - { - DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher(); - - ListenerHandler handler = new ListenerHandler(); - - RepositoryListener listener = - (RepositoryListener) Proxy.newProxyInstance( getClass().getClassLoader(), - new Class<?>[] { RepositoryListener.class }, handler ); - - DefaultRepositorySystemSession session = TestUtils.newSession(); - session.setRepositoryListener( listener ); - - for ( RepositoryEvent.EventType type : RepositoryEvent.EventType.values() ) - { - RepositoryEvent event = new RepositoryEvent.Builder( session, type ).build(); - - handler.methodName = null; - - dispatcher.dispatch( event ); - - assertNotNull( "not handled: " + type, handler.methodName ); - - assertEquals( "badly handled: " + type, type.name().replace( "_", "" ).toLowerCase( Locale.ENGLISH ), - handler.methodName.toLowerCase( Locale.ENGLISH ) ); - } - } - - static class ListenerHandler - implements InvocationHandler - { - - public String methodName; - - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { - if ( args.length == 1 && args[0] instanceof RepositoryEvent ) - { - methodName = method.getName(); - } - - return null; - } - - } - -}