Search in sources :

Example 61 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class RemoteRepoHeadErrorTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String path = "org/foo/bar/maven-metadata.xml";
    server.registerException(server.formatUrl(repo1, path), "upstream error");
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repo1, path)) {
    } catch (final IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
    }
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 62 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class RemoteRepoHeadExistenceCheckTest method run.

@Ignore
@Test
public void run() throws Exception {
    final InputStream stream = new ByteArrayInputStream(("{\"content\": \"This is a test: " + System.nanoTime() + "\"}").getBytes());
    final String path = "org/foo/foo-project/1/foo-1.txt";
    final String nonExistPath = "org/foo/foo-project/1/foo-2.txt";
    server.expect(server.formatUrl(STORE, path), 200, stream);
    server.expect(server.formatUrl(STORE, nonExistPath), 404, "not exist");
    client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
    final PathInfo result = client.content().getInfo(remote, STORE, path);
    try {
        boolean exists = client.content().exists(remote, STORE, path);
        assertTrue(exists);
        File f = new File(new File(fixture.getBootOptions().getIndyHome()), "var/lib/indy/storage/remote-test/" + path);
        assertTrue(!f.exists());
        //TODO: this breaks because for whatever reason the head can not get content-length and we have to fall over to get().
        //Refer to NCL-2729 and we will have a better fix in future
        exists = client.content().exists(remote, STORE, nonExistPath);
        assertFalse(exists);
    } catch (final IndyClientException e) {
        fail("IndyClientException: " + e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) IndyClientException(org.commonjava.indy.client.core.IndyClientException) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 63 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class GroupIgnoresDisabledRemoteRepositoryTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String repo2 = "repo2";
    final String path = "path/to/test.txt";
    String disabledContent = "This is disabled.";
    String enabledContent = "This is enabled.";
    server.expect(server.formatUrl(repo1, path), 200, disabledContent);
    server.expect(server.formatUrl(repo2, path), 200, enabledContent);
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1.setDisabled(true);
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
    remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
    Group g = new Group("test", remote1.getKey(), remote2.getKey());
    g = client.stores().create(g, "adding group", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    final InputStream stream = client.content().get(group, g.getName(), path);
    assertThat(stream, notNullValue());
    final String content = IOUtils.toString(stream);
    assertThat(content, equalTo(enabledContent));
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 64 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class GroupMetadataMergeWithRepoErrorTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String repo2 = "repo2";
    final String path = "org/foo/bar/maven-metadata.xml";
    /* @formatter:off */
    final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.0</latest>\n" + "    <release>1.0</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20150722164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    server.expect(server.formatUrl(repo1, path), 200, repo1Content);
    server.registerException(server.formatUrl(repo2, path), "Server error");
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
    remote2.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
    Group g = new Group("test", remote1.getKey(), remote2.getKey());
    g = client.stores().create(g, "adding group", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    final InputStream stream = client.content().get(group, g.getName(), path);
    assertThat(stream, notNullValue());
    final String metadata = IOUtils.toString(stream);
    assertThat(metadata, equalTo(repo1Content));
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 65 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class GroupMetadataMergeWithRepoTimeoutTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String repo2 = "repo2";
    final String path = "org/foo/bar/maven-metadata.xml";
    /* @formatter:off */
    final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.0</latest>\n" + "    <release>1.0</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20150722164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    server.expect(server.formatUrl(repo1, path), 200, repo1Content);
    server.expect("GET", server.formatUrl(repo2, path), (request, response) -> {
        try {
            Thread.sleep(5000);
        } catch (final InterruptedException e) {
        }
        response.setStatus(404);
    });
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
    remote2.setTimeoutSeconds(2);
    remote2.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
    Group g = new Group("test", remote1.getKey(), remote2.getKey());
    g = client.stores().create(g, "adding group", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    final InputStream stream = client.content().get(group, g.getName(), path);
    assertThat(stream, notNullValue());
    final String metadata = IOUtils.toString(stream);
    assertThat(metadata, equalTo(repo1Content));
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9