You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2016/09/03 20:23:55 UTC
[32/51] [partial] maven-aether git commit: [MNG-6007] rename Aether
to Maven Artifact Resolver
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemTest.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemTest.java
deleted file mode 100644
index 9576152..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemTest.java
+++ /dev/null
@@ -1,149 +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.List;
-
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.collection.CollectRequest;
-import org.eclipse.aether.collection.CollectResult;
-import org.eclipse.aether.collection.DependencyCollectionException;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.impl.DependencyCollector;
-import org.eclipse.aether.internal.test.util.TestUtils;
-import org.eclipse.aether.repository.Authentication;
-import org.eclipse.aether.repository.Proxy;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.resolution.DependencyRequest;
-import org.eclipse.aether.resolution.DependencyResolutionException;
-import org.eclipse.aether.util.repository.AuthenticationBuilder;
-import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
-import org.eclipse.aether.util.repository.DefaultMirrorSelector;
-import org.eclipse.aether.util.repository.DefaultProxySelector;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DefaultRepositorySystemTest
-{
-
- private DefaultRepositorySystem system;
-
- private DefaultRepositorySystemSession session;
-
- @Before
- public void init()
- {
- DefaultRemoteRepositoryManager remoteRepoManager = new DefaultRemoteRepositoryManager();
- system = new DefaultRepositorySystem();
- system.setRemoteRepositoryManager( remoteRepoManager );
- session = TestUtils.newSession();
- }
-
- @Test
- public void testNewResolutionRepositories()
- {
- Proxy proxy = new Proxy( "http", "localhost", 8080 );
- DefaultProxySelector proxySelector = new DefaultProxySelector();
- proxySelector.add( proxy, "" );
- session.setProxySelector( proxySelector );
-
- Authentication auth = new AuthenticationBuilder().addUsername( "user" ).build();
- DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
- authSelector.add( "mirror", auth );
- authSelector.add( "test-2", auth );
- session.setAuthenticationSelector( authSelector );
-
- DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
- mirrorSelector.add( "mirror", "http:void", "default", false, "test-1", null );
- session.setMirrorSelector( mirrorSelector );
-
- RemoteRepository rawRepo1 = new RemoteRepository.Builder( "test-1", "default", "http://void" ).build();
- RemoteRepository rawRepo2 = new RemoteRepository.Builder( "test-2", "default", "http://null" ).build();
- List<RemoteRepository> resolveRepos =
- system.newResolutionRepositories( session, Arrays.asList( rawRepo1, rawRepo2 ) );
- assertNotNull( resolveRepos );
- assertEquals( 2, resolveRepos.size() );
- RemoteRepository resolveRepo = resolveRepos.get( 0 );
- assertNotNull( resolveRepo );
- assertEquals( "mirror", resolveRepo.getId() );
- assertSame( proxy, resolveRepo.getProxy() );
- assertSame( auth, resolveRepo.getAuthentication() );
- resolveRepo = resolveRepos.get( 1 );
- assertNotNull( resolveRepo );
- assertEquals( "test-2", resolveRepo.getId() );
- assertSame( proxy, resolveRepo.getProxy() );
- assertSame( auth, resolveRepo.getAuthentication() );
- }
-
- @Test
- public void testNewDeploymentRepository()
- {
- Proxy proxy = new Proxy( "http", "localhost", 8080 );
- DefaultProxySelector proxySelector = new DefaultProxySelector();
- proxySelector.add( proxy, "" );
- session.setProxySelector( proxySelector );
-
- Authentication auth = new AuthenticationBuilder().addUsername( "user" ).build();
- DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
- authSelector.add( "test", auth );
- session.setAuthenticationSelector( authSelector );
-
- DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
- mirrorSelector.add( "mirror", "file:void", "default", false, "*", null );
- session.setMirrorSelector( mirrorSelector );
-
- RemoteRepository rawRepo = new RemoteRepository.Builder( "test", "default", "http://void" ).build();
- RemoteRepository deployRepo = system.newDeploymentRepository( session, rawRepo );
- assertNotNull( deployRepo );
- assertSame( proxy, deployRepo.getProxy() );
- assertSame( auth, deployRepo.getAuthentication() );
- }
-
- @Test
- public void testResolveDependencies_NoRootNode()
- throws Exception
- {
- DependencyRequest request = new DependencyRequest();
- request.setCollectRequest( new CollectRequest().setRoot( new Dependency( new DefaultArtifact( "g:a:v" ), "" ) ) );
- system.setDependencyCollector( new DependencyCollector()
- {
- public CollectResult collectDependencies( RepositorySystemSession session, CollectRequest request )
- throws DependencyCollectionException
- {
- throw new DependencyCollectionException( null );
- }
- } );
- try
- {
- system.resolveDependencies( session, request );
- fail( "Expected exception" );
- }
- catch ( DependencyResolutionException e )
- {
- assertTrue( e.getCause() instanceof DependencyCollectionException );
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManagerTest.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManagerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManagerTest.java
deleted file mode 100644
index 43ccd54..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManagerTest.java
+++ /dev/null
@@ -1,816 +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.net.URI;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.impl.UpdateCheck;
-import org.eclipse.aether.internal.impl.DefaultUpdateCheckManager;
-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.Metadata;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.repository.RepositoryPolicy;
-import org.eclipse.aether.transfer.ArtifactNotFoundException;
-import org.eclipse.aether.transfer.ArtifactTransferException;
-import org.eclipse.aether.transfer.MetadataNotFoundException;
-import org.eclipse.aether.transfer.MetadataTransferException;
-import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- */
-public class DefaultUpdateCheckManagerTest
-{
-
- private static final int HOUR = 60 * 60 * 1000;
-
- private DefaultUpdateCheckManager manager;
-
- private DefaultRepositorySystemSession session;
-
- private Metadata metadata;
-
- private RemoteRepository repository;
-
- private Artifact artifact;
-
- @Before
- public void setup()
- throws Exception
- {
- File dir = TestFileUtils.createTempFile( "" );
- TestFileUtils.deleteFile( dir );
-
- File metadataFile = new File( dir, "metadata.txt" );
- TestFileUtils.writeString( metadataFile, "metadata" );
- File artifactFile = new File( dir, "artifact.txt" );
- TestFileUtils.writeString( artifactFile, "artifact" );
-
- session = TestUtils.newSession();
- repository =
- new RemoteRepository.Builder( "id", "default", TestFileUtils.createTempDir().toURI().toURL().toString() ).build();
- manager = new DefaultUpdateCheckManager().setUpdatePolicyAnalyzer( new DefaultUpdatePolicyAnalyzer() );
- metadata =
- new DefaultMetadata( "gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT,
- metadataFile );
- artifact = new DefaultArtifact( "gid", "aid", "", "ext", "ver" ).setFile( artifactFile );
- }
-
- @After
- public void teardown()
- throws Exception
- {
- new File( metadata.getFile().getParent(), "resolver-status.properties" ).delete();
- new File( artifact.getFile().getPath() + ".lastUpdated" ).delete();
- metadata.getFile().delete();
- artifact.getFile().delete();
- TestFileUtils.deleteFile( new File( new URI( repository.getUrl() ) ) );
- }
-
- static void resetSessionData( RepositorySystemSession session )
- {
- session.getData().set( "updateCheckManager.checks", null );
- }
-
- private UpdateCheck<Metadata, MetadataTransferException> newMetadataCheck()
- {
- UpdateCheck<Metadata, MetadataTransferException> check = new UpdateCheck<Metadata, MetadataTransferException>();
- check.setItem( metadata );
- check.setFile( metadata.getFile() );
- check.setRepository( repository );
- check.setAuthoritativeRepository( repository );
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10" );
- return check;
- }
-
- private UpdateCheck<Artifact, ArtifactTransferException> newArtifactCheck()
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = new UpdateCheck<Artifact, ArtifactTransferException>();
- check.setItem( artifact );
- check.setFile( artifact.getFile() );
- check.setRepository( repository );
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10" );
- return check;
- }
-
- @Test( expected = Exception.class )
- public void testCheckMetadataFailOnNoFile()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setItem( metadata.setFile( null ) );
- check.setFile( null );
-
- manager.checkMetadata( session, check );
- }
-
- @Test
- public void testCheckMetadataUpdatePolicyRequired()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
-
- Calendar cal = Calendar.getInstance();
- cal.add( Calendar.DATE, -1 );
- check.setLocalLastUpdated( cal.getTimeInMillis() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- manager.checkMetadata( session, check );
- assertNull( check.getException() );
- assertTrue( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkMetadata( session, check );
- assertNull( check.getException() );
- assertTrue( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60" );
- manager.checkMetadata( session, check );
- assertNull( check.getException() );
- assertTrue( check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataUpdatePolicyNotRequired()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
-
- check.setLocalLastUpdated( System.currentTimeMillis() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- manager.checkMetadata( session, check );
- assertFalse( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkMetadata( session, check );
- assertFalse( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":61" );
- manager.checkMetadata( session, check );
- assertFalse( check.isRequired() );
-
- check.setPolicy( "no particular policy" );
- manager.checkMetadata( session, check );
- assertFalse( check.isRequired() );
- }
-
- @Test
- public void testCheckMetadata()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
-
- // existing file, never checked before
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
-
- // just checked
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60" );
-
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
-
- // no local file
- check.getFile().delete();
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- // (! file.exists && ! repoKey) -> no timestamp
- }
-
- @Test
- public void testCheckMetadataNoLocalFile()
- throws Exception
- {
- metadata.getFile().delete();
-
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
-
- long lastUpdate = new Date().getTime() - HOUR;
- check.setLocalLastUpdated( lastUpdate );
-
- // ! file.exists && updateRequired -> check in remote repo
- check.setLocalLastUpdated( lastUpdate );
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataNotFoundInRepoCachingEnabled()
- throws Exception
- {
- metadata.getFile().delete();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
-
- check.setException( new MetadataNotFoundException( metadata, repository, "" ) );
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- // ! file.exists && ! updateRequired -> artifact not found in remote repo
- check = newMetadataCheck().setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
- assertTrue( check.getException() instanceof MetadataNotFoundException );
- assertTrue( check.getException().isFromCache() );
- }
-
- @Test
- public void testCheckMetadataNotFoundInRepoCachingDisabled()
- throws Exception
- {
- metadata.getFile().delete();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( false, false ) );
-
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
-
- check.setException( new MetadataNotFoundException( metadata, repository, "" ) );
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- // ! file.exists && updateRequired -> check in remote repo
- check = newMetadataCheck().setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- assertNull( check.getException() );
- }
-
- @Test
- public void testCheckMetadataErrorFromRepoCachingEnabled()
- throws Exception
- {
- metadata.getFile().delete();
-
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
-
- check.setException( new MetadataTransferException( metadata, repository, "some error" ) );
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
- check = newMetadataCheck();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( false, true ) );
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
- assertTrue( check.getException() instanceof MetadataTransferException );
- assertTrue( String.valueOf( check.getException() ), check.getException().getMessage().contains( "some error" ) );
- assertTrue( check.getException().isFromCache() );
- }
-
- @Test
- public void testCheckMetadataErrorFromRepoCachingDisabled()
- throws Exception
- {
- metadata.getFile().delete();
-
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
-
- check.setException( new MetadataTransferException( metadata, repository, "some error" ) );
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
- check = newMetadataCheck();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( false, false ) );
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- assertNull( check.getException() );
- }
-
- @Test
- public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
-
- // first check
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
-
- manager.touchMetadata( session, check );
-
- // second check in same session
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataSessionStateModes()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- manager.touchMetadata( session, check );
-
- session.setConfigProperty( DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "bypass" );
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
-
- resetSessionData( session );
- manager.touchMetadata( session, check );
-
- session.setConfigProperty( DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "true" );
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
-
- session.setConfigProperty( DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "false" );
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_InvalidFile()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- check.setFileValid( false );
-
- // first check
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
-
- // first touch, without exception
- manager.touchMetadata( session, check );
-
- // another check in same session
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
-
- // another touch, with exception
- check.setException( new MetadataNotFoundException( check.getItem(), check.getRepository() ) );
- manager.touchMetadata( session, check );
-
- // another check in same session
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_DifferentRepoIdSameUrl()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- check.setFileValid( false );
-
- // first check
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
-
- manager.touchMetadata( session, check );
-
- // second check in same session but for repo with different id
- check.setRepository( new RemoteRepository.Builder( check.getRepository() ).setId( "check" ).build() );
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataWhenLocallyMissingEvenIfUpdatePolicyIsNever()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- check.getFile().delete();
- assertEquals( check.getFile().getAbsolutePath(), false, check.getFile().exists() );
-
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataWhenLocallyPresentButInvalidEvenIfUpdatePolicyIsNever()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- check.setFileValid( false );
-
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataWhenLocallyDeletedEvenIfTimestampUpToDate()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- manager.touchMetadata( session, check );
- resetSessionData( session );
-
- check.getFile().delete();
- assertEquals( check.getFile().getAbsolutePath(), false, check.getFile().exists() );
-
- manager.checkMetadata( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckMetadataNotWhenUpdatePolicyIsNeverAndTimestampIsUnavailable()
- throws Exception
- {
- UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- manager.checkMetadata( session, check );
- assertEquals( false, check.isRequired() );
- }
-
- @Test( expected = IllegalArgumentException.class )
- public void testCheckArtifactFailOnNoFile()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setItem( artifact.setFile( null ) );
- check.setFile( null );
-
- manager.checkArtifact( session, check );
- assertNotNull( check.getException() );
- }
-
- @Test
- public void testCheckArtifactUpdatePolicyRequired()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setItem( artifact );
- check.setFile( artifact.getFile() );
-
- Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) );
- cal.add( Calendar.DATE, -1 );
- long lastUpdate = cal.getTimeInMillis();
- artifact.getFile().setLastModified( lastUpdate );
- check.setLocalLastUpdated( lastUpdate );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- manager.checkArtifact( session, check );
- assertNull( check.getException() );
- assertTrue( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkArtifact( session, check );
- assertNull( check.getException() );
- assertTrue( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60" );
- manager.checkArtifact( session, check );
- assertNull( check.getException() );
- assertTrue( check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactUpdatePolicyNotRequired()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setItem( artifact );
- check.setFile( artifact.getFile() );
-
- Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) );
- cal.add( Calendar.HOUR_OF_DAY, -1 );
- check.setLocalLastUpdated( cal.getTimeInMillis() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- manager.checkArtifact( session, check );
- assertFalse( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkArtifact( session, check );
- assertFalse( check.isRequired() );
-
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":61" );
- manager.checkArtifact( session, check );
- assertFalse( check.isRequired() );
-
- check.setPolicy( "no particular policy" );
- manager.checkArtifact( session, check );
- assertFalse( check.isRequired() );
- }
-
- @Test
- public void testCheckArtifact()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- long fifteenMinutes = new Date().getTime() - ( 15 * 60 * 1000 );
- check.getFile().setLastModified( fifteenMinutes );
- // time is truncated on setLastModfied
- fifteenMinutes = check.getFile().lastModified();
-
- // never checked before
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
-
- // just checked
- check.setLocalLastUpdated( 0 );
- long lastUpdate = new Date().getTime();
- check.getFile().setLastModified( lastUpdate );
- lastUpdate = check.getFile().lastModified();
-
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
-
- // no local file, no repo timestamp
- check.setLocalLastUpdated( 0 );
- check.getFile().delete();
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactNoLocalFile()
- throws Exception
- {
- artifact.getFile().delete();
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
-
- long lastUpdate = new Date().getTime() - HOUR;
-
- // ! file.exists && updateRequired -> check in remote repo
- check.setLocalLastUpdated( lastUpdate );
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactNotFoundInRepoCachingEnabled()
- throws Exception
- {
- artifact.getFile().delete();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setException( new ArtifactNotFoundException( artifact, repository ) );
- manager.touchArtifact( session, check );
- resetSessionData( session );
-
- // ! file.exists && ! updateRequired -> artifact not found in remote repo
- check = newArtifactCheck().setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
- assertTrue( check.getException() instanceof ArtifactNotFoundException );
- assertTrue( check.getException().isFromCache() );
- }
-
- @Test
- public void testCheckArtifactNotFoundInRepoCachingDisabled()
- throws Exception
- {
- artifact.getFile().delete();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( false, false ) );
-
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setException( new ArtifactNotFoundException( artifact, repository ) );
- manager.touchArtifact( session, check );
- resetSessionData( session );
-
- // ! file.exists && updateRequired -> check in remote repo
- check = newArtifactCheck().setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- assertNull( check.getException() );
- }
-
- @Test
- public void testCheckArtifactErrorFromRepoCachingEnabled()
- throws Exception
- {
- artifact.getFile().delete();
-
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- check.setException( new ArtifactTransferException( artifact, repository, "some error" ) );
- manager.touchArtifact( session, check );
- resetSessionData( session );
-
- // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
- check = newArtifactCheck();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( false, true ) );
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
- assertTrue( check.getException() instanceof ArtifactTransferException );
- assertTrue( check.getException().isFromCache() );
- }
-
- @Test
- public void testCheckArtifactErrorFromRepoCachingDisabled()
- throws Exception
- {
- artifact.getFile().delete();
-
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_DAILY );
- check.setException( new ArtifactTransferException( artifact, repository, "some error" ) );
- manager.touchArtifact( session, check );
- resetSessionData( session );
-
- // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
- check = newArtifactCheck();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( false, false ) );
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- assertNull( check.getException() );
- }
-
- @Test
- public void testCheckArtifactAtMostOnceDuringSessionEvenIfUpdatePolicyAlways()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
-
- // first check
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
-
- manager.touchArtifact( session, check );
-
- // second check in same session
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactSessionStateModes()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- manager.touchArtifact( session, check );
-
- session.setConfigProperty( DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "bypass" );
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
-
- resetSessionData( session );
- manager.touchArtifact( session, check );
-
- session.setConfigProperty( DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "true" );
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
-
- session.setConfigProperty( DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "false" );
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_InvalidFile()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
- check.setFileValid( false );
-
- // first check
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
-
- // first touch, without exception
- manager.touchArtifact( session, check );
-
- // another check in same session
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
-
- // another touch, with exception
- check.setException( new ArtifactNotFoundException( check.getItem(), check.getRepository() ) );
- manager.touchArtifact( session, check );
-
- // another check in same session
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_DifferentRepoIdSameUrl()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
-
- // first check
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
-
- manager.touchArtifact( session, check );
-
- // second check in same session but for repo with different id
- check.setRepository( new RemoteRepository.Builder( check.getRepository() ).setId( "check" ).build() );
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactWhenLocallyMissingEvenIfUpdatePolicyIsNever()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- check.getFile().delete();
- assertEquals( check.getFile().getAbsolutePath(), false, check.getFile().exists() );
-
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactWhenLocallyPresentButInvalidEvenIfUpdatePolicyIsNever()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- manager.touchArtifact( session, check );
- resetSessionData( session );
-
- check.setFileValid( false );
-
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactWhenLocallyDeletedEvenIfTimestampUpToDate()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- manager.touchArtifact( session, check );
- resetSessionData( session );
-
- check.getFile().delete();
- assertEquals( check.getFile().getAbsolutePath(), false, check.getFile().exists() );
-
- manager.checkArtifact( session, check );
- assertEquals( true, check.isRequired() );
- }
-
- @Test
- public void testCheckArtifactNotWhenUpdatePolicyIsNeverAndTimestampIsUnavailable()
- throws Exception
- {
- UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
- check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
- session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) );
-
- manager.checkArtifact( session, check );
- assertEquals( false, check.isRequired() );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
deleted file mode 100644
index 31bcbaa..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
+++ /dev/null
@@ -1,130 +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.eclipse.aether.repository.RepositoryPolicy.*;
-import static org.junit.Assert.*;
-
-import java.util.Calendar;
-
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.test.util.TestUtils;
-import org.eclipse.aether.repository.RepositoryPolicy;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- */
-public class DefaultUpdatePolicyAnalyzerTest
-{
-
- private DefaultUpdatePolicyAnalyzer analyzer;
-
- private DefaultRepositorySystemSession session;
-
- @Before
- public void setup()
- throws Exception
- {
- analyzer = new DefaultUpdatePolicyAnalyzer();
- session = TestUtils.newSession();
- }
-
- private long now()
- {
- return System.currentTimeMillis();
- }
-
- @Test
- public void testIsUpdateRequired_PolicyNever()
- throws Exception
- {
- String policy = RepositoryPolicy.UPDATE_POLICY_NEVER;
- assertEquals( false, analyzer.isUpdatedRequired( session, Long.MIN_VALUE, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, Long.MAX_VALUE, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, 0, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, 1, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, now() - 604800000, policy ) );
- }
-
- @Test
- public void testIsUpdateRequired_PolicyAlways()
- throws Exception
- {
- String policy = RepositoryPolicy.UPDATE_POLICY_ALWAYS;
- assertEquals( true, analyzer.isUpdatedRequired( session, Long.MIN_VALUE, policy ) );
- assertEquals( true, analyzer.isUpdatedRequired( session, Long.MAX_VALUE, policy ) );
- assertEquals( true, analyzer.isUpdatedRequired( session, 0, policy ) );
- assertEquals( true, analyzer.isUpdatedRequired( session, 1, policy ) );
- assertEquals( true, analyzer.isUpdatedRequired( session, now() - 1000, policy ) );
- }
-
- @Test
- public void testIsUpdateRequired_PolicyDaily()
- throws Exception
- {
- Calendar cal = Calendar.getInstance();
- cal.set( Calendar.HOUR_OF_DAY, 0 );
- cal.set( Calendar.MINUTE, 0 );
- cal.set( Calendar.SECOND, 0 );
- cal.set( Calendar.MILLISECOND, 0 );
- long localMidnight = cal.getTimeInMillis();
-
- String policy = RepositoryPolicy.UPDATE_POLICY_DAILY;
- assertEquals( true, analyzer.isUpdatedRequired( session, Long.MIN_VALUE, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, Long.MAX_VALUE, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, localMidnight + 0, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, localMidnight + 1, policy ) );
- assertEquals( true, analyzer.isUpdatedRequired( session, localMidnight - 1, policy ) );
- }
-
- @Test
- public void testIsUpdateRequired_PolicyInterval()
- throws Exception
- {
- String policy = RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":5";
- assertEquals( true, analyzer.isUpdatedRequired( session, Long.MIN_VALUE, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, Long.MAX_VALUE, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, now(), policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, now() - 5 - 1, policy ) );
- assertEquals( false, analyzer.isUpdatedRequired( session, now() - 1000 * 5 - 1, policy ) );
- assertEquals( true, analyzer.isUpdatedRequired( session, now() - 1000 * 60 * 5 - 1, policy ) );
-
- policy = RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":invalid";
- assertEquals( false, analyzer.isUpdatedRequired( session, now(), policy ) );
- }
-
- @Test
- public void testEffectivePolicy()
- {
- assertEquals( UPDATE_POLICY_ALWAYS,
- analyzer.getEffectiveUpdatePolicy( session, UPDATE_POLICY_ALWAYS, UPDATE_POLICY_DAILY ) );
- assertEquals( UPDATE_POLICY_ALWAYS,
- analyzer.getEffectiveUpdatePolicy( session, UPDATE_POLICY_ALWAYS, UPDATE_POLICY_NEVER ) );
- assertEquals( UPDATE_POLICY_DAILY,
- analyzer.getEffectiveUpdatePolicy( session, UPDATE_POLICY_DAILY, UPDATE_POLICY_NEVER ) );
- assertEquals( UPDATE_POLICY_INTERVAL + ":60",
- analyzer.getEffectiveUpdatePolicy( session, UPDATE_POLICY_DAILY, UPDATE_POLICY_INTERVAL + ":60" ) );
- assertEquals( UPDATE_POLICY_INTERVAL + ":60",
- analyzer.getEffectiveUpdatePolicy( session, UPDATE_POLICY_INTERVAL + ":100",
- UPDATE_POLICY_INTERVAL + ":60" ) );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DependencyGraphDumper.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DependencyGraphDumper.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DependencyGraphDumper.java
deleted file mode 100644
index 39bc1ed..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DependencyGraphDumper.java
+++ /dev/null
@@ -1,222 +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 java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.graph.DependencyNode;
-
-/**
- * A helper to visualize dependency graphs.
- */
-public class DependencyGraphDumper
-{
-
- public static void dump( PrintWriter writer, DependencyNode node )
- {
- Context context = new Context();
- dump( context, node, 0, true );
-
- LinkedList<Indent> indents = new LinkedList<Indent>();
- for ( Line line : context.lines )
- {
- if ( line.depth > indents.size() )
- {
- if ( !indents.isEmpty() )
- {
- if ( indents.getLast() == Indent.CHILD )
- {
- indents.removeLast();
- indents.addLast( Indent.CHILDREN );
- }
- else if ( indents.getLast() == Indent.LAST_CHILD )
- {
- indents.removeLast();
- indents.addLast( Indent.NO_CHILDREN );
- }
- }
- indents.addLast( line.last ? Indent.LAST_CHILD : Indent.CHILD );
- }
- else if ( line.depth < indents.size() )
- {
- while ( line.depth <= indents.size() )
- {
- indents.removeLast();
- }
- indents.addLast( line.last ? Indent.LAST_CHILD : Indent.CHILD );
- }
- else if ( line.last && !indents.isEmpty() )
- {
- indents.removeLast();
- indents.addLast( Indent.LAST_CHILD );
- }
-
- for ( Indent indent : indents )
- {
- writer.print( indent );
- }
-
- line.print( writer );
- }
-
- writer.flush();
- }
-
- private static void dump( Context context, DependencyNode node, int depth, boolean last )
- {
- Line line = context.nodes.get( node );
- if ( line != null )
- {
- if ( line.id <= 0 )
- {
- line.id = ++context.ids;
- }
- context.lines.add( new Line( null, line.id, depth, last ) );
- return;
- }
-
- Dependency dependency = node.getDependency();
-
- if ( dependency == null )
- {
- line = new Line( null, 0, depth, last );
- }
- else
- {
- line = new Line( dependency, 0, depth, last );
- }
-
- context.lines.add( line );
-
- context.nodes.put( node, line );
-
- depth++;
-
- for ( Iterator<DependencyNode> it = node.getChildren().iterator(); it.hasNext(); )
- {
- DependencyNode child = it.next();
- dump( context, child, depth, !it.hasNext() );
- }
- }
-
- static enum Indent
- {
-
- NO_CHILDREN( " " ),
-
- CHILDREN( "| " ),
-
- CHILD( "+- " ),
-
- LAST_CHILD( "\\- " );
-
- private final String chars;
-
- Indent( String chars )
- {
- this.chars = chars;
- }
-
- @Override
- public String toString()
- {
- return chars;
- }
-
- }
-
- static class Context
- {
-
- int ids;
-
- List<Line> lines;
-
- Map<DependencyNode, Line> nodes;
-
- Context()
- {
- this.lines = new ArrayList<Line>();
- this.nodes = new IdentityHashMap<DependencyNode, Line>( 1024 );
- }
-
- }
-
- static class Line
- {
-
- Dependency dependency;
-
- int id;
-
- int depth;
-
- boolean last;
-
- Line( Dependency dependency, int id, int depth, boolean last )
- {
- this.dependency = dependency;
- this.id = id;
- this.depth = depth;
- this.last = last;
- }
-
- void print( PrintWriter writer )
- {
- if ( dependency == null )
- {
- if ( id > 0 )
- {
- writer.print( "^" );
- writer.print( id );
- }
- else
- {
- writer.print( "(null)" );
- }
- }
- else
- {
- if ( id > 0 )
- {
- writer.print( "(" );
- writer.print( id );
- writer.print( ")" );
- }
- writer.print( dependency.getArtifact() );
- if ( dependency.getScope().length() > 0 )
- {
- writer.print( ":" );
- writer.print( dependency.getScope() );
- }
- }
- writer.println();
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/EnhancedLocalRepositoryManagerTest.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/EnhancedLocalRepositoryManagerTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/EnhancedLocalRepositoryManagerTest.java
deleted file mode 100644
index 41bf542..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/EnhancedLocalRepositoryManagerTest.java
+++ /dev/null
@@ -1,343 +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.Collections;
-
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManager;
-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.Metadata;
-import org.eclipse.aether.metadata.Metadata.Nature;
-import org.eclipse.aether.repository.LocalArtifactRegistration;
-import org.eclipse.aether.repository.LocalArtifactRequest;
-import org.eclipse.aether.repository.LocalArtifactResult;
-import org.eclipse.aether.repository.LocalMetadataRequest;
-import org.eclipse.aether.repository.LocalMetadataResult;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class EnhancedLocalRepositoryManagerTest
-{
-
- private Artifact artifact;
-
- private Artifact snapshot;
-
- private File basedir;
-
- private EnhancedLocalRepositoryManager manager;
-
- private File artifactFile;
-
- private RemoteRepository repository;
-
- private String testContext = "project/compile";
-
- private RepositorySystemSession session;
-
- private Metadata metadata;
-
- private Metadata noVerMetadata;
-
- @Before
- public void setup()
- throws Exception
- {
- String url = TestFileUtils.createTempDir( "enhanced-remote-repo" ).toURI().toURL().toString();
- repository =
- new RemoteRepository.Builder( "enhanced-remote-repo", "default", url ).setRepositoryManager( true ).build();
-
- artifact =
- new DefaultArtifact( "gid", "aid", "", "jar", "1-test", Collections.<String, String> emptyMap(),
- TestFileUtils.createTempFile( "artifact" ) );
-
- snapshot =
- new DefaultArtifact( "gid", "aid", "", "jar", "1.0-20120710.231549-9",
- Collections.<String, String> emptyMap(), TestFileUtils.createTempFile( "artifact" ) );
-
- metadata =
- new DefaultMetadata( "gid", "aid", "1-test", "maven-metadata.xml", Nature.RELEASE,
- TestFileUtils.createTempFile( "metadata" ) );
-
- noVerMetadata =
- new DefaultMetadata( "gid", "aid", null, "maven-metadata.xml", Nature.RELEASE,
- TestFileUtils.createTempFile( "metadata" ) );
-
- basedir = TestFileUtils.createTempDir( "enhanced-repo" );
- session = TestUtils.newSession();
- manager = new EnhancedLocalRepositoryManager( basedir, session );
-
- artifactFile = new File( basedir, manager.getPathForLocalArtifact( artifact ) );
- }
-
- @After
- public void tearDown()
- throws Exception
- {
- TestFileUtils.deleteFile( basedir );
- TestFileUtils.deleteFile( new File( new URI( repository.getUrl() ) ) );
-
- session = null;
- manager = null;
- repository = null;
- artifact = null;
- }
-
- private long addLocalArtifact( Artifact artifact )
- throws IOException
- {
- manager.add( session, new LocalArtifactRegistration( artifact ) );
- String path = manager.getPathForLocalArtifact( artifact );
-
- return copy( artifact, path );
- }
-
- private long addRemoteArtifact( Artifact artifact )
- throws IOException
- {
- Collection<String> contexts = Arrays.asList( testContext );
- manager.add( session, new LocalArtifactRegistration( artifact, repository, contexts ) );
- String path = manager.getPathForRemoteArtifact( artifact, repository, testContext );
- return copy( artifact, path );
- }
-
- private long copy( Metadata metadata, String path )
- throws IOException
- {
- if ( metadata.getFile() == null )
- {
- return -1;
- }
- return TestFileUtils.copyFile( metadata.getFile(), new File( basedir, path ) );
- }
-
- private long copy( Artifact artifact, String path )
- throws IOException
- {
- if ( artifact.getFile() == null )
- {
- return -1;
- }
- File artifactFile = new File( basedir, path );
- return TestFileUtils.copyFile( artifact.getFile(), artifactFile );
- }
-
- @Test
- public void testGetPathForLocalArtifact()
- {
- Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
- assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
- assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) );
-
- artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" );
- assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
- assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) );
- }
-
- @Test
- public void testGetPathForRemoteArtifact()
- {
- RemoteRepository remoteRepo = new RemoteRepository.Builder( "repo", "default", "ram:/void" ).build();
-
- Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
- assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
- assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar",
- manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) );
-
- artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" );
- assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
- assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar",
- manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) );
- }
-
- @Test
- public void testFindLocalArtifact()
- throws Exception
- {
- addLocalArtifact( artifact );
-
- LocalArtifactRequest request = new LocalArtifactRequest( artifact, null, null );
- LocalArtifactResult result = manager.find( session, request );
- assertTrue( result.isAvailable() );
- assertEquals( null, result.getRepository() );
-
- snapshot = snapshot.setVersion( snapshot.getBaseVersion() );
- addLocalArtifact( snapshot );
-
- request = new LocalArtifactRequest( snapshot, null, null );
- result = manager.find( session, request );
- assertTrue( result.isAvailable() );
- assertEquals( null, result.getRepository() );
- }
-
- @Test
- public void testFindRemoteArtifact()
- throws Exception
- {
- addRemoteArtifact( artifact );
-
- LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext );
- LocalArtifactResult result = manager.find( session, request );
- assertTrue( result.isAvailable() );
- assertEquals( repository, result.getRepository() );
-
- addRemoteArtifact( snapshot );
-
- request = new LocalArtifactRequest( snapshot, Arrays.asList( repository ), testContext );
- result = manager.find( session, request );
- assertTrue( result.isAvailable() );
- assertEquals( repository, result.getRepository() );
- }
-
- @Test
- public void testDoNotFindDifferentContext()
- throws Exception
- {
- addRemoteArtifact( artifact );
-
- LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), "different" );
- LocalArtifactResult result = manager.find( session, request );
- assertFalse( result.isAvailable() );
- }
-
- @Test
- public void testDoNotFindNullFile()
- throws Exception
- {
- artifact = artifact.setFile( null );
- addLocalArtifact( artifact );
-
- LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext );
- LocalArtifactResult result = manager.find( session, request );
- assertFalse( result.isAvailable() );
- }
-
- @Test
- public void testDoNotFindDeletedFile()
- throws Exception
- {
- addLocalArtifact( artifact );
- assertTrue( "could not delete artifact file", artifactFile.delete() );
-
- LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext );
- LocalArtifactResult result = manager.find( session, request );
- assertFalse( result.isAvailable() );
- }
-
- @Test
- public void testFindUntrackedFile()
- throws Exception
- {
- copy( artifact, manager.getPathForLocalArtifact( artifact ) );
-
- LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext );
- LocalArtifactResult result = manager.find( session, request );
- assertTrue( result.isAvailable() );
- }
-
- private long addMetadata( Metadata metadata, RemoteRepository repo )
- throws IOException
- {
- String path;
- if ( repo == null )
- {
- path = manager.getPathForLocalMetadata( metadata );
- }
- else
- {
- path = manager.getPathForRemoteMetadata( metadata, repo, testContext );
- }
- System.err.println( path );
-
- return copy( metadata, path );
- }
-
- @Test
- public void testFindLocalMetadata()
- throws Exception
- {
- addMetadata( metadata, null );
-
- LocalMetadataRequest request = new LocalMetadataRequest( metadata, null, testContext );
- LocalMetadataResult result = manager.find( session, request );
-
- assertNotNull( result.getFile() );
- }
-
- @Test
- public void testFindLocalMetadataNoVersion()
- throws Exception
- {
- addMetadata( noVerMetadata, null );
-
- LocalMetadataRequest request = new LocalMetadataRequest( noVerMetadata, null, testContext );
- LocalMetadataResult result = manager.find( session, request );
-
- assertNotNull( result.getFile() );
- }
-
- @Test
- public void testDoNotFindRemoteMetadataDifferentContext()
- throws Exception
- {
- addMetadata( noVerMetadata, repository );
- addMetadata( metadata, repository );
-
- LocalMetadataRequest request = new LocalMetadataRequest( noVerMetadata, repository, "different" );
- LocalMetadataResult result = manager.find( session, request );
- assertNull( result.getFile() );
-
- request = new LocalMetadataRequest( metadata, repository, "different" );
- result = manager.find( session, request );
- assertNull( result.getFile() );
- }
-
- @Test
- public void testFindArtifactUsesTimestampedVersion()
- throws Exception
- {
- Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
- File file = new File( basedir, manager.getPathForLocalArtifact( artifact ) );
- TestFileUtils.writeString( file, "test" );
- addLocalArtifact( artifact );
-
- artifact = artifact.setVersion( "1.0-20110329.221805-4" );
- LocalArtifactRequest request = new LocalArtifactRequest();
- request.setArtifact( artifact );
- LocalArtifactResult result = manager.find( session, request );
- assertNull( result.toString(), result.getFile() );
- assertFalse( result.toString(), result.isAvailable() );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/FailChecksumPolicyTest.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/FailChecksumPolicyTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/FailChecksumPolicyTest.java
deleted file mode 100644
index f36e0a0..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/FailChecksumPolicyTest.java
+++ /dev/null
@@ -1,94 +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 org.eclipse.aether.spi.connector.checksum.ChecksumPolicy;
-import org.eclipse.aether.transfer.ChecksumFailureException;
-import org.eclipse.aether.transfer.TransferResource;
-import org.junit.Before;
-import org.junit.Test;
-
-public class FailChecksumPolicyTest
-{
-
- private FailChecksumPolicy policy;
-
- private ChecksumFailureException exception;
-
- @Before
- public void setup()
- {
- policy = new FailChecksumPolicy( null, new TransferResource( "file:/dev/null", "file.txt", null, null ) );
- exception = new ChecksumFailureException( "test" );
- }
-
- @Test
- public void testOnTransferChecksumFailure()
- {
- assertFalse( policy.onTransferChecksumFailure( exception ) );
- }
-
- @Test
- public void testOnChecksumMatch()
- {
- assertTrue( policy.onChecksumMatch( "SHA-1", 0 ) );
- assertTrue( policy.onChecksumMatch( "SHA-1", ChecksumPolicy.KIND_UNOFFICIAL ) );
- }
-
- @Test
- public void testOnChecksumMismatch()
- throws Exception
- {
- try
- {
- policy.onChecksumMismatch( "SHA-1", 0, exception );
- fail( "No exception" );
- }
- catch ( ChecksumFailureException e )
- {
- assertSame( exception, e );
- }
- policy.onChecksumMismatch( "SHA-1", ChecksumPolicy.KIND_UNOFFICIAL, exception );
- }
-
- @Test
- public void testOnChecksumError()
- throws Exception
- {
- policy.onChecksumError( "SHA-1", 0, exception );
- }
-
- @Test
- public void testOnNoMoreChecksums()
- {
- try
- {
- policy.onNoMoreChecksums();
- fail( "No exception" );
- }
- catch ( ChecksumFailureException e )
- {
- assertTrue( e.getMessage().contains( "no checksums available" ) );
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-impl/src/test/java/org/eclipse/aether/internal/impl/IniArtifactDescriptorReader.java
----------------------------------------------------------------------
diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/IniArtifactDescriptorReader.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/IniArtifactDescriptorReader.java
deleted file mode 100644
index 4ae2b9b..0000000
--- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/IniArtifactDescriptorReader.java
+++ /dev/null
@@ -1,39 +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.impl.ArtifactDescriptorReader;
-
-/**
- */
-public class IniArtifactDescriptorReader
- extends org.eclipse.aether.internal.test.util.IniArtifactDescriptorReader
- implements ArtifactDescriptorReader
-{
-
- /**
- * Use the given prefix to load the artifact descriptions.
- */
- public IniArtifactDescriptorReader( String prefix )
- {
- super( prefix );
- }
-
-}