Search in sources :

Example 11 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider 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 12 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider 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)

Aggregations

CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)12 Location (org.commonjava.maven.galley.model.Location)11 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)10 Test (org.junit.Test)10 OutputStream (java.io.OutputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 File (java.io.File)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 TransferManager (org.commonjava.maven.galley.TransferManager)1 MemoryPasswordManager (org.commonjava.maven.galley.auth.MemoryPasswordManager)1 FileCacheProvider (org.commonjava.maven.galley.cache.FileCacheProvider)1 TestFileEventManager (org.commonjava.maven.galley.cache.testutil.TestFileEventManager)1 TestTransferDecorator (org.commonjava.maven.galley.cache.testutil.TestTransferDecorator)1 TransportManagerConfig (org.commonjava.maven.galley.config.TransportManagerConfig)1 NoOpFileEventManager (org.commonjava.maven.galley.event.NoOpFileEventManager)1 FileTransport (org.commonjava.maven.galley.filearc.FileTransport)1