Search in sources :

Example 6 with ArtifactDownload

use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.

the class GetTest method testDownloadCorrupted.

@Test
public void testDownloadCorrupted() throws Exception {
    RecordingTransferListener transferListener = new RecordingTransferListener();
    session().setTransferListener(transferListener);
    addDelivery("gid/aid/version/aid-version-classifier.extension", "artifact");
    addDelivery("gid/aid/version/aid-version-classifier.extension.sha1", "foo");
    addDelivery("gid/aid/version/aid-version-classifier.extension.md5", "bar");
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("bla");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_WARN);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
    TransferEvent corruptedEvent = null;
    for (TransferEvent e : transferListener.getEvents()) {
        if (TransferEvent.EventType.CORRUPTED.equals(e.getType())) {
            corruptedEvent = e;
            break;
        }
    }
    assertNotNull(corruptedEvent);
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) TransferEvent(org.sonatype.aether.transfer.TransferEvent) RecordingTransferListener(org.sonatype.aether.test.impl.RecordingTransferListener) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 7 with ArtifactDownload

use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.

the class GetTest method testDownloadArtifactChecksumFailure.

@Test
public void testDownloadArtifactChecksumFailure() throws Exception {
    addDelivery("gid/aid/version/aid-version-classifier.extension", "artifact");
    addDelivery("gid/aid/version/aid-version-classifier.extension.sha1", "foo");
    addDelivery("gid/aid/version/aid-version-classifier.extension.md5", "bar");
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("bla");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
    assertNotNull(down.getException());
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 8 with ArtifactDownload

use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.

the class GetTest method testDownloadArtifactNoChecksumAvailable.

@Test
public void testDownloadArtifactNoChecksumAvailable() throws Exception {
    addDelivery("gid/aid/version/aid-version-classifier.extension", "artifact");
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("foo");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
    TestFileUtils.assertContent("", f);
    assertNotNull(down.getException());
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 9 with ArtifactDownload

use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.

the class GetTest method testClosedGet.

@Test(expected = IllegalStateException.class)
public void testClosedGet() throws Exception {
    connector().close();
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("foo");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 10 with ArtifactDownload

use of org.sonatype.aether.spi.connector.ArtifactDownload in project sonatype-aether by sonatype.

the class TransferEventTester method testFailedTransferEvents.

/**
     * Test the order of events and their properties for the unsuccessful up- and download of artifact and metadata.
     * Failure is triggered by setting the file to transfer to {@code null} for uploads, and asking for a non-existent
     * item for downloads.
     */
public static void testFailedTransferEvents(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("us-ascii");
    File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
    Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, null);
    Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
    Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, null);
    Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
    connector.put(artUps, null);
    LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.get(artDowns, null);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.put(null, metaUps);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.get(null, metaDowns);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    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)

Aggregations

ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)28 File (java.io.File)21 Test (org.junit.Test)19 Artifact (org.sonatype.aether.artifact.Artifact)16 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)15 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)10 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)9 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)8 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)8 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)6 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)5 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)5 ArrayList (java.util.ArrayList)4 Metadata (org.sonatype.aether.metadata.Metadata)4 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)4 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)4 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)4 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3