use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testResolveFromWorkspaceFallbackToRepository.
@Test
public void testResolveFromWorkspaceFallbackToRepository() throws IOException, ArtifactResolutionException {
session = new TestRepositorySystemSession() {
@Override
public WorkspaceReader getWorkspaceReader() {
return new WorkspaceReader() {
public WorkspaceRepository getRepository() {
return new WorkspaceRepository("default");
}
public List<String> findVersions(Artifact artifact) {
return Arrays.asList(artifact.getVersion());
}
public File findArtifact(Artifact artifact) {
return null;
}
};
}
};
connector.setExpectGet(artifact);
remoteRepositoryManager.setConnector(connector);
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue("exception on resolveArtifact", result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
connector.assertSeenExpected();
}
use of org.sonatype.aether.repository.RemoteRepository 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.repository.RemoteRepository in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testRepositoryEventsSuccessfulRemote.
@Test
public void testRepositoryEventsSuccessfulRemote() throws ArtifactResolutionException {
RecordingRepositoryListener listener = new RecordingRepositoryListener();
session.setRepositoryListener(listener);
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
resolver.resolveArtifact(session, request);
List<EventWrapper> events = listener.getEvents();
assertEquals(2, events.size());
EventWrapper event = events.get(0);
assertEquals(RecordingRepositoryListener.Type.ARTIFACT_RESOLVING, event.getType());
assertNull(event.getEvent().getException());
assertEquals(artifact, event.getEvent().getArtifact());
event = events.get(1);
assertEquals(RecordingRepositoryListener.Type.ARTIFACT_RESOLVED, event.getType());
assertNull(event.getEvent().getException());
assertEquals(artifact, event.getEvent().getArtifact().setFile(null));
}
use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testResolveRemoteArtifact.
@Test
public void testResolveRemoteArtifact() throws IOException, ArtifactResolutionException {
connector.setExpectGet(artifact);
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
connector.assertSeenExpected();
}
use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testLocalArtifactAvailable.
@Test
public void testLocalArtifactAvailable() throws ArtifactResolutionException {
session.setLocalRepositoryManager(new LocalRepositoryManager() {
public LocalRepository getRepository() {
return null;
}
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return null;
}
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return null;
}
public String getPathForLocalMetadata(Metadata metadata) {
return null;
}
public String getPathForLocalArtifact(Artifact artifact) {
return null;
}
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(true);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
}
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
Aggregations