Search in sources :

Example 56 with Build

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\","));
}
Also used : Build(org.jboss.pnc.dto.Build) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) ProgressUpdatesRequest(org.jboss.pnc.notification.ProgressUpdatesRequest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 57 with Build

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);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildStatus(org.jboss.pnc.enums.BuildStatus) Test(org.junit.Test)

Example 58 with Build

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);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 59 with Build

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());
}
Also used : Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 60 with Build

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());
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Aggregations

Build (org.jboss.pnc.dto.Build)71 Test (org.junit.Test)52 ContainerTest (org.jboss.pnc.test.category.ContainerTest)35 BuildClient (org.jboss.pnc.client.BuildClient)20 BuildRecord (org.jboss.pnc.model.BuildRecord)18 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)16 BuildStatus (org.jboss.pnc.enums.BuildStatus)15 GroupBuild (org.jboss.pnc.dto.GroupBuild)14 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)14 ArrayList (java.util.ArrayList)12 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)11 HashSet (java.util.HashSet)10 List (java.util.List)10 Set (java.util.Set)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Date (java.util.Date)9 Page (org.jboss.pnc.dto.response.Page)9 BuildMapper (org.jboss.pnc.mapper.api.BuildMapper)9 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)9