Search in sources :

Example 16 with ArtifactUpload

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

the class RecordingRepositoryConnector method put.

public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
    if (artifactUploads != null) {
        for (ArtifactUpload artifactUpload : artifactUploads) {
            // mimic "real" connector
            artifactUpload.setState(State.ACTIVE);
            if (artifactUpload.getFile() == null) {
                artifactUpload.setException(new ArtifactTransferException(artifactUpload.getArtifact(), null, "no file"));
            }
            this.actualPut.add(artifactUpload.getArtifact());
            artifactUpload.setState(State.DONE);
        }
    }
    if (metadataUploads != null) {
        for (MetadataUpload metadataUpload : metadataUploads) {
            // mimic "real" connector
            metadataUpload.setState(State.ACTIVE);
            if (metadataUpload.getFile() == null) {
                metadataUpload.setException(new MetadataTransferException(metadataUpload.getMetadata(), null, "no file"));
            }
            this.actualPutMD.add(metadataUpload.getMetadata());
            metadataUpload.setState(State.DONE);
        }
    }
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException)

Example 17 with ArtifactUpload

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

the class PutTest method testArtifactUpload.

@Test
public void testArtifactUpload() throws Exception {
    addExpectation("gid/aid/version/aid-version-classifier.extension", "artifact");
    addExpectation("gid/aid/version/aid-version-classifier.extension.sha1", sha1("artifact"));
    addExpectation("gid/aid/version/aid-version-classifier.extension.md5", md5("artifact"));
    Artifact artifact = artifact("artifact");
    ArtifactUpload up = new ArtifactUpload(artifact, artifact.getFile());
    List<ArtifactUpload> uploads = Arrays.asList(up);
    connector().put(uploads, null);
    ArtifactTransferException ex = up.getException();
    assertNull(ex != null ? ex.getMessage() : "", ex);
    assertExpectations();
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 18 with ArtifactUpload

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

the class PutTest method testArtifactWithZeroBytesFile.

@Test
@Ignore("https://issues.sonatype.org/browse/AHC-5")
public void testArtifactWithZeroBytesFile() throws Exception {
    String content = "";
    addExpectation("gid/aid/version/aid-version-classifier.extension", content);
    addExpectation("gid/aid/version/aid-version-classifier.extension.sha1", sha1(content));
    addExpectation("gid/aid/version/aid-version-classifier.extension.md5", md5(content));
    Artifact artifact = artifact(content);
    ArtifactUpload up = new ArtifactUpload(artifact, artifact.getFile());
    List<ArtifactUpload> uploads = Arrays.asList(up);
    connector().put(uploads, null);
    ArtifactTransferException ex = up.getException();
    assertNull(ex != null ? ex.getMessage() : "", ex);
    assertExpectations();
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) Artifact(org.sonatype.aether.artifact.Artifact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)18 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)13 File (java.io.File)9 Test (org.junit.Test)9 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)9 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)8 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)8 Artifact (org.sonatype.aether.artifact.Artifact)7 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)6 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)5 Metadata (org.sonatype.aether.metadata.Metadata)4 ArrayList (java.util.ArrayList)3 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)3 LinkedList (java.util.LinkedList)2 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)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