use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class TransferEventTester method testSuccessfulTransferEvents.
/**
* Test the order of events and their properties for the successful up- and download of artifact and metadata.
*/
public static void testSuccessfulTransferEvents(RepositoryConnectorFactory factory, TestRepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException, IOException {
RecordingTransferListener listener = new RecordingTransferListener(session.getTransferListener());
session.setTransferListener(listener);
RepositoryConnector connector = factory.newInstance(session, repository);
byte[] pattern = "tmpFile".getBytes();
File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
long expectedBytes = tmpFile.length();
Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, tmpFile);
Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, tmpFile);
Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
connector.put(artUps, null);
LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
listener.clear();
connector.get(artDowns, null);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
listener.clear();
connector.put(null, metaUps);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
listener.clear();
connector.get(null, metaDowns);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
connector.close();
session.setTransferListener(null);
}
use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class ArtifactWorkerTest method testMetadataTransfer.
@Test
public void testMetadataTransfer() throws IOException, MetadataTransferException {
String expectedContent = "Dies ist ein Test.";
File srcFile = TestFileUtils.createTempFile(expectedContent);
DefaultMetadata metadata = new DefaultMetadata("test", "artId1", "1", "jar", Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload up = new MetadataUpload(metadata, srcFile);
FileRepositoryWorker worker = new FileRepositoryWorker(up, repository, session);
worker.setFileProcessor(TestFileProcessor.INSTANCE);
worker.run();
if (up.getException() != null) {
throw up.getException();
}
File targetFile = TestFileUtils.createTempFile("");
TestFileUtils.delete(targetFile);
MetadataDownload down = new MetadataDownload();
down.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
down.setMetadata(metadata).setFile(targetFile);
worker = new FileRepositoryWorker(down, repository, session);
worker.setFileProcessor(TestFileProcessor.INSTANCE);
worker.run();
if (down.getException() != null) {
throw down.getException();
}
assertTrue("download did not happen.", targetFile.exists());
assertContentEquals(targetFile, expectedContent);
}
use of org.sonatype.aether.spi.connector.MetadataUpload 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