Search in sources :

Example 11 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation 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 12 with SimpleLocation

use of org.commonjava.maven.galley.model.SimpleLocation 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 13 with SimpleLocation

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

the class CacheProviderTCK method writeAndListDirectory.

@Test
public void writeAndListDirectory() throws Exception {
    final String content = "This is a test";
    final Location loc = new SimpleLocation("http://foo.com");
    final String dir = "/path/to/my/";
    final String fname = dir + "file.txt";
    final CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
    out.write(content.getBytes("UTF-8"));
    out.flush();
    out.close();
    // NOTE: This is NOT as tightly specified as I would like. 
    // We keep the listing assertions loose (greater-than instead of equals, 
    // contains instead of exact positional assertion) because the Infinispan
    // live testing has these spurious foo.txt.#0 files cropping up.
    //
    // I have no idea what they are, but I'm sick of fighting JBoss bugs for now.
    final Set<String> listing = new HashSet<String>(Arrays.asList(provider.list(new ConcreteResource(loc, dir))));
    System.out.printf("\n\nFile listing is:\n\n  %s\n\n\n", join(listing, "\n  "));
    assertThat(listing.size() > 0, equalTo(true));
    assertThat(listing.contains("file.txt"), equalTo(true));
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with SimpleLocation

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

the class CacheProviderTCK method writeAndVerifyExistence.

@Test
public void writeAndVerifyExistence() 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));
}
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 15 with SimpleLocation

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

the class CacheProviderTCK method lockThenWaitForLockReturnsImmediatelyInSameThread.

@Test
public void lockThenWaitForLockReturnsImmediatelyInSameThread() 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);
    cache.waitForWriteUnlock(res);
    assertThat(cache.isWriteLocked(res), equalTo(false));
}
Also used : 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)

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