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