Search in sources :

Example 96 with Group

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

the class StoreReverseMapMigrationTest method run.

@Test
public void run() throws Exception {
    /* @formatter:off */
    final String repoAContent = "<?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>20150721164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    /* @formatter:off */
    final String repoBContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>2.0</latest>\n" + "    <release>2.0</release>\n" + "    <versions>\n" + "      <version>2.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20160722164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    /* @formatter:off */
    final String repoCContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>3.0</latest>\n" + "    <release>3.0</release>\n" + "    <versions>\n" + "      <version>3.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20160723164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    createHostedStorePath(hostedA, path, repoAContent);
    try (final InputStream stream = client.content().get(hostedA.getKey(), path)) {
        assertContent(repoAContent, IOUtils.toString(stream));
    }
    createHostedStorePath(hostedB, path, repoBContent);
    try (final InputStream stream = client.content().get(hostedB.getKey(), path)) {
        assertContent(repoBContent, IOUtils.toString(stream));
    }
    createHostedStorePath(hostedC, path, repoCContent);
    try (final InputStream stream = client.content().get(hostedC.getKey(), path)) {
        assertContent(repoCContent, IOUtils.toString(stream));
    }
    /* @formatter:off */
    final String mergedContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "  <metadata>\n" + "    <groupId>org.foo</groupId>\n" + "    <artifactId>bar</artifactId>\n" + "    <versioning>\n" + "      <latest>2.0</latest>\n" + "      <release>2.0</release>\n" + "      <versions>\n" + "        <version>1.0</version>\n" + "        <version>2.0</version>\n" + "      </versions>\n" + "      <lastUpdated>20160722164334</lastUpdated>\n" + "    </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    try (final InputStream stream = client.content().get(group, gY.getName(), path)) {
        assertContent(mergedContent1, IOUtils.toString(stream));
    }
    gX.addConstituent(hostedC);
    client.stores().update(gX, "test update");
    gX = client.stores().load(StoreType.group, gX.getName(), Group.class);
    logger.debug("\n\nGroup constituents are:\n  {}\n\n", StringUtils.join(gX.getConstituents(), "\n  "));
    waitForEventPropagation();
    /* @formatter:off */
    final String mergedContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "  <metadata>\n" + "    <groupId>org.foo</groupId>\n" + "    <artifactId>bar</artifactId>\n" + "    <versioning>\n" + "      <latest>3.0</latest>\n" + "      <release>3.0</release>\n" + "      <versions>\n" + "        <version>1.0</version>\n" + "        <version>2.0</version>\n" + "        <version>3.0</version>\n" + "      </versions>\n" + "      <lastUpdated>20160723164334</lastUpdated>\n" + "    </versioning>\n" + "</metadata>\n";
    try (final InputStream stream = client.content().get(group, gY.getName(), path)) {
        assertContent(mergedContent2, IOUtils.toString(stream));
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 97 with Group

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

the class ContentIndexDirLvWithMetadataTest method test.

@Test
public void test() throws Exception {
    final String remoteName1 = newName();
    RemoteRepository remote1 = new RemoteRepository(MAVEN_PKG_KEY, remoteName1, server.formatUrl(remoteName1));
    remote1 = client.stores().create(remote1, name.getMethodName(), RemoteRepository.class);
    final String remoteName2 = newName();
    RemoteRepository remote2 = new RemoteRepository(MAVEN_PKG_KEY, remoteName2, server.formatUrl(remoteName2));
    remote2 = client.stores().create(remote2, name.getMethodName(), RemoteRepository.class);
    final String groupName = newName();
    Group group = new Group(MAVEN_PKG_KEY, groupName, remote1.getKey(), remote2.getKey());
    group = client.stores().create(group, name.getMethodName(), Group.class);
    server.expect(server.formatUrl(remoteName2, PATH_META), 200, PATH_META_CONTENT);
    try (InputStream s = client.content().get(group.getKey(), PATH_META)) {
        assertThat(IOUtils.toString(s), equalTo(PATH_META_CONTENT));
    }
    AdvancedCache<IndexedStorePath, IndexedStorePath> advancedCache = (AdvancedCache) contentIndex.execute(c -> c);
    System.out.println("[Content index DEBUG]: cached isps: " + advancedCache.keySet());
    for (IndexedStorePath value : advancedCache.values()) {
        assertThat(value.getOriginStoreKey(), equalTo(remote2.getKey()));
    }
    System.out.println("[Content index DEBUG]: cache size:" + advancedCache.size());
    System.out.println("[Content index DEBUG]: cache hit:" + advancedCache.getStats().getHits());
    System.out.println("[Content index DEBUG]: cache misses:" + advancedCache.getStats().getMisses());
}
Also used : ExpectationServer(org.commonjava.test.http.expect.ExpectationServer) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Arrays(java.util.Arrays) IndexedStorePath(org.commonjava.indy.content.index.IndexedStorePath) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ContentIndexCacheProducer(org.commonjava.indy.content.index.ContentIndexCacheProducer) CDI(javax.enterprise.inject.spi.CDI) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) BasicCacheHandle(org.commonjava.indy.subsys.infinispan.BasicCacheHandle) CacheHandle(org.commonjava.indy.subsys.infinispan.CacheHandle) Group(org.commonjava.indy.model.core.Group) Assert.assertThat(org.junit.Assert.assertThat) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) AdvancedCache(org.infinispan.AdvancedCache) Rule(org.junit.Rule) CoreServerFixture(org.commonjava.indy.test.fixture.core.CoreServerFixture) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) Before(org.junit.Before) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndexedStorePath(org.commonjava.indy.content.index.IndexedStorePath) AdvancedCache(org.infinispan.AdvancedCache) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 98 with Group

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

