Search in sources :

Example 11 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project indy by Commonjava.

the class MavenContentFilteringTransferDecoratorTest method hugeVersionListMetadataWritable.

@Test
public void hugeVersionListMetadataWritable() throws Exception {
    final String fname = "/org/foo/bar/maven-metadata.xml";
    final String content = getHugeVersionListMetadata();
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, false, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, fname));
    final String url = fixture.formatUrl(fname);
    assertThat(transfer.exists(), equalTo(false));
    try (OutputStream stream = transfer.openOutputStream(TransferOperation.UPLOAD)) {
        IOUtils.write(content, stream);
    }
    try (InputStream in = transfer.openInputStream()) {
        List<String> filtered = IOUtils.readLines(in);
        assertThat(filtered, notNullValue());
        StringBuilder builder = new StringBuilder();
        filtered.forEach(builder::append);
        String result = builder.toString();
        assertThat(result.length() > 1000, equalTo(true));
    }
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test)

Example 12 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project indy by Commonjava.

the class MavenContentFilteringTransferDecoratorTest method snapshotListingNotInWhenSnapshotsNotAllowedWithVersionPath.

@Test
public void snapshotListingNotInWhenSnapshotsNotAllowedWithVersionPath() throws Exception {
    final String fname = "commons-codec/commons-codec/1.1-SNAPSHOT/";
    final SimpleHttpLocation location = new SimpleHttpLocation("test", "http://test", false, true, false, false, null);
    final ConcreteResource resource = new ConcreteResource(location, fname);
    final Transfer transfer = new Transfer(resource, null, null, null);
    String[] listing = Arrays.asList("commons-codec-1.1-SNAPSHOT.jar", "commons-codec-1.1-SNAPSHOT-source.jar", "maven-metadata.xml").toArray(new String[4]);
    MavenContentsFilteringTransferDecorator decorator = new MavenContentsFilteringTransferDecorator();
    listing = decorator.decorateListing(transfer, listing, new EventMetadata());
    assertThat(listing, CoreMatchers.notNullValue());
    assertThat(listing.length, equalTo(0));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 13 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpExistenceTest method simpleRetrieveOfUrlWithError.

@Test
public void simpleRetrieveOfUrlWithError() throws Exception {
    final String fname = "simple-error.html";
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, true, true, true, true, null);
    final String url = fixture.formatUrl(fname);
    final String error = "Test Error.";
    fixture.registerException(fixture.getUrlPath(url), error);
    final HttpExistence dl = new HttpExistence(url, location, fixture.getTransfer(new ConcreteResource(location, fname)), fixture.getHttp(), new ObjectMapper());
    final Boolean result = dl.call();
    final TransferException err = dl.getError();
    assertThat(err, notNullValue());
    assertThat(result, notNullValue());
    assertThat(result, equalTo(false));
    final String path = fixture.getUrlPath(url);
    assertThat(fixture.getAccessesFor("HEAD", path), equalTo(1));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 14 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpListTest method simpleCentralListing_Error.

@Test
public void simpleCentralListing_Error() throws Exception {
    final String dir = "central-error/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    fixture.registerException(fixture.getUrlPath(url), "Test Error");
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(result, nullValue());
    assertThat(listing.getError(), notNullValue());
    assertTrue(listing.getError().getMessage().contains("Test Error"));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 15 with SimpleHttpLocation

use of org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation in project galley by Commonjava.

the class HttpListTest method simpleCentralListing.

@Test
public void simpleCentralListing() throws Exception {
    final String dir = "central-btm/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final String body = getBody(fname);
    fixture.getServer().expect(url, 200, body);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(listing.getError(), nullValue());
    assertThat(result, notNullValue());
    assertThat(result.getListing(), notNullValue());
    System.out.println("Got listing\n\n  " + StringUtils.join(result.getListing(), "\n  ") + "\n\n");
    assertTrue(Arrays.equals(centralbtm, result.getListing()));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Aggregations

SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)24 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)22 Test (org.junit.Test)21 Transfer (org.commonjava.maven.galley.model.Transfer)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)10 TransferException (org.commonjava.maven.galley.TransferException)9 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 HashMap (java.util.HashMap)6 DownloadJob (org.commonjava.maven.galley.spi.transport.DownloadJob)6 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 ExpectationHandler (org.commonjava.test.http.expect.ExpectationHandler)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)2