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());
}
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());
}
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);
}
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);
}
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());
}
Aggregations