use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest 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 testFilterFinishedBuildsByBuildConfigName.
@Test
public void testFilterFinishedBuildsByBuildConfigName() {
// Given
Base32LongID givenIdAndBcName = new Base32LongID(85792L);
mockBuildTask();
mockBuildTask();
BuildRecord givenBuild = mockBuildRecord(givenIdAndBcName, new Long[0], new Long[0]);
when(buildConfigurationAuditedRepository.searchIdRevForBuildConfigurationName(givenIdAndBcName.toString())).thenReturn(Stream.of(givenBuild.getBuildConfigurationAuditedIdRev()).collect(Collectors.toList()));
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", false, false, givenIdAndBcName.toString());
Page<Build> builds = provider.getBuilds(pageInfo);
// Then
assertEquals(1, builds.getTotalHits());
Iterator<Build> it = builds.getContent().iterator();
assertEquals(BuildMapper.idMapper.toDto(givenBuild.getId()), it.next().getId());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method testGetBuilds.
@Test
public void testGetBuilds() {
// Prepare
// hit
mockBuildRecord();
// hit
mockBuildTask();
// hit
mockBuildRecord();
// hit
mockBuildTask();
// hit
mockBuildRecord();
// hit
mockBuildTask();
// hit
BuildRecord build2 = mockBuildRecord();
// hit
BuildTask build1 = mockBuildTask();
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 2, "", "", false, false, "");
Page<Build> builds = provider.getBuilds(pageInfo);
// Verify
assertEquals(8, builds.getTotalHits());
assertEquals(2, builds.getContent().size());
Iterator<Build> it = builds.getContent().iterator();
assertEquals(build1.getId(), it.next().getId());
assertEquals(BuildMapper.idMapper.toDto(build2.getId()), it.next().getId());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImplTest method testGetBuildsPages.
@Test
public void testGetBuildsPages() {
// Prepare
BuildRecord build8 = mockBuildRecord();
BuildTask build7 = mockBuildTask();
BuildRecord build6 = mockBuildRecord();
BuildTask build5 = mockBuildTask();
BuildRecord build4 = mockBuildRecord();
BuildTask build3 = mockBuildTask();
BuildRecord build2 = mockBuildRecord();
BuildTask build1 = mockBuildTask();
testPage(0, 2, new Base32LongID(build1.getId()), build2.getId());
testPage(1, 2, new Base32LongID(build3.getId()), build4.getId());
testPage(2, 2, new Base32LongID(build5.getId()), build6.getId());
testPage(3, 2, new Base32LongID(build7.getId()), build8.getId());
testPage(1, 3, build4.getId(), new Base32LongID(build5.getId()), build6.getId());
testPage(2, 3, new Base32LongID(build7.getId()), build8.getId());
testPage(2, 10);
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class BuildProviderImpl method setBuiltArtifacts.
@RolesAllowed(SYSTEM_USER)
@Override
public void setBuiltArtifacts(String buildId, List<String> artifactIds) {
Set<Integer> ids = artifactIds.stream().map(Integer::valueOf).collect(Collectors.toSet());
List<Artifact> artifacts = artifactRepository.queryWithPredicates(withIds(ids));
if (ids.size() != artifacts.size()) {
artifacts.stream().map(Artifact::getId).forEach(ids::remove);
throw new InvalidEntityException("Artifacts not found, missing ids: " + ids);
}
final Base32LongID id = parseId(buildId);
BuildRecord buildRecord = repository.queryById(id);
for (Artifact artifact : artifacts) {
if (artifact.getBuildRecord() != null && !id.equals(artifact.getBuildRecord().getId())) {
throw new ConflictedEntryException("Artifact " + artifact.getId() + " is already marked as built by different build.", BuildRecord.class, BuildMapper.idMapper.toDto(artifact.getBuildRecord().getId()));
}
artifact.setBuildRecord(buildRecord);
}
HashSet<Artifact> oldBuiltArtifacts = new HashSet<>(buildRecord.getBuiltArtifacts());
oldBuiltArtifacts.stream().filter(a -> !ids.contains(a.getId())).forEach(a -> a.setBuildRecord(null));
}
Aggregations