http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/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 65acfdb..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRepositorySystemTest.java +++ /dev/null @@ -1,115 +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.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.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, null ); - 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, null ); - 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() ); - } - -}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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-resolver/blob/3a1b8ae0/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 ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java deleted file mode 100644 index 7411a1d..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/Maven2RepositoryLayoutFactoryTest.java +++ /dev/null @@ -1,241 +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.net.URI; -import java.util.List; -import java.util.Locale; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.artifact.DefaultArtifact; -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.spi.connector.layout.RepositoryLayout; -import org.eclipse.aether.spi.connector.layout.RepositoryLayout.Checksum; -import org.eclipse.aether.transfer.NoRepositoryLayoutException; -import org.junit.Before; -import org.junit.Test; - -public class Maven2RepositoryLayoutFactoryTest -{ - - private DefaultRepositorySystemSession session; - - private Maven2RepositoryLayoutFactory factory; - - private RepositoryLayout layout; - - private RemoteRepository newRepo( String type ) - { - return new RemoteRepository.Builder( "test", type, "classpath:/nil" ).build(); - } - - private void assertChecksum( Checksum actual, String expectedUri, String expectedAlgo ) - { - assertEquals( expectedUri, actual.getLocation().toString() ); - assertEquals( expectedAlgo, actual.getAlgorithm() ); - } - - private void assertChecksums( List<Checksum> actual, String baseUri, String... algos ) - { - assertEquals( algos.length, actual.size() ); - for ( int i = 0; i < algos.length; i++ ) - { - String uri = baseUri + '.' + algos[i].replace( "-", "" ).toLowerCase( Locale.ENGLISH ); - assertChecksum( actual.get( i ), uri, algos[i] ); - } - } - - @Before - public void setUp() - throws Exception - { - session = TestUtils.newSession(); - factory = new Maven2RepositoryLayoutFactory(); - layout = factory.newInstance( session, newRepo( "default" ) ); - } - - @Test( expected = NoRepositoryLayoutException.class ) - public void testBadLayout() - throws Exception - { - factory.newInstance( session, newRepo( "DEFAULT" ) ); - } - - @Test - public void testArtifactLocation_Release() - { - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0" ); - URI uri = layout.getLocation( artifact, false ); - assertEquals( "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext", uri.toString() ); - uri = layout.getLocation( artifact, true ); - assertEquals( "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext", uri.toString() ); - } - - @Test - public void testArtifactLocation_Snapshot() - { - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0-20110329.221805-4" ); - URI uri = layout.getLocation( artifact, false ); - assertEquals( "g/i/d/a-i.d/1.0-SNAPSHOT/a-i.d-1.0-20110329.221805-4-cls.ext", uri.toString() ); - uri = layout.getLocation( artifact, true ); - assertEquals( "g/i/d/a-i.d/1.0-SNAPSHOT/a-i.d-1.0-20110329.221805-4-cls.ext", uri.toString() ); - } - - @Test - public void testMetadataLocation_RootLevel() - { - DefaultMetadata metadata = new DefaultMetadata( "archetype-catalog.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT ); - URI uri = layout.getLocation( metadata, false ); - assertEquals( "archetype-catalog.xml", uri.toString() ); - uri = layout.getLocation( metadata, true ); - assertEquals( "archetype-catalog.xml", uri.toString() ); - } - - @Test - public void testMetadataLocation_GroupLevel() - { - DefaultMetadata metadata = - new DefaultMetadata( "org.apache.maven.plugins", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT ); - URI uri = layout.getLocation( metadata, false ); - assertEquals( "org/apache/maven/plugins/maven-metadata.xml", uri.toString() ); - uri = layout.getLocation( metadata, true ); - assertEquals( "org/apache/maven/plugins/maven-metadata.xml", uri.toString() ); - } - - @Test - public void testMetadataLocation_ArtifactLevel() - { - DefaultMetadata metadata = - new DefaultMetadata( "org.apache.maven.plugins", "maven-jar-plugin", "maven-metadata.xml", - Metadata.Nature.RELEASE_OR_SNAPSHOT ); - URI uri = layout.getLocation( metadata, false ); - assertEquals( "org/apache/maven/plugins/maven-jar-plugin/maven-metadata.xml", uri.toString() ); - uri = layout.getLocation( metadata, true ); - assertEquals( "org/apache/maven/plugins/maven-jar-plugin/maven-metadata.xml", uri.toString() ); - } - - @Test - public void testMetadataLocation_VersionLevel() - { - DefaultMetadata metadata = - new DefaultMetadata( "org.apache.maven.plugins", "maven-jar-plugin", "1.0-SNAPSHOT", "maven-metadata.xml", - Metadata.Nature.RELEASE_OR_SNAPSHOT ); - URI uri = layout.getLocation( metadata, false ); - assertEquals( "org/apache/maven/plugins/maven-jar-plugin/1.0-SNAPSHOT/maven-metadata.xml", uri.toString() ); - uri = layout.getLocation( metadata, true ); - assertEquals( "org/apache/maven/plugins/maven-jar-plugin/1.0-SNAPSHOT/maven-metadata.xml", uri.toString() ); - } - - @Test - public void testArtifactChecksums_Download() - { - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0" ); - URI uri = layout.getLocation( artifact, false ); - List<Checksum> checksums = layout.getChecksums( artifact, false, uri ); - assertEquals( 2, checksums.size() ); - assertChecksum( checksums.get( 0 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.sha1", "SHA-1" ); - assertChecksum( checksums.get( 1 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.md5", "MD5" ); - } - - @Test - public void testArtifactChecksums_Upload() - { - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "ext", "1.0" ); - URI uri = layout.getLocation( artifact, true ); - List<Checksum> checksums = layout.getChecksums( artifact, true, uri ); - assertEquals( 2, checksums.size() ); - assertChecksum( checksums.get( 0 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.sha1", "SHA-1" ); - assertChecksum( checksums.get( 1 ), "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.ext.md5", "MD5" ); - } - - @Test - public void testMetadataChecksums_Download() - { - DefaultMetadata metadata = - new DefaultMetadata( "org.apache.maven.plugins", "maven-jar-plugin", "maven-metadata.xml", - Metadata.Nature.RELEASE_OR_SNAPSHOT ); - URI uri = layout.getLocation( metadata, false ); - List<Checksum> checksums = layout.getChecksums( metadata, false, uri ); - assertEquals( 2, checksums.size() ); - assertChecksum( checksums.get( 0 ), "org/apache/maven/plugins/maven-jar-plugin/maven-metadata.xml.sha1", - "SHA-1" ); - assertChecksum( checksums.get( 1 ), "org/apache/maven/plugins/maven-jar-plugin/maven-metadata.xml.md5", "MD5" ); - } - - @Test - public void testMetadataChecksums_Upload() - { - DefaultMetadata metadata = - new DefaultMetadata( "org.apache.maven.plugins", "maven-jar-plugin", "maven-metadata.xml", - Metadata.Nature.RELEASE_OR_SNAPSHOT ); - URI uri = layout.getLocation( metadata, true ); - List<Checksum> checksums = layout.getChecksums( metadata, true, uri ); - assertEquals( 2, checksums.size() ); - assertChecksum( checksums.get( 0 ), "org/apache/maven/plugins/maven-jar-plugin/maven-metadata.xml.sha1", - "SHA-1" ); - assertChecksum( checksums.get( 1 ), "org/apache/maven/plugins/maven-jar-plugin/maven-metadata.xml.md5", "MD5" ); - } - - @Test - public void testSignatureChecksums_Download() - { - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "asc", "1.0" ); - URI uri = layout.getLocation( artifact, false ); - List<Checksum> checksums = layout.getChecksums( artifact, false, uri ); - assertChecksums( checksums, "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.asc", "SHA-1", "MD5" ); - - artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.asc", "1.0" ); - uri = layout.getLocation( artifact, false ); - checksums = layout.getChecksums( artifact, false, uri ); - assertEquals( 0, checksums.size() ); - } - - @Test - public void testSignatureChecksums_Upload() - { - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "asc", "1.0" ); - URI uri = layout.getLocation( artifact, true ); - List<Checksum> checksums = layout.getChecksums( artifact, true, uri ); - assertChecksums( checksums, "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.asc", "SHA-1", "MD5" ); - - artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.asc", "1.0" ); - uri = layout.getLocation( artifact, true ); - checksums = layout.getChecksums( artifact, true, uri ); - assertEquals( 0, checksums.size() ); - } - - @Test - public void testSignatureChecksums_Force() - throws Exception - { - session.setConfigProperty( Maven2RepositoryLayoutFactory.CONFIG_PROP_SIGNATURE_CHECKSUMS, "true" ); - layout = factory.newInstance( session, newRepo( "default" ) ); - DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.asc", "1.0" ); - URI uri = layout.getLocation( artifact, true ); - List<Checksum> checksums = layout.getChecksums( artifact, true, uri ); - assertChecksums( checksums, "g/i/d/a-i.d/1.0/a-i.d-1.0-cls.jar.asc", "SHA-1", "MD5" ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-impl/src/test/java/org/eclipse/aether/internal/impl/PrioritizedComponentTest.java ---------------------------------------------------------------------- diff --git a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/PrioritizedComponentTest.java b/aether-impl/src/test/java/org/eclipse/aether/internal/impl/PrioritizedComponentTest.java deleted file mode 100644 index 989c1ad..0000000 --- a/aether-impl/src/test/java/org/eclipse/aether/internal/impl/PrioritizedComponentTest.java +++ /dev/null @@ -1,73 +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.junit.Test; - -public class PrioritizedComponentTest -{ - - @Test - public void testIsDisabled() - { - assertTrue( new PrioritizedComponent<String>( "", String.class, Float.NaN, 0 ).isDisabled() ); - assertFalse( new PrioritizedComponent<String>( "", String.class, 0, 0 ).isDisabled() ); - assertFalse( new PrioritizedComponent<String>( "", String.class, 1, 0 ).isDisabled() ); - assertFalse( new PrioritizedComponent<String>( "", String.class, -1, 0 ).isDisabled() ); - } - - @Test - public void testCompareTo() - { - assertCompare( 0, Float.NaN, Float.NaN ); - assertCompare( 0, 0, 0 ); - - assertCompare( 1, 0, 1 ); - assertCompare( 1, 2, Float.POSITIVE_INFINITY ); - assertCompare( 1, Float.NEGATIVE_INFINITY, -3 ); - - assertCompare( 1, Float.NaN, 0 ); - assertCompare( 1, Float.NaN, -1 ); - assertCompare( 1, Float.NaN, Float.NEGATIVE_INFINITY ); - assertCompare( 1, Float.NaN, Float.POSITIVE_INFINITY ); - - assertCompare( -1, Float.NaN, 0, 1 ); - assertCompare( -1, 10, 0, 1 ); - } - - private void assertCompare( int expected, float priority1, float priority2 ) - { - PrioritizedComponent<?> one = new PrioritizedComponent<String>( "", String.class, priority1, 0 ); - PrioritizedComponent<?> two = new PrioritizedComponent<String>( "", String.class, priority2, 0 ); - assertEquals( expected, one.compareTo( two ) ); - assertEquals( -expected, two.compareTo( one ) ); - } - - private void assertCompare( int expected, float priority, int index1, int index2 ) - { - PrioritizedComponent<?> one = new PrioritizedComponent<String>( "", String.class, priority, index1 ); - PrioritizedComponent<?> two = new PrioritizedComponent<String>( "", String.class, priority, index2 ); - assertEquals( expected, one.compareTo( two ) ); - assertEquals( -expected, two.compareTo( one ) ); - } - -}