Search in sources :

Example 16 with ArtifactTransferException

use of org.sonatype.aether.transfer.ArtifactTransferException in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveRemoteArtifactUnsuccessful.

@Test
public void testResolveRemoteArtifactUnsuccessful() throws IOException, ArtifactResolutionException {
    RecordingRepositoryConnector connector = new RecordingRepositoryConnector() {

        @Override
        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            super.get(artifactDownloads, metadataDownloads);
            ArtifactDownload download = artifactDownloads.iterator().next();
            ArtifactTransferException exception = new ArtifactNotFoundException(download.getArtifact(), null, "not found");
            download.setException(exception);
        }
    };
    connector.setExpectGet(artifact);
    remoteRepositoryManager.setConnector(connector);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
        assertNotNull(e.getResults());
        assertEquals(1, e.getResults().size());
        ArtifactResult result = e.getResults().get(0);
        assertSame(request, result.getRequest());
        assertFalse(result.getExceptions().isEmpty());
        assertTrue(result.getExceptions().get(0) instanceof ArtifactNotFoundException);
        Artifact resolved = result.getArtifact();
        assertNull(resolved);
    }
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) Collection(java.util.Collection) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Aggregations

ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)16 Test (org.junit.Test)12 Artifact (org.sonatype.aether.artifact.Artifact)12 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)9 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)7 File (java.io.File)4 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)4 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)4 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)4 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)4 Collection (java.util.Collection)3 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)3 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)3 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)3 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)3 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)2 FileNotFoundException (java.io.FileNotFoundException)1