Search in sources :

Example 21 with SimpleHttpLocation

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

the class HttpDownloadTest method partialDownloadDeletesTargetFile.

@Test
public void partialDownloadDeletesTargetFile() 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) Test(org.junit.Test)

Example 22 with SimpleHttpLocation

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

the class HttpDownloadTest method simpleRetrieveOfAvailableUrl.

@Test
public void simpleRetrieveOfAvailableUrl() throws Exception {
    final String fname = "simple-retrieval.html";
    fixture.getServer().expect(fixture.formatUrl(fname), 200, fname);
    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, fname));
    final String url = fixture.formatUrl(fname);
    Map<Transfer, Long> transferSizes = new HashMap<Transfer, Long>();
    assertThat(transfer.exists(), equalTo(false));
    final HttpDownload dl = new HttpDownload(url, location, transfer, transferSizes, new EventMetadata(), fixture.getHttp(), new ObjectMapper());
    final DownloadJob resultJob = dl.call();
    final TransferException error = dl.getError();
    assertThat(error, nullValue());
    assertThat(resultJob, notNullValue());
    final Transfer result = resultJob.getTransfer();
    assertThat(result, notNullValue());
    assertThat(result.exists(), equalTo(true));
    assertThat(transfer.exists(), equalTo(true));
    final String path = fixture.getUrlPath(url);
    assertThat(fixture.getAccessesFor(path), equalTo(1));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) TransferException(org.commonjava.maven.galley.TransferException) HashMap(java.util.HashMap) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DownloadJob(org.commonjava.maven.galley.spi.transport.DownloadJob) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 23 with SimpleHttpLocation

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

the class HttpExistenceTest method simpleRetrieveOfMissingUrl.

@Test
public void simpleRetrieveOfMissingUrl() throws Exception {
    final String fname = "simple-missing.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 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();
    // if ( error != null )
    // {
    // error.printStackTrace();
    // }
    assertThat(error, nullValue());
    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 24 with SimpleHttpLocation

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

the class MavenContentFilteringTransferDecoratorTest method releaseListingInWhenSnapshotsNotAllowedWithVersionPath.

@Test
public void releaseListingInWhenSnapshotsNotAllowedWithVersionPath() throws Exception {
    final String fname = "commons-codec/commons-codec/1.1/";
    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);
    final List<String> listElems = Arrays.asList("commons-codec-1.1.jar", "commons-codec-1.1-source.jar", "maven-metadata.xml");
    String[] listing = listElems.toArray(new String[3]);
    MavenContentsFilteringTransferDecorator decorator = new MavenContentsFilteringTransferDecorator();
    listing = decorator.decorateListing(transfer, listing, new EventMetadata());
    assertThat(listing, CoreMatchers.notNullValue());
    assertThat(listing.length, equalTo(3));
    assertThat(Arrays.asList(listing).containsAll(listElems), equalTo(true));
}
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)

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