Search in sources :

Example 41 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class HttpDownloadTest 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 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(false));
    assertThat(transfer.exists(), equalTo(false));
    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 42 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class TestTransport method createPublishJob.

@Override
public PublishJob createPublishJob(final ConcreteResource resource, final InputStream stream, final long length, final String contentType, final int timeoutSeconds) throws TransferException {
    final TestPublish job = publishes.get(resource);
    if (job == null) {
        throw new TransferException("No publish job registered for: {}", resource);
    }
    job.setContent(stream, length, contentType);
    return job;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) TestPublish(org.commonjava.maven.galley.testing.core.transport.job.TestPublish)

Example 43 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class HttpDownloadTest 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 Transfer transfer = fixture.getTransfer(new ConcreteResource(location, fname));
    final String url = fixture.formatUrl(fname);
    final String error = "Test Error.";
    final String path = fixture.getUrlPath(url);
    fixture.registerException(path, error);
    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 err = dl.getError();
    assertThat(err, notNullValue());
    assertThat(err.getMessage().contains(error), equalTo(true));
    assertThat(resultJob, notNullValue());
    final Transfer result = resultJob.getTransfer();
    assertThat(result, notNullValue());
    assertThat(transfer.exists(), equalTo(false));
    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 44 with TransferException

use of org.commonjava.maven.galley.TransferException 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 45 with TransferException

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

Aggregations

TransferException (org.commonjava.maven.galley.TransferException)49 IOException (java.io.IOException)17 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Transfer (org.commonjava.maven.galley.model.Transfer)12 ArrayList (java.util.ArrayList)9 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)9 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 OutputStream (java.io.OutputStream)7 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 InputStream (java.io.InputStream)6 Location (org.commonjava.maven.galley.model.Location)6 File (java.io.File)5 HashMap (java.util.HashMap)5 JarFile (java.util.jar.JarFile)5 ZipEntry (java.util.zip.ZipEntry)5 ZipFile (java.util.zip.ZipFile)5 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)5 Test (org.junit.Test)5 ExecutionException (java.util.concurrent.ExecutionException)4