use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.
the class CacheProviderTCK method lockThenWriteViaTransferSucceedsInSameThread.
@Test
public void lockThenWriteViaTransferSucceedsInSameThread() throws Exception {
final Location loc = new SimpleLocation("http://foo.com");
final String path = "my/path.txt";
final ConcreteResource res = new ConcreteResource(loc, path);
final CacheProvider cache = getCacheProvider();
cache.lockWrite(res);
final Transfer txfr = new Transfer(res, cache, new TestFileEventManager(), new TestTransferDecorator());
OutputStream out = null;
try {
out = txfr.openOutputStream(TransferOperation.UPLOAD);
IOUtils.write("this is a test", out);
} finally {
IOUtils.closeQuietly(out);
}
}
use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.
the class CacheProviderTCK method writeDeleteAndVerifyNonExistence.
@Test
public void writeDeleteAndVerifyNonExistence() throws Exception {
final String content = "This is a test";
final Location loc = new SimpleLocation("http://foo.com");
final String fname = "/path/to/my/file.txt";
final CacheProvider provider = getCacheProvider();
final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
out.write(content.getBytes("UTF-8"));
out.close();
assertThat(provider.exists(new ConcreteResource(loc, fname)), equalTo(true));
provider.delete(new ConcreteResource(loc, fname));
assertThat(provider.exists(new ConcreteResource(loc, fname)), equalTo(false));
}
use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.
the class CacheProviderTCK method writeCopyAndReadNewFile.
@Test
public void writeCopyAndReadNewFile() throws Exception {
final String content = "This is a test";
final Location loc = new SimpleLocation("http://foo.com");
final String fname = "/path/to/my/file.txt";
final Location loc2 = new SimpleLocation("http://bar.com");
final CacheProvider provider = getCacheProvider();
final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
out.write(content.getBytes("UTF-8"));
out.close();
provider.copy(new ConcreteResource(loc, fname), new ConcreteResource(loc2, fname));
final InputStream in = provider.openInputStream(new ConcreteResource(loc2, fname));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
final byte[] buf = new byte[512];
while ((read = in.read(buf)) > -1) {
baos.write(buf, 0, read);
}
final String result = new String(baos.toByteArray(), "UTF-8");
assertThat(result, equalTo(content));
}
use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.
the class ChecksummingInputStreamTest method verifyUsingMd5.
@Test
public void verifyUsingMd5() throws Exception {
final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), "my-path.txt"));
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("UTF-8");
final InputStream is = new ByteArrayInputStream(data);
ChecksummingInputStream stream = null;
final TestMetadataConsumer testConsumer = new TestMetadataConsumer();
try {
stream = new ChecksummingInputStream(new HashSet<AbstractChecksumGeneratorFactory<?>>(Arrays.asList(new Md5GeneratorFactory(), new Sha1GeneratorFactory(), new Sha256GeneratorFactory())), is, txfr, testConsumer, true);
logger.debug("Reading stream with {} bytes", data.length);
byte[] resultData = IOUtils.toByteArray(stream);
logger.debug("Result is {} bytes", resultData.length);
assertThat(Arrays.equals(resultData, data), equalTo(true));
} finally {
IOUtils.closeQuietly(stream);
}
final MessageDigest md = MessageDigest.getInstance("MD5");
md.update(data);
final byte[] digest = md.digest();
final String digestHex = Hex.encodeHexString(digest);
logger.debug("Verifying .md5 file");
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));
logger.debug("Verifying MD5 in metadata consumer");
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.SimpleLocation in project indy by Commonjava.
the class ContentControllerTest method detectHtml_SingleHtmlElementLine.
@Test
public void detectHtml_SingleHtmlElementLine() throws Exception {
final ConcreteResource res = new ConcreteResource(new SimpleLocation("test:uri"), "file.html");
final Transfer tx = fixture.getCache().getTransfer(res);
PrintWriter writer = null;
try {
writer = new PrintWriter(new OutputStreamWriter(tx.openOutputStream(TransferOperation.GENERATE)));
writer.print("<html>");
writer.flush();
} finally {
IOUtils.closeQuietly(writer);
}
assertThat(content.isHtmlContent(tx), equalTo(true));
}
Aggregations