use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testRepositoryEventsUnsuccessfulRemote.
@Test
public void testRepositoryEventsUnsuccessfulRemote() 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);
}
};
remoteRepositoryManager.setConnector(connector);
RecordingRepositoryListener listener = new RecordingRepositoryListener();
session.setRepositoryListener(listener);
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
try {
resolver.resolveArtifact(session, request);
fail("expected exception");
} catch (ArtifactResolutionException e) {
}
List<EventWrapper> events = listener.getEvents();
assertEquals(2, events.size());
EventWrapper event = events.get(0);
assertEquals(artifact, event.getEvent().getArtifact());
assertEquals(Type.ARTIFACT_RESOLVING, event.getType());
event = events.get(1);
assertEquals(artifact, event.getEvent().getArtifact());
assertEquals(Type.ARTIFACT_RESOLVED, event.getType());
assertNotNull(event.getEvent().getException());
assertEquals(1, event.getEvent().getExceptions().size());
}
use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testArtifactNotFoundCache.
@Test
public void testArtifactNotFoundCache() throws Exception {
RecordingRepositoryConnector connector = new RecordingRepositoryConnector() {
@Override
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
super.get(artifactDownloads, metadataDownloads);
for (ArtifactDownload download : artifactDownloads) {
download.getFile().delete();
ArtifactTransferException exception = new ArtifactNotFoundException(download.getArtifact(), null, "not found");
download.setException(exception);
}
}
};
remoteRepositoryManager.setConnector(connector);
resolver.setUpdateCheckManager(new DefaultUpdateCheckManager());
session.setNotFoundCachingEnabled(true);
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
RemoteRepository remoteRepo = new RemoteRepository("id", "default", "file:///");
Artifact artifact1 = artifact;
Artifact artifact2 = artifact.setVersion("ver2");
ArtifactRequest request1 = new ArtifactRequest(artifact1, Arrays.asList(remoteRepo), "");
ArtifactRequest request2 = new ArtifactRequest(artifact2, Arrays.asList(remoteRepo), "");
connector.setExpectGet(new Artifact[] { artifact1, artifact2 });
try {
resolver.resolveArtifacts(session, Arrays.asList(request1, request2));
fail("expected exception");
} catch (ArtifactResolutionException e) {
connector.assertSeenExpected();
}
TestFileUtils.write("artifact", new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact2)));
lrm.setArtifactAvailability(artifact2, false);
DefaultUpdateCheckManagerTest.resetSessionData(session);
connector.resetActual();
connector.setExpectGet(new Artifact[0]);
try {
resolver.resolveArtifacts(session, Arrays.asList(request1, request2));
fail("expected exception");
} catch (ArtifactResolutionException e) {
connector.assertSeenExpected();
for (ArtifactResult result : e.getResults()) {
Throwable t = result.getExceptions().get(0);
assertEquals(t.toString(), true, t instanceof ArtifactNotFoundException);
assertEquals(t.toString(), true, t.getMessage().contains("cached"));
}
}
}
use of org.sonatype.aether.spi.connector.ArtifactDownload 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);
}
}
Aggregations