Search in sources :

Example 76 with RemoteRepository

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

the class RemoteRepositoryTest method copyFidelity.

@Test
public void copyFidelity() {
    RemoteRepository src = new RemoteRepository(GenericPackageTypeDescriptor.GENERIC_PKG_KEY, "test", "http://test.com/repo");
    src.setTimeoutSeconds(100);
    src.setPassword("foo");
    src.setUser("bar");
    src.setMetadata("key", "value");
    src.setCacheTimeoutSeconds(200);
    src.setKeyCertPem("THISISACERTIFICATEPEM");
    src.setKeyPassword("certpass");
    src.setMetadataTimeoutSeconds(300);
    src.setNfcTimeoutSeconds(400);
    src.setPassthrough(false);
    src.setProxyHost("127.0.0.1");
    src.setProxyPort(8888);
    src.setProxyUser("proxyuser");
    src.setProxyPassword("proxypass");
    src.setServerCertPem("ANOTHERCERTIFICATEPEM");
    src.setServerTrustPolicy("all");
    src.setAllowReleases(false);
    src.setAllowSnapshots(false);
    src.setDescription("some description");
    src.setDisableTimeout(500);
    src.setDisabled(true);
    src.setPathMaskPatterns(Collections.singleton("some/path"));
    src.setTransientMetadata("transient", "someval");
    src.setPathStyle(PathStyle.hashed);
    RemoteRepository target = src.copyOf();
    Stream.of(RemoteRepository.class.getMethods()).filter(m -> m.getName().startsWith("get") && m.isAccessible() && m.getParameterCount() == 0).forEach(m -> {
        try {
            assertThat(m.getName() + " didn't get copied correctly!", m.invoke(target), equalTo(m.invoke(src)));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            fail("Failed to invoke: " + m.getName());
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    });
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) Stream(java.util.stream.Stream) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GenericPackageTypeDescriptor(org.commonjava.indy.model.core.GenericPackageTypeDescriptor) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathStyle(org.commonjava.indy.model.core.PathStyle) Collections(java.util.Collections) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 77 with RemoteRepository

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

the class RemoteRepoTimeoutNeverDisableTest method assertResult.

@Override
protected void assertResult(RemoteRepository remoteRepo) throws Exception {
    assertThat(remoteRepo.isDisabled(), equalTo(false));
    Thread.sleep(2000);
    RemoteRepository result = client.stores().load(remote, remoteRepo.getName(), RemoteRepository.class);
    assertThat(result.isDisabled(), equalTo(false));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 78 with RemoteRepository

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

the class RemoteRepoTimeoutReenableWithTimeoutSetTest method assertResult.

@Override
protected void assertResult(RemoteRepository remoteRepo) throws Exception {
    assertThat(remoteRepo.isDisabled(), equalTo(true));
    Thread.sleep(2000);
    RemoteRepository result = client.stores().load(remote, remoteRepo.getName(), RemoteRepository.class);
    assertThat(result.isDisabled(), equalTo(false));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 79 with RemoteRepository

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

the class RepositoryPathMaskExtTest method run.

/**
     * Extensive tests. Both regex patterns and "directory prefix" patterns need to be tested, involving all three store types:
     * RemoteRepository (direct access)
     * HostedRepository (direct access)
     * Group (where one or more members has path masks)
     *  Case where two members contain the same path, but first one's path mask doesn't match
     *   - Should return content from the second member
     */
@Test
public void run() throws Exception {
    final String content1 = "{\"content1\": \"This is a test: " + System.nanoTime() + "\"}";
    final String content2 = "{\"content2\": \"This is a test: " + System.nanoTime() + "\"}";
    final String path_1 = "org/foo/foo-project/1.0/pom.xml";
    final String path_2 = "org/bar/bar-project/1.0/pom.xml";
    final String remote1 = "remote1";
    final String hosted1 = "hosted1";
    server.expect(server.formatUrl(remote1, path_1), 200, new ByteArrayInputStream(content1.getBytes()));
    RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
    Set<String> pathMaskPatterns = new HashSet<>();
    // regex patterns
    pathMaskPatterns.add("r|org/bar.*|");
    remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
    remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
    HostedRepository hostedRepo1 = new HostedRepository(hosted1);
    pathMaskPatterns = new HashSet<>();
    pathMaskPatterns.add("org/foo");
    pathMaskPatterns.add("r|org/bar.*|");
    hostedRepo1.setPathMaskPatterns(pathMaskPatterns);
    hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
    client.content().store(hosted, hosted1, path_1, new ByteArrayInputStream(content2.getBytes()));
    client.content().store(hosted, hosted1, path_2, new ByteArrayInputStream(content2.getBytes()));
    Group g = new Group("group1", remoteRepo1.getKey(), hostedRepo1.getKey());
    g = client.stores().create(g, "adding group1", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    InputStream stream = null;
    String str = null;
    // Case 1. return content from the repo with valid mask
    // get stream for path-1 via group
    stream = client.content().get(group, g.getName(), path_1);
    assertThat(stream, notNullValue());
    // return content from the repo with mask
    str = IOUtils.toString(stream);
    stream.close();
    assertThat(str, equalTo(content2));
    // Case 2. multiple repositories with same mask, use what can supply the real artifact
    // get stream for path-2 via group (success)
    stream = client.content().get(group, g.getName(), path_2);
    assertThat(stream, notNullValue());
    stream.close();
    // Case 3. test direct access hosted repo with regex mask
    // direct access for path-2 (success)
    stream = client.content().get(hosted, hostedRepo1.getName(), path_2);
    assertThat(stream, notNullValue());
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HashSet(java.util.HashSet) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 80 with RemoteRepository

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

the class RepositoryPathMaskMetadataTest method run.

/**
     *  Case where user requests maven-metadata.xml which is allowed by path mask
     *   - Should include versions from the member that has a path mask
     */
@Test
public void run() throws Exception {
    final String path_metadata = "org/bar/bar-project/maven-metadata.xml";
    final String remote1 = "remote1";
    final String hosted1 = "hosted1";
    server.expect(server.formatUrl(remote1, path_metadata), 200, meta1);
    RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
    Set<String> pathMaskPatterns = new HashSet<>();
    // regex patterns
    pathMaskPatterns.add("r|org/bar.*|");
    remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
    remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
    HostedRepository hostedRepo1 = new HostedRepository(hosted1);
    pathMaskPatterns = new HashSet<>();
    pathMaskPatterns.add("org/bar.*");
    hostedRepo1.setPathMaskPatterns(pathMaskPatterns);
    hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
    client.content().store(hosted, hosted1, path_metadata, new ByteArrayInputStream(meta2.getBytes()));
    Group g = new Group("group1", remoteRepo1.getKey(), hostedRepo1.getKey());
    g = client.stores().create(g, "adding group1", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    InputStream stream = null;
    String str = null;
    // get metadata from hosted1
    stream = client.content().get(hosted, hostedRepo1.getName(), path_metadata);
    assertThat(stream, notNullValue());
    str = IOUtils.toString(stream);
    System.out.println("hosted1.metadata >>>> " + str);
    stream.close();
    // get metadata from remote1
    stream = client.content().get(remote, remoteRepo1.getName(), path_metadata);
    assertThat(stream, notNullValue());
    str = IOUtils.toString(stream);
    System.out.println("remote1.metadata >>>> " + str);
    stream.close();
    // get metadata from group1
    stream = client.content().get(group, g.getName(), path_metadata);
    assertThat(stream, notNullValue());
    // return aggregated versions from all repositories with valid mask
    str = IOUtils.toString(stream);
    System.out.println("group1.metadata >>>> " + str);
    assertThat(str.trim(), equalTo(aggregatedMeta));
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HashSet(java.util.HashSet) HostedRepository(org.commonjava.indy.model.core.HostedRepository) 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