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