use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository.
@Test
public void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() 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(false);
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);
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
return new VersionResult(request).setRepository(new LocalRepository("id")).setVersion(request.getArtifact().getVersion());
}
});
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testProgressEventsDataBuffer.
@Test
public void testProgressEventsDataBuffer() throws UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoRepositoryConnectorException {
byte[] bytes = "These are the test contents.\n".getBytes("UTF-8");
int count = 120000;
MessageDigest digest = MessageDigest.getInstance("SHA-1");
for (int i = 0; i < count; i++) {
digest.update(bytes);
}
byte[] hash = digest.digest();
File file = TestFileUtils.createTempFile(bytes, count);
Artifact artifact = new StubArtifact("gid:aid:ext:ver");
ArtifactUpload upA = new ArtifactUpload(artifact, file);
File dir = TestFileUtils.createTempDir("con-test");
File downAFile = new File(dir, "downA.file");
downAFile.deleteOnExit();
ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload upM = new MetadataUpload(metadata, file);
File downMFile = new File(dir, "downM.file");
downMFile.deleteOnExit();
MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
DigestingTransferListener listener = new DigestingTransferListener();
session.setTransferListener(listener);
RepositoryConnector connector = factory().newInstance(session, repository);
connector.put(Arrays.asList(upA), null);
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.put(null, Arrays.asList(upM));
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.get(Arrays.asList(downA), null);
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.get(null, Arrays.asList(downM));
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.close();
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultUpdateCheckManagerTest method testCheckMetadataErrorFromRepo.
@Test
public void testCheckMetadataErrorFromRepo() 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.setTransferErrorCachingEnabled(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"));
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultUpdateCheckManagerTest method testCheckMetadataErrorFromRepoNoCaching.
@Test
public void testCheckMetadataErrorFromRepoNoCaching() 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.setTransferErrorCachingEnabled(false);
manager.checkMetadata(session, check);
assertEquals(true, check.isRequired());
assertNull(check.getException());
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class PutTest method testClosedPut.
@Test(expected = Exception.class)
public void testClosedPut() throws Exception {
connector().close();
Metadata metadata = metadata("metadata");
List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
connector().put(null, uploads);
}
Aggregations