Search in sources :

Example 1 with ResultBufferingGroupRepoFilter

use of org.commonjava.indy.ftest.core.fixture.ResultBufferingGroupRepoFilter in project indy by Commonjava.

the class RepositoryFilterGACacheTest method run.

/* @formatter:on */
@Test
public // @Ignore( "Test validation relies on log message stability, which is not something we test for")
void run() throws Exception {
    BufferedLogAppender bufferedLogAppender = prepareTestAppender();
    final String remoteR = "R";
    final String build_1 = "build-1";
    final String build_2 = "build-2";
    final String build_3 = "build-3";
    final String build_4 = "build-4";
    final String npc_builds = "npc_builds";
    final String groupG = "G";
    RemoteRepository remote = prepareRemote(remoteR, A_0, V1);
    HostedRepository hosted_1 = prepareHosted(build_1, A_1, V2_1);
    HostedRepository hosted_2 = prepareHosted(build_2, A_1, V2_2);
    HostedRepository hosted_3 = prepareHosted(build_3, A_2, V2_1);
    HostedRepository hosted_4 = prepareHosted(build_4, A_2, V2_2);
    HostedRepository hosted_npc_builds = prepareHosted(npc_builds, A_1, V1);
    hosted_npc_builds = prepareHosted(npc_builds, A_2, V1);
    List<StoreKey> storeKeys = new ArrayList<>();
    storeKeys.add(hosted_1.getKey());
    storeKeys.add(hosted_2.getKey());
    storeKeys.add(hosted_3.getKey());
    storeKeys.add(hosted_4.getKey());
    storeKeys.add(hosted_npc_builds.getKey());
    storeKeys.add(remote.getKey());
    // add confusing repos, hope it is not confused
    for (int i = 100; i < 200; i++) {
        HostedRepository h = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, "build-" + i), "Add hosted-" + i, HostedRepository.class);
        storeKeys.add(h.getKey());
    }
    // create group G
    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  "));
    // fill the GA cache (because when test fixture starts up the repos are not created yet)
    CDI.current().select(PathMappedMavenGACache.class).get().fill();
    ResultBufferingGroupRepoFilter filterBuffer = CDI.current().select(ResultBufferingGroupRepoFilter.class).get();
    Thread.sleep(10);
    // get pom
    String pomPath = getPomPath(A_0, V1);
    try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + pomPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_0 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V1 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
    // checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:npc_builds, maven:remote:R]" );
    pomPath = getPomPath(A_1, V2_1);
    try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + pomPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_1 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V2_1 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_1, hosted_2, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
    // checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:build-1, maven:hosted:build-2, maven:hosted:npc_builds, maven:remote:R]" );
    pomPath = getPomPath(A_2, V2_1);
    try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + pomPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_2 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V2_1 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_3, hosted_4, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
    // checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:build-3, maven:hosted:build-4, maven:hosted:npc_builds, maven:remote:R]" );
    pomPath = getPomPath(A_1, V1);
    try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + pomPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_1 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V1 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_1, hosted_2, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
    // checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:build-1, maven:hosted:build-2, maven:hosted:npc_builds, maven:remote:R]" );
    // get metadata
    String metadataPath = getMetadataPath(A_0);
    try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + metadataPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_0 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V1 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(metadataPath, g));
    // checkLogMessage( metadataPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:npc_builds, maven:remote:R]" );
    metadataPath = getMetadataPath(A_1);
    try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + metadataPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_1 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V1 + "</version>"));
        assertThat(str, containsString("<version>" + V2_1 + "</version>"));
        assertThat(str, containsString("<version>" + V2_2 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_1, hosted_2, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(metadataPath, g));
    // checkLogMessage( metadataPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:build-1, maven:hosted:build-2, maven:hosted:npc_builds, maven:remote:R]" );
    metadataPath = getMetadataPath(A_2);
    try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
        String str = IOUtils.toString(stream);
        System.out.println(">>>> " + metadataPath + "\n" + str);
        assertThat(str, containsString("<artifactId>" + A_2 + "</artifactId>"));
        assertThat(str, containsString("<version>" + V1 + "</version>"));
        assertThat(str, containsString("<version>" + V2_1 + "</version>"));
        assertThat(str, containsString("<version>" + V2_2 + "</version>"));
    }
    assertEquals(Arrays.asList(hosted_3, hosted_4, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(metadataPath, g));
    // checkLogMessage( metadataPath, bufferedLogAppender.getMessages().toString(),
    // "[maven:hosted:build-3, maven:hosted:build-4, maven:hosted:npc_builds, maven:remote:R]" );
    // 
    String messages = bufferedLogAppender.getMessages().toString();
    System.out.println(">>>>\n{\n" + messages + "}\n\n");
}
Also used : Group(org.commonjava.indy.model.core.Group) 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) ResultBufferingGroupRepoFilter(org.commonjava.indy.ftest.core.fixture.ResultBufferingGroupRepoFilter) HostedRepository(org.commonjava.indy.model.core.HostedRepository) ClusterTest(org.commonjava.indy.ftest.core.category.ClusterTest) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)1 ClusterTest (org.commonjava.indy.ftest.core.category.ClusterTest)1 ResultBufferingGroupRepoFilter (org.commonjava.indy.ftest.core.fixture.ResultBufferingGroupRepoFilter)1 Group (org.commonjava.indy.model.core.Group)1 HostedRepository (org.commonjava.indy.model.core.HostedRepository)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1