Search in sources :

Example 61 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class TemporaryBuildsCleanerTest method shouldDeleteTemporaryBuildWithoutArtifactsTest.

@Test
public void shouldDeleteTemporaryBuildWithoutArtifactsTest() throws ValidationException {
    // given
    BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).build();
    buildRecordRepository.save(tempBr);
    System.out.println("shouldDeleteTemporaryBuildWithoutArtifactsTest#Inserted BR: " + tempBr.getId());
    List<BuildRecord> givenBuilds = buildRecordRepository.queryAll();
    int numberOfBuilds = givenBuilds.size();
    // when
    temporaryBuildsCleaner.deleteTemporaryBuild(tempBr.getId(), "");
    // then
    assertEquals(numberOfBuilds - 1, buildRecordRepository.queryAll().size());
    assertNull(buildRecordRepository.queryById(tempBr.getId()));
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 62 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class TemporaryBuildsCleanerTest method shouldNotDeleteNonTemporaryBuildSetTest.

@Test(expected = ValidationException.class)
public void shouldNotDeleteNonTemporaryBuildSetTest() throws ValidationException {
    // given
    BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).build();
    buildRecordRepository.save(tempBr);
    Set<BuildRecord> buildRecords = new HashSet<>();
    buildRecords.add(tempBr);
    BuildConfigSetRecord buildConfigSetRecord = initBuildConfigSetRecordBuilder().temporaryBuild(false).build();
    buildConfigSetRecord.setBuildRecords(buildRecords);
    buildConfigSetRecordRepository.save(buildConfigSetRecord);
    // when - then
    temporaryBuildsCleaner.deleteTemporaryBuildConfigSetRecord(buildConfigSetRecord.getId(), "");
    fail("Deletion of non-temporary build should be prohibited");
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 63 with BuildRecord

use of org.jboss.pnc.model.BuildRecord 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 64 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildIteratorTest method mockBuildRecord.

private static BuildRecord mockBuildRecord(Base32LongID i) {
    BuildRecord br = mock(BuildRecord.class);
    when(br.getId()).thenReturn(i);
    return br;
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 65 with BuildRecord

use of org.jboss.pnc.model.BuildRecord 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)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10