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));
}
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));
}
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));
}
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));
}
Aggregations