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);
}
}
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);
}
}
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));
}
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());
}
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);
}
Aggregations