Search in sources :

Example 1 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class EmbeddableCDI_HTTPArtifactDownload_Test method resolveArtifactViaHttp.

@Test
public void resolveArtifactViaHttp() throws Exception {
    String path = "/group/artifact/1/artifact-1.pom";
    String content = "this is a test.";
    server.expect(path, 200, content);
    Transfer transfer = transfers.retrieve(new SimpleLocation(server.getBaseUri()), new SimpleProjectVersionRef("group", "artifact", "1").asPomArtifact());
    assertThat(transfer, notNullValue());
    InputStream stream = null;
    try {
        stream = transfer.openInputStream();
        assertThat(IOUtils.toString(stream), equalTo(content));
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 2 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class EmbeddableCDI_HTTPDownload_Test method resolveFileViaHttp.

@Test
public void resolveFileViaHttp() throws Exception {
    String path = "/path/to/file.txt";
    String content = "this is a test.";
    server.expect(path, 200, content);
    Transfer transfer = transfers.retrieve(new ConcreteResource(new SimpleLocation(server.getBaseUri()), path));
    assertThat(transfer, notNullValue());
    InputStream stream = null;
    try {
        stream = transfer.openInputStream();
        assertThat(IOUtils.toString(stream), equalTo(content));
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Test(org.junit.Test)

Example 3 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class ChecksummingOutputStreamTest method verifyUsingMd5.

@Test
public void verifyUsingMd5() throws Exception {
    final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), "my-path.txt"));
    final OutputStream os = new ByteArrayOutputStream();
    final byte[] data = "This is a test with a bunch of data and some other stuff, in a big box sealed with chewing gum".getBytes();
    ChecksummingOutputStream stream = null;
    final TestMetadataConsumer testConsumer = new TestMetadataConsumer();
    try {
        stream = new ChecksummingOutputStream(new HashSet<AbstractChecksumGeneratorFactory<?>>(Arrays.asList(new Md5GeneratorFactory(), new Sha1GeneratorFactory(), new Sha256GeneratorFactory())), os, txfr, testConsumer, true);
        stream.write(data);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    final MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(data);
    final byte[] digest = md.digest();
    final String digestHex = Hex.encodeHexString(digest);
    final Transfer md5Txfr = txfr.getSiblingMeta(".md5");
    InputStream in = null;
    String resultHex = null;
    try {
        in = md5Txfr.openInputStream();
        resultHex = IOUtils.toString(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
    assertThat(resultHex, equalTo(digestHex));
    TransferMetadata metadata = testConsumer.getMetadata(txfr);
    assertThat(metadata, notNullValue());
    Map<ContentDigest, String> digests = metadata.getDigests();
    assertThat(digests, CoreMatchers.<Map<ContentDigest, String>>notNullValue());
    assertThat(digests.get(MD5), equalTo(digestHex));
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) TestMetadataConsumer(org.commonjava.maven.galley.io.checksum.testutil.TestMetadataConsumer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MessageDigest(java.security.MessageDigest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class ChecksummingTransferDecoratorTest method noChecksumOnReadWhenChecksumsAreDisabledForReads.

@Test
public void noChecksumOnReadWhenChecksumsAreDisabledForReads() throws Exception {
    fixture.setDecorator(new ChecksummingTransferDecorator(Collections.<TransferOperation>emptySet(), new SpecialPathManagerImpl(), false, false, metadataConsumer, new Md5GeneratorFactory()));
    fixture.initMissingComponents();
    fixture.getCache().startReporting();
    String path = "my-path.txt";
    final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), path));
    File f = new File(temp.getRoot(), "cache/test:uri");
    f = new File(f, path);
    byte[] data = "This is a test with a bunch of data and some other stuff, in a big box sealed with chewing gum".getBytes();
    FileUtils.writeByteArrayToFile(f, data);
    logger.info("Opening transfer input stream");
    EventMetadata forceEventMetadata = new EventMetadata();
    try (InputStream stream = txfr.openInputStream(false, forceEventMetadata)) {
        logger.info("Reading stream");
        byte[] resultData = IOUtils.toByteArray(stream);
        logger.debug("Result is {} bytes", resultData.length);
        assertThat(Arrays.equals(resultData, data), equalTo(true));
    }
    logger.debug("Verifying .md5 file is missing");
    final Transfer md5Txfr = txfr.getSiblingMeta(".md5");
    assertThat(md5Txfr.exists(), equalTo(false));
    logger.debug("Verifying MD5 in metadata consumer is missing");
    TransferMetadata metadata = metadataConsumer.getMetadata(txfr);
    assertThat(metadata, nullValue());
}
Also used : InputStream(java.io.InputStream) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) File(java.io.File) Test(org.junit.Test)

Example 5 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class ChecksummingTransferDecoratorTest method customChecksumReaderFilter.

@Test
public void customChecksumReaderFilter() throws Exception {
    String path = "my-path.txt";
    fixture.setDecorator(new ChecksummingTransferDecorator(new TestDecoratorAdvisor(), new DisabledChecksummingDecoratorAdvisor(), new SpecialPathManagerImpl(), metadataConsumer, new Md5GeneratorFactory()));
    fixture.initMissingComponents();
    fixture.getCache().startReporting();
    final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), path));
    File f = new File(temp.getRoot(), "cache/test:uri");
    f = new File(f, path);
    byte[] data = "This is a test with a bunch of data and some other stuff, in a big box sealed with chewing gum".getBytes();
    FileUtils.writeByteArrayToFile(f, data);
    EventMetadata em = new EventMetadata();
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, false, false);
    em = new EventMetadata().set(DO_CHECKSUMS, ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_NO_WRITE);
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, false, true);
    logger.debug("Removing checksum metadata from consumer");
    metadataConsumer.removeMetadata(txfr);
    em = new EventMetadata().set(DO_CHECKSUMS, ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_AND_WRITE);
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, true, true);
}
Also used : TestDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.testutil.TestDecoratorAdvisor) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) File(java.io.File) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

Transfer (org.commonjava.maven.galley.model.Transfer)218 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)89 Test (org.junit.Test)80 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)64 IOException (java.io.IOException)63 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)59 InputStream (java.io.InputStream)43 StoreKey (org.commonjava.indy.model.core.StoreKey)43 Logger (org.slf4j.Logger)34 ArrayList (java.util.ArrayList)33 OutputStream (java.io.OutputStream)31 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)31 HostedRepository (org.commonjava.indy.model.core.HostedRepository)29 IndyDataException (org.commonjava.indy.data.IndyDataException)28 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)28 Group (org.commonjava.indy.model.core.Group)26 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)23 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)21 TransferException (org.commonjava.maven.galley.TransferException)20 Location (org.commonjava.maven.galley.model.Location)19