Search in sources :

Example 1 with IndyClientHttp

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)));
}
Also used : IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp)

Example 2 with IndyClientHttp

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)));
}
Also used : IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp)

Example 3 with IndyClientHttp

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")));
}
Also used : InputStream(java.io.InputStream) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpGet(org.apache.http.client.methods.HttpGet) SettingsXpp3Reader(org.apache.maven.settings.io.xpp3.SettingsXpp3Reader) Mirror(org.apache.maven.settings.Mirror) Settings(org.apache.maven.settings.Settings) Test(org.junit.Test)

Example 4 with IndyClientHttp

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));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.jsoup.nodes.Element) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 5 with IndyClientHttp

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));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.jsoup.nodes.Element) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

IndyClientHttp (org.commonjava.indy.client.core.IndyClientHttp)8 InputStream (java.io.InputStream)5 HttpGet (org.apache.http.client.methods.HttpGet)5 Test (org.junit.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)4 Document (org.jsoup.nodes.Document)4 Element (org.jsoup.nodes.Element)4 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)2 Header (org.apache.http.Header)1 HttpResponse (org.apache.http.HttpResponse)1 Mirror (org.apache.maven.settings.Mirror)1 Settings (org.apache.maven.settings.Settings)1 SettingsXpp3Reader (org.apache.maven.settings.io.xpp3.SettingsXpp3Reader)1