Search in sources :

Example 16 with MetadataUpload

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);
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) TransferEvent(org.sonatype.aether.transfer.TransferEvent) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RecordingTransferListener(org.sonatype.aether.test.impl.RecordingTransferListener) LinkedList(java.util.LinkedList) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File)

Example 17 with MetadataUpload

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);
}
Also used : DefaultMetadata(org.sonatype.aether.util.metadata.DefaultMetadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) Test(org.junit.Test)

Example 18 with MetadataUpload

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);
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) Test(org.junit.Test)

Aggregations

MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)18 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)13 Test (org.junit.Test)10 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)9 File (java.io.File)8 Metadata (org.sonatype.aether.metadata.Metadata)8 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)8 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)8 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)5 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)5 Artifact (org.sonatype.aether.artifact.Artifact)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 RecordingTransferListener (org.sonatype.aether.test.impl.RecordingTransferListener)2 TransferEvent (org.sonatype.aether.transfer.TransferEvent)2 IOException (java.io.IOException)1 MessageDigest (java.security.MessageDigest)1 IdentityHashMap (java.util.IdentityHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1