use of org.commonjava.indy.client.core.IndyClientHttp in project indy by Commonjava.
the class StoreOneAndVerifyInHtmlListingTest method storeOneFileAndVerifyItInParentDirectoryListing.
@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
final byte[] data = "this is a test".getBytes();
final ByteArrayInputStream stream = new ByteArrayInputStream(data);
final String root = "/path/to/";
final String path = root + "foo.txt";
client.content().store(hosted, STORE, path, stream);
final IndyClientHttp http = getHttp();
final HttpGet request = http.newRawGet(client.content().contentUrl(hosted, STORE, root));
request.addHeader("Accept", "text/html");
final CloseableHttpClient hc = http.newClient();
final CloseableHttpResponse response = hc.execute(request);
final InputStream listing = response.getEntity().getContent();
final String html = IOUtils.toString(listing);
// TODO: Charset!!
final Document doc = Jsoup.parse(html);
for (final Element item : doc.select("a.item-link")) {
final String fname = item.text();
System.out.printf("Listing contains: '%s'\n", fname);
final String href = item.attr("href");
final String expected = client.content().contentUrl(hosted, STORE, root, fname);
assertThat(fname + " does not have a href", href, notNullValue());
assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName() + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
}
}
use of org.commonjava.indy.client.core.IndyClientHttp in project indy by Commonjava.
the class GroupHttpHeadersFromSameRepoWhenNotInPathMaskTest method assertGetContentAndLength.
private void assertGetContentAndLength(ArtifactStore store, String path, String content) throws IndyClientException, IOException {
IndyClientHttp http = httpModule.getHttp();
try (HttpResources resources = http.getRaw(client.content().contentPath(store.getKey(), path))) {
HttpResponse response = resources.getResponse();
assertThat("Request " + store.getKey() + ":" + path + " failed with status: " + response.getStatusLine(), response.getStatusLine().getStatusCode(), equalTo(200));
Header header = response.getFirstHeader("Content-Length");
assertThat("Content-Length header missing: " + store.getKey() + ":" + path, header, notNullValue());
String clStr = header.getValue();
assertThat(clStr, notNullValue());
long length = content.getBytes().length;
Long len = Long.parseLong(clStr);
assertThat("Error: " + store.getKey() + ":" + path + ": had incorrect retrieved content-length (" + len + "); should have been: " + length, len, equalTo(Long.valueOf(length)));
assertThat("Unexpected response content: " + store.getKey() + ":" + path, IOUtils.toString(resources.getResponseEntityContent()), equalTo(content));
}
}
use of org.commonjava.indy.client.core.IndyClientHttp in project indy by Commonjava.
the class StoreOneAndSourceStoreUrlInHtmlListingTest method storeOneFileAndVerifyItInParentDirectoryListing.
@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
final byte[] data = "this is a test".getBytes();
final ByteArrayInputStream stream = new ByteArrayInputStream(data);
final String root = "/path/to/";
final String path = root + "foo.txt";
final String track = "track";
content.store(track, hosted, STORE, path, stream);
final IndyClientHttp http = getHttp();
final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root));
request.addHeader("Accept", "text/html");
final CloseableHttpClient hc = http.newClient();
final CloseableHttpResponse response = hc.execute(request);
final InputStream listing = response.getEntity().getContent();
final String html = IOUtils.toString(listing);
// TODO: Charset!!
final Document doc = Jsoup.parse(html);
for (final Element item : doc.select("a.source-link")) {
final String fname = item.text();
System.out.printf("Listing contains: '%s'\n", fname);
final String href = item.attr("href");
final String expected = client.content().contentUrl(hosted, STORE);
assertThat(fname + " does not have a href", href, notNullValue());
assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName() + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
}
}
Aggregations