Search in sources :

Example 36 with SimpleLocation

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);
    }
}
Also used : TestTransferDecorator(org.commonjava.maven.galley.cache.testutil.TestTransferDecorator) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) TestFileEventManager(org.commonjava.maven.galley.cache.testutil.TestFileEventManager) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 37 with SimpleLocation

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));
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 38 with SimpleLocation

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));
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 39 with SimpleLocation

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 40 with SimpleLocation

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));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)42 Test (org.junit.Test)39 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)35 Location (org.commonjava.maven.galley.model.Location)26 Transfer (org.commonjava.maven.galley.model.Transfer)22 InputStream (java.io.InputStream)12 OutputStream (java.io.OutputStream)10 CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)7 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)7 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)6 OutputStreamWriter (java.io.OutputStreamWriter)5 PrintWriter (java.io.PrintWriter)5 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)5 File (java.io.File)4