the class RepositoryFilterTest method run.

/* @formatter:on */
@Test
public void run() throws Exception {
    final String path_1 = "org/foo/bar/1.0/bar-1.0.pom";
    final String content_1_remote = "This is a test from remote";
    final String content_1 = "This is a test";
    final String path_2 = "org/foo/bar/1.0-rh-0001/bar-1.0-rh-0001.pom";
    final String content_2 = "This is a rh test";
    final String remoteR = "R";
    final String hostedBuild_1 = "build-1";
    final String groupG = "G";
    final String metadataPath = "org/foo/bar/maven-metadata.xml";
    server.expect(server.formatUrl(remoteR, path_1), 200, content_1_remote);
    server.expect(server.formatUrl(remoteR, metadataPath), 200, METADATA_TEMPLATE.replaceAll("%version%", "1.0"));
    RemoteRepository remote = client.stores().create(new RemoteRepository(MAVEN_PKG_KEY, remoteR, server.formatUrl(remoteR)), "Add remote", RemoteRepository.class);
    HostedRepository hosted = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, hostedBuild_1), "Add hosted", HostedRepository.class);
    client.content().store(hosted.getKey(), path_1, new ByteArrayInputStream(content_1.getBytes()));
    client.content().store(hosted.getKey(), path_2, new ByteArrayInputStream(content_2.getBytes()));
    client.content().store(hosted.getKey(), metadataPath, new ByteArrayInputStream(METADATA_TEMPLATE.replaceAll("%version%", "1.0-rh-0001").getBytes()));
    // add confusing repos, hope it is not confused
    List<StoreKey> storeKeys = new ArrayList<>();
    for (int i = 100; i < 200; i++) {
        HostedRepository h = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, "build-" + i), "Add hosted", HostedRepository.class);
        storeKeys.add(h.getKey());
    }
    storeKeys.add(hosted.getKey());
    storeKeys.add(remote.getKey());
    // create group
    StoreKey[] keyArray = new StoreKey[storeKeys.size()];
    Group g = client.stores().create(new Group(MAVEN_PKG_KEY, groupG, storeKeys.toArray(keyArray)), "Add group", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    // get
    try (InputStream stream = client.content().get(g.getKey(), path_1)) {
        String str = IOUtils.toString(stream);
        assertThat(str, equalTo(content_1_remote));
    }
    try (InputStream stream = client.content().get(g.getKey(), path_2)) {
        String str = IOUtils.toString(stream);
        assertThat(str, equalTo(content_2));
    }
    try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
        String str = IOUtils.toString(stream);
        assertThat(str, containsString("<version>1.0</version>"));
        assertThat(str, containsString("<version>1.0-rh-0001</version>"));
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 99 with Group

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

the class StoreFileAndVerifyExistenceInGroupTest method storeFileInConstituentAndVerifyExistenceInGroup.

@Test
public void storeFileInConstituentAndVerifyExistenceInGroup() throws Exception {
    final Group g = client.stores().load(group, PUBLIC, Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    assertThat(g.getConstituents().contains(new StoreKey(hosted, STORE)), equalTo(true));
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String path = "/path/to/foo.class";
    assertThat(client.content().exists(hosted, STORE, path), equalTo(false));
    client.content().store(hosted, STORE, path, stream);
    assertThat(client.content().exists(group, PUBLIC, path), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 100 with Group

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

the class StoreReverseMapInitTest method run.

@Test
public void run() throws Exception {
    /* @formatter:off */
    final String repoAContent = "<?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>20150721164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    /* @formatter:off */
    final String repoBContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>2.0</latest>\n" + "    <release>2.0</release>\n" + "    <versions>\n" + "      <version>2.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20160722164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    /* @formatter:off */
    final String repoCContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>3.0</latest>\n" + "    <release>3.0</release>\n" + "    <versions>\n" + "      <version>3.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20160723164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    HostedRepository hostedA = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, hosted, repoA), HostedRepository.class);
    createHostedStorePath(hostedA, repoAContent);
    try (final InputStream stream = client.content().get(hostedA.getKey(), path)) {
        assertContent(repoAContent, IOUtils.toString(stream));
    }
    HostedRepository hostedB = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, hosted, repoB), HostedRepository.class);
    createHostedStorePath(hostedB, repoBContent);
    try (final InputStream stream = client.content().get(hostedB.getKey(), path)) {
        assertContent(repoBContent, IOUtils.toString(stream));
    }
    HostedRepository hostedC = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, hosted, repoC), HostedRepository.class);
    createHostedStorePath(hostedC, repoCContent);
    try (final InputStream stream = client.content().get(hostedC.getKey(), path)) {
        assertContent(repoCContent, IOUtils.toString(stream));
    }
    /* @formatter:off */
    final String mergedContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "  <metadata>\n" + "    <groupId>org.foo</groupId>\n" + "    <artifactId>bar</artifactId>\n" + "    <versioning>\n" + "      <latest>2.0</latest>\n" + "      <release>2.0</release>\n" + "      <versions>\n" + "        <version>1.0</version>\n" + "        <version>2.0</version>\n" + "      </versions>\n" + "      <lastUpdated>20160722164334</lastUpdated>\n" + "    </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    Group gY = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, group, groupY), Group.class);
    try (final InputStream stream = client.content().get(gY.getKey(), path)) {
        assertContent(mergedContent1, IOUtils.toString(stream));
    }
    Group gX = client.stores().load(new StoreKey(PKG_TYPE_MAVEN, group, groupX), Group.class);
    gX.addConstituent(hostedC);
    client.stores().update(gX, "test update");
    gX = client.stores().load(gX.getKey(), Group.class);
    logger.debug("\n\nGroup constituents are:\n  {}\n\n", StringUtils.join(gX.getConstituents(), "\n  "));
    waitForEventPropagation();
    /* @formatter:off */
    final String mergedContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "  <metadata>\n" + "    <groupId>org.foo</groupId>\n" + "    <artifactId>bar</artifactId>\n" + "    <versioning>\n" + "      <latest>3.0</latest>\n" + "      <release>3.0</release>\n" + "      <versions>\n" + "        <version>1.0</version>\n" + "        <version>2.0</version>\n" + "        <version>3.0</version>\n" + "      </versions>\n" + "      <lastUpdated>20160723164334</lastUpdated>\n" + "    </versioning>\n" + "</metadata>\n";
    try (final InputStream stream = client.content().get(gY.getKey(), path)) {
        assertContent(mergedContent2, IOUtils.toString(stream));
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest) Test(org.junit.Test)

Aggregations

Group (org.commonjava.indy.model.core.Group)211 Test (org.junit.Test)111 HostedRepository (org.commonjava.indy.model.core.HostedRepository)89 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)82 StoreKey (org.commonjava.indy.model.core.StoreKey)76 ByteArrayInputStream (java.io.ByteArrayInputStream)67 InputStream (java.io.InputStream)62 IndyDataException (org.commonjava.indy.data.IndyDataException)44 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)42 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)42 Transfer (org.commonjava.maven.galley.model.Transfer)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)30 Logger (org.slf4j.Logger)30 Before (org.junit.Before)29 StoreDataManager (org.commonjava.indy.data.StoreDataManager)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)27 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)25 List (java.util.List)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)22