Search in sources :

Example 1 with GroupConfigurationClient

use of org.jboss.pnc.client.GroupConfigurationClient in project pnc by project-ncl.

the class GroupConfigurationEndpointTest method testConcurrentGet.

/**
 * reproducer for NCL-3552
 */
@Test
public void testConcurrentGet() throws RemoteResourceException {
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    Map<Integer, RemoteCollection<BuildConfiguration>> responseMap = new HashMap<>();
    String gcId = "100";
    ExecutorService executorService = MDCExecutors.newFixedThreadPool(2);
    executorService.execute(() -> {
        logger.info("Making 1st request ...");
        RemoteCollection<BuildConfiguration> configurations = null;
        try {
            configurations = client.getBuildConfigs(gcId);
        } catch (RemoteResourceException e) {
        // detected with null in responseMap
        }
        logger.info("1st done.");
        responseMap.put(1, configurations);
    });
    executorService.execute(() -> {
        logger.info("Making 2nd request ...");
        RemoteCollection<BuildConfiguration> configurations = null;
        try {
            configurations = client.getBuildConfigs(gcId);
        } catch (RemoteResourceException e) {
        // detected with null in responseMap
        }
        logger.info("2nd done.");
        responseMap.put(2, configurations);
    });
    try {
        executorService.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        executorService.shutdownNow();
        throw new AssertionError("Requests were not completed in given timeout.", e);
    }
    assertThat(responseMap).containsKeys(1, 2).doesNotContainValue(null);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) ExecutorService(java.util.concurrent.ExecutorService) GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with GroupConfigurationClient

use of org.jboss.pnc.client.GroupConfigurationClient in project pnc by project-ncl.

the class GroupConfigurationEndpointTest method testCreateNewGroupConfig.

@Test
public void testCreateNewGroupConfig() throws ClientException {
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    final String name = "Testing 101";
    GroupConfiguration gc = GroupConfiguration.builder().productVersion(ProductVersionRef.refBuilder().id("101").build()).name(name).build();
    GroupConfiguration created = client.createNew(gc);
    assertEquals(name, created.getName());
    GroupConfiguration specific = client.getSpecific(created.getId());
    assertEquals(created, specific);
}
Also used : GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with GroupConfigurationClient

use of org.jboss.pnc.client.GroupConfigurationClient in project pnc by project-ncl.

the class GroupConfigurationEndpointTest method testUpdateGroupConfig.

@Test
public void testUpdateGroupConfig() throws ClientException {
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    final String name = "Testing 100 Updated";
    GroupConfiguration specific = client.getSpecific("100");
    GroupConfiguration updating = specific.toBuilder().name(name).build();
    client.update("100", updating);
    GroupConfiguration updated = client.getSpecific("100");
    assertEquals(name, updated.getName());
}
Also used : GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with GroupConfigurationClient

use of org.jboss.pnc.client.GroupConfigurationClient in project pnc by project-ncl.

the class GroupConfigurationEndpointTest method shouldDeleteBuildConfigWithPatch.

@Test
public void shouldDeleteBuildConfigWithPatch() throws Exception {
    // given
    GroupConfigurationClient groupConfigurationClient = new GroupConfigurationClient(RestClientConfiguration.asUser());
    BuildConfigurationClient bcClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    GroupConfiguration gc = groupConfigurationClient.getAll().iterator().next();
    assertThat(gc.getBuildConfigs()).isNotEmpty();
    BuildConfiguration toRemove = bcClient.getSpecific(gc.getBuildConfigs().keySet().iterator().next());
    GroupConfigurationPatchBuilder builder = new GroupConfigurationPatchBuilder();
    builder.removeBuildConfigs(Collections.singletonList(toRemove.getId()));
    // when
    groupConfigurationClient.patch(gc.getId(), builder);
    // then
    GroupConfiguration refresh = groupConfigurationClient.getSpecific(gc.getId());
    assertThat(refresh.getBuildConfigs().keySet()).doesNotContain(toRemove.getId());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupConfigurationPatchBuilder(org.jboss.pnc.client.patch.GroupConfigurationPatchBuilder) GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with GroupConfigurationClient

use of org.jboss.pnc.client.GroupConfigurationClient in project pnc by project-ncl.

the class GroupConfigurationEndpointTest method testGetSpecificGroupConfig.

@Test
public void testGetSpecificGroupConfig() throws ClientException {
    String gcid = "100";
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    assertThat(client.getSpecific(gcid)).isNotNull();
}
Also used : GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)16 ContainerTest (org.jboss.pnc.test.category.ContainerTest)16 Test (org.junit.Test)16 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)12 HashMap (java.util.HashMap)5 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)5 ProductVersion (org.jboss.pnc.dto.ProductVersion)4 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)3 ProductVersionClient (org.jboss.pnc.client.ProductVersionClient)3 GroupConfigurationRef (org.jboss.pnc.dto.GroupConfigurationRef)3 GroupConfigurationPatchBuilder (org.jboss.pnc.client.patch.GroupConfigurationPatchBuilder)2 ProductVersionPatchBuilder (org.jboss.pnc.client.patch.ProductVersionPatchBuilder)2 ExecutorService (java.util.concurrent.ExecutorService)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 RemoteCollection (org.jboss.pnc.client.RemoteCollection)1 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)1 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)1