Search in sources :

Example 26 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.

the class RSQLPredicateProducerTest method testPredicateOut.

@Test
public void testPredicateOut() {
    Predicate<BuildConfiguration> streamPredicate = producer.getStreamPredicate("id=out=(2,3)");
    BuildConfiguration fooBarG = BuildConfiguration.builder().id("1").name("FooBar").buildType(BuildType.GRADLE).build();
    BuildConfiguration fooBarM = BuildConfiguration.builder().id("2").name("FooBar").buildType(BuildType.MVN).build();
    BuildConfiguration fooBazG = BuildConfiguration.builder().id("3").name("FooBaz").buildType(BuildType.GRADLE).build();
    List<BuildConfiguration> filtered = Arrays.asList(fooBarG, fooBarM, fooBazG).stream().filter(streamPredicate).collect(Collectors.toList());
    assertEquals(1, filtered.size());
    assertEquals("1", filtered.get(0).getId());
    assertEquals("FooBar", filtered.get(0).getName());
    assertEquals(BuildType.GRADLE, filtered.get(0).getBuildType());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Test(org.junit.Test)

Example 27 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.

the class RSQLPredicateProducerTest method testComparatorWithNullValue.

@Test
public void testComparatorWithNullValue() {
    Comparator<BuildConfiguration> comparator = producer.getComparator("=desc=id");
    BuildConfiguration foo = BuildConfiguration.builder().id("3").name("FooBC").build();
    BuildConfiguration bar = BuildConfiguration.builder().id("5").name("BarBC").build();
    BuildConfiguration baz = BuildConfiguration.builder().id("7").name("BazBC").build();
    BuildConfiguration nul = BuildConfiguration.builder().id(null).name("NulBC").build();
    List<BuildConfiguration> sorted = Arrays.asList(foo, bar, baz, nul).stream().sorted(comparator).collect(Collectors.toList());
    assertEquals(4, sorted.size());
    assertEquals("NulBC", sorted.get(0).getName());
    assertEquals("BazBC", sorted.get(1).getName());
    assertEquals("BarBC", sorted.get(2).getName());
    assertEquals("FooBC", sorted.get(3).getName());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Test(org.junit.Test)

Example 28 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.

the class WebSocketClientTest method testBuildListener.

@Test
public void testBuildListener() throws Exception {
    // with
    WebSocketClient wsClient = new VertxWebSocketClient();
    wsClient.connect(PNC_SOCKET_URL).get();
    BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration bc = buildConfigurationClient.getAll().iterator().next();
    AtomicInteger notificationCounter = new AtomicInteger(0);
    // when
    ListenerUnsubscriber unsubscriber = wsClient.onBuildChangedNotification((notification -> {
        notificationCounter.incrementAndGet();
        assertThat(notification).isNotNull();
        assertThat(notification.getBuild()).isNotNull();
    }), withBuildConfiguration(bc.getId()));
    buildConfigurationClient.trigger(bc.getId(), new BuildParameters());
    // then
    Thread.sleep(1000);
    unsubscriber.run();
    wsClient.disconnect().get();
    assertThat(notificationCounter).hasValueGreaterThanOrEqualTo(2);
}
Also used : BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) NOTIFICATION_PATH(org.jboss.pnc.integration.setup.RestClientConfiguration.NOTIFICATION_PATH) Handlers(io.undertow.Handlers) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) AdvancedGroupConfigurationClient(org.jboss.pnc.restclient.AdvancedGroupConfigurationClient) Arquillian(org.jboss.arquillian.junit.Arquillian) GroupBuildClient(org.jboss.pnc.client.GroupBuildClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) Undertow(io.undertow.Undertow) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ListenerUnsubscriber(org.jboss.pnc.restclient.websocket.ListenerUnsubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupBuild(org.jboss.pnc.dto.GroupBuild) Deployments(org.jboss.pnc.integration.setup.Deployments) Method(java.lang.reflect.Method) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) GroupBuildChangedNotificationPredicates.withGConfigId(org.jboss.pnc.restclient.websocket.predicates.GroupBuildChangedNotificationPredicates.withGConfigId) AbstractReceiveListener(io.undertow.websockets.core.AbstractReceiveListener) Category(org.junit.experimental.categories.Category) BuildChangedNotificationPredicates.withBuildCompleted(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildCompleted) Assertions.fail(org.assertj.core.api.Assertions.fail) WebSocketHttpExchange(io.undertow.websockets.spi.WebSocketHttpExchange) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) WebSocketConnectionCallback(io.undertow.websockets.WebSocketConnectionCallback) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ResponseUtils(org.jboss.pnc.integration.utils.ResponseUtils) ClientException(org.jboss.pnc.client.ClientException) BufferedBinaryMessage(io.undertow.websockets.core.BufferedBinaryMessage) BuildChangedNotification(org.jboss.pnc.dto.notification.BuildChangedNotification) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) GroupBuildChangedNotification(org.jboss.pnc.dto.notification.GroupBuildChangedNotification) Logger(org.slf4j.Logger) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) GroupBuildChangedNotificationPredicates.withGBuildCompleted(org.jboss.pnc.restclient.websocket.predicates.GroupBuildChangedNotificationPredicates.withGBuildCompleted) Test(org.junit.Test) IOException(java.io.IOException) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) RemoteResourceNotFoundException(org.jboss.pnc.client.RemoteResourceNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Deployment(org.jboss.arquillian.container.test.api.Deployment) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) ListenerUnsubscriber(org.jboss.pnc.restclient.websocket.ListenerUnsubscriber) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 29 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration 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 30 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration 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)

Aggregations

BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)90 Test (org.junit.Test)65 ContainerTest (org.jboss.pnc.test.category.ContainerTest)45 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)31 HashMap (java.util.HashMap)17 InSequence (org.jboss.arquillian.junit.InSequence)17 Build (org.jboss.pnc.dto.Build)13 GroupBuild (org.jboss.pnc.dto.GroupBuild)12 SCMRepository (org.jboss.pnc.dto.SCMRepository)10 Test (org.junit.jupiter.api.Test)10 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)9 Instant (java.time.Instant)8 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)7 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ArrayList (java.util.ArrayList)4 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)4 HashSet (java.util.HashSet)3