use of org.commonjava.indy.client.core.IndyClientHttp in project indy by Commonjava.
the class GroupHttpHeadersFromSameRepoAsPomTest method assertContentLength.
private void assertContentLength(ArtifactStore store, String path, int length) throws IndyClientException {
IndyClientHttp http = httpModule.getHttp();
Map<String, String> headers = http.head(client.content().contentPath(store.getKey(), path));
assertThat(headers, notNullValue());
String clStr = headers.get("content-length");
assertThat(clStr, notNullValue());
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)));
}
use of org.commonjava.indy.client.core.IndyClientHttp in project indy by Commonjava.
the class GroupHttpHeadersFromSameRepoWhenNotInPathMaskTest method assertContentLength.
private void assertContentLength(ArtifactStore store, String path, int length) throws IndyClientException {
IndyClientHttp http = httpModule.getHttp();
Map<String, String> headers = http.head(client.content().contentPath(store.getKey(), path));
assertThat(headers, notNullValue());
String clStr = headers.get("content-length");
assertThat(clStr, notNullValue());
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)));
}
use of org.commonjava.indy.client.core.IndyClientHttp in project indy by Commonjava.
the class SettingsGeneratedForRemoteRepoTest method generateSettingsXml.
@Test
public void generateSettingsXml() throws Exception {
final IndyClientHttp http = getHttp();
// all mavdav requests are siblings of the default base-url suffix '/api/'
final String url = getDotMavenUrl("settings/remote/settings-central.xml");
System.out.println("Requesting: " + url);
final HttpResources resources = http.getRaw(new HttpGet(url));
InputStream stream = null;
Settings settings = null;
try {
stream = resources.getResponseStream();
settings = new SettingsXpp3Reader().read(stream);
} finally {
closeQuietly(stream);
closeQuietly(resources);
}
assertThat(settings.getLocalRepository(), equalTo("${user.home}/.m2/repo-remote-central"));
assertThat(settings.getMirrors(), notNullValue());
assertThat(settings.getMirrors().size(), equalTo(1));
final Mirror mirror = settings.getMirrors().get(0);
assertThat(mirror.getUrl(), equalTo(http.toIndyUrl("remote/central")));
}
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";
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.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 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";
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.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