use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class ProcessProgressNotificationTest method shouldSubscribeToProcessUpdatesNotification.
@Test
public void shouldSubscribeToProcessUpdatesNotification() throws Exception {
// given
Integer taskId = 1;
Build build = BuildMock.newBuild(taskId, BuildStatus.SUCCESS, "Build1");
BuildStatusChangedEvent buildStatusChangedEvent = new DefaultBuildStatusChangedEvent(build, BuildStatus.NEW, build.getStatus());
// when
buildStatusNotificationEvent.fire(buildStatusChangedEvent);
ProgressUpdatesRequest progressUpdatesRequest = new ProgressUpdatesRequest(Action.SUBSCRIBE, "component-build", taskId.toString());
String text = JsonOutputConverterMapper.apply(new TypedMessage<>(MessageType.PROCESS_UPDATES, progressUpdatesRequest));
logger.info("Sending test message:" + text);
asyncRemote.sendText(text);
waitForMessages(1);
// then
logger.info("Received: " + notificationCollector.getMessages().get(0));
assertTrue(notificationCollector.getMessages().get(0).startsWith("{\"oldStatus\":\"NEW\",\"build\":{\"id\":\"1\",\"submitTime\":null,\"startTime\":null,\"endTime\":null,\"progress\":null,\"status\":\"SUCCESS\","));
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildStatusChangedTest method shouldSerializeObject.
@Test
public void shouldSerializeObject() throws IOException {
// given
Build build = getBuild();
BuildStatus oldStatus = BuildStatus.NEW;
BuildStatusChanged buildStatusChanged = BuildStatusChanged.builder().oldStatus(oldStatus.toString()).build(build).buildMe();
// when
String serialized = buildStatusChanged.toJson();
logger.info("Serialized: {}", serialized);
BuildStatusChanged deserialized = JsonOutputConverterMapper.readValue(serialized, BuildStatusChanged.class);
// then
Assertions.assertThat(deserialized).isEqualToComparingFieldByField(buildStatusChanged);
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildIteratorTest method testBuildIterator.
@Test
public void testBuildIterator() {
SortInfo sortInfo = mock(SortInfo.class);
Predicate<BuildRecord> predicate = mock(Predicate.class);
mockRepository(sortInfo, predicate);
BuildProviderImpl.BuildIterator bit;
List<Integer> ret;
bit = provider.new BuildIterator(1, 10, 1, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
Build next = bit.next();
System.out.println("next: " + next);
ret.add(Integer.valueOf(next.getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 10, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(7, 12, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(7, 8, 9, 10, 11, 12), ret);
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildProviderImplTest method testGetLatestBuild.
@Test
public void testGetLatestBuild() {
// Prepare
mockBuildTask();
mockBuildTask();
mockBuildRecord();
mockBuildTask();
BuildRecord latestBuild = mockBuildRecord();
logger.debug("Task id: {}", latestBuild.getId());
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", true, false, "");
Page<Build> builds = provider.getBuilds(pageInfo);
// Verify
assertEquals(1, builds.getTotalHits());
assertEquals(BuildMapper.idMapper.toDto(latestBuild.getId()), builds.getContent().iterator().next().getId());
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildProviderImplTest method dependencyGraphTest.
@Test
public void dependencyGraphTest() {
// given
BuildTask bt100002 = mock(BuildTask.class);
when(bt100002.getId()).thenReturn("100002");
BuildTask bt110000 = mock(BuildTask.class);
when(bt110000.getId()).thenReturn("110000");
when(bt110000.getDependencies()).thenReturn(Collections.emptySet());
when(bt110000.getDependants()).thenReturn(Collections.singleton(bt100002));
runningBuilds.add(bt110000);
mockBuildRecord(new Base32LongID(100000L), new Long[] { 100002L }, new Long[] {});
mockBuildRecord(new Base32LongID(100001L), new Long[] { 100002L }, new Long[] {});
BuildRecord currentBuild = mockBuildRecord(new Base32LongID(100002L), new Long[] { 100003L, 100005L, 100006L }, new Long[] { 100000L, 100001L, Long.valueOf(bt110000.getId()) });
BuildRecord buildRecord100003 = mockBuildRecord(new Base32LongID(100003L), new Long[] { 100004L }, new Long[] { 100002L });
mockBuildRecord(new Base32LongID(100004L), new Long[] {}, new Long[] { 100003L });
mockBuildRecord(new Base32LongID(100005L), new Long[] {}, new Long[] { 100002L });
mockBuildRecord(new Base32LongID(100006L), new Long[] {}, new Long[] { 100002L });
// when
Graph<Build> dependencyGraph = provider.getDependencyGraph(bt100002.getId());
// then
logger.info("Graph: {}", dependencyGraph.toString());
assertEquals(8, dependencyGraph.getVertices().size());
Vertex<Build> vertex = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(currentBuild.getId()));
Build build = vertex.getData();
assertEquals(BuildMapper.idMapper.toDto(currentBuild.getId()), build.getId());
assertEquals(4, getOutgoingEdges(dependencyGraph, vertex).count());
assertEquals(3, getIncommingEdges(dependencyGraph, vertex).count());
Vertex<Build> vertex3 = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(buildRecord100003.getId()));
assertEquals(1, getOutgoingEdges(dependencyGraph, vertex3).count());
assertEquals(1, getIncommingEdges(dependencyGraph, vertex3).count());
// then from running build
Graph<Build> dependencyGraphFromRunning = provider.getDependencyGraph(bt110000.getId());
Vertex<Build> runningVertex = getBuildVertexByName(dependencyGraphFromRunning, bt110000.getId());
assertEquals(1, getOutgoingEdges(dependencyGraphFromRunning, runningVertex).count());
assertEquals(1, getIncommingEdges(dependencyGraphFromRunning, runningVertex).count());
}
Aggregations