Search in sources :

Example 1 with SimpleHttpLocation

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

the class HttpExistenceTest method simpleRetrieveOfAvailableUrl.

@Test
public void simpleRetrieveOfAvailableUrl() throws Exception {
    final String fname = "simple-retrieval.html";
    final String url = fixture.formatUrl(fname);
    fixture.getServer().expect(url, 200, fname);
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, true, true, true, true, null);
    final HttpExistence dl = new HttpExistence(url, location, fixture.getTransfer(new ConcreteResource(location, fname)), fixture.getHttp(), new ObjectMapper());
    final Boolean result = dl.call();
    final TransferException error = dl.getError();
    assertThat(error, nullValue());
    assertThat(result, notNullValue());
    assertThat(result, equalTo(true));
    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 2 with SimpleHttpLocation

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

the class HttpListTest method simpleCentralListing_Missing.

@Test
public void simpleCentralListing_Missing() throws Exception {
    final String dir = "central-missing/";
    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);
    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(), nullValue());
}
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 3 with SimpleHttpLocation

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

the class HttpListTest method simpleNexusListing.

@Test
public void simpleNexusListing() throws Exception {
    final String dir = "nexus-switchyard/";
    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());
    assertTrue(Arrays.equals(nexusswitchyard, 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)

Example 4 with SimpleHttpLocation

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

the class HttpListTest method simpleCentralListing_WriteListingFile.

@Test
public void simpleCentralListing_WriteListingFile() 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());
    assertTrue(Arrays.equals(centralbtm, result.getListing()));
    final List<String> lines = IOUtils.readLines(transfer.openInputStream());
    assertTrue("Listing file written incorrectly!", lines.equals(Arrays.asList(centralbtm)));
}
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 5 with SimpleHttpLocation

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

the class HttpDownloadTest method IOExceptionDuringDownloadTransferDeletesTargetFile.

@Test
@BMRule(name = "throw IOException during writeTarget copy operation", targetClass = "HttpDownload", targetMethod = "doCopy", targetLocation = "ENTRY", condition = "!flagged(\"firstCopy\")", action = "flag(\"firstCopy\"); throw new IOException(\"BMUnit exception\");")
public void IOExceptionDuringDownloadTransferDeletesTargetFile() throws Exception {
    final String content = "This is some content " + System.currentTimeMillis() + "." + System.nanoTime();
    final String path = "/path/to/file";
    fixture.getServer().expect("GET", fixture.formatUrl(path), new ExpectationHandler() {

        int count = 0;

        @Override
        public void handle(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws ServletException, IOException {
            httpServletResponse.setStatus(200);
            httpServletResponse.setHeader("Content-Length", Integer.toString(content.length()));
            PrintWriter writer = httpServletResponse.getWriter();
            if (count < 1) {
                writer.write(content.substring(0, content.length() / 2));
            } else {
                writer.write(content);
            }
            count++;
        }
    });
    final String baseUri = fixture.getBaseUri();
    final SimpleHttpLocation location = new SimpleHttpLocation("test", baseUri, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, path));
    final String url = fixture.formatUrl(path);
    assertThat(transfer.exists(), equalTo(false));
    // first call, server should quit transferring halfway through the transfer
    HttpDownload dl = new HttpDownload(url, location, transfer, new HashMap<Transfer, Long>(), new EventMetadata(), fixture.getHttp(), new ObjectMapper());
    DownloadJob resultJob = dl.call();
    TransferException error = dl.getError();
    assertThat(error, notNullValue());
    error.printStackTrace();
    assertThat(resultJob, notNullValue());
    Transfer result = resultJob.getTransfer();
    assertThat(result, notNullValue());
    assertThat(result.exists(), equalTo(false));
    assertThat(transfer.exists(), equalTo(false));
    // second call should hit upstream again and succeed.
    dl = new HttpDownload(url, location, transfer, new HashMap<Transfer, Long>(), new EventMetadata(), fixture.getHttp(), new ObjectMapper());
    resultJob = dl.call();
    error = dl.getError();
    assertThat(error, nullValue());
    assertThat(resultJob, notNullValue());
    result = resultJob.getTransfer();
    assertThat(result, notNullValue());
    assertThat(result.exists(), equalTo(true));
    assertThat(transfer.exists(), equalTo(true));
    final String urlPath = fixture.getUrlPath(url);
    assertThat(fixture.getAccessesFor(urlPath), equalTo(2));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) TransferException(org.commonjava.maven.galley.TransferException) ExpectationHandler(org.commonjava.test.http.expect.ExpectationHandler) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrintWriter(java.io.PrintWriter) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) 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