Skip to content

Commit

Permalink
NCL-7815 Implement Artifacts Delivered in Milestones integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikk0123 committed Dec 11, 2024
1 parent dae74c2 commit e00eeec
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,39 @@ public void initiliazeBuildRecordDemoData() {
.deployPath("/built15")
.build();

Artifact builtArtifact16a = Artifact.Builder.newBuilder()
.buildRecord(buildRecord7)
.identifier("demo:built-artifact16:jar:1.0.redhat-a")
.targetRepository(targetRepository)
.filename("demo built artifact 16a")
.md5("md5-fake-123abc")
.sha1("sha1-fake-123abc")
.sha256("sha256-fake-123abc")
.size(16L)
.artifactQuality(ArtifactQuality.NEW)
.deployPath("/demo/built-artifact16/1.0.redhat-a/built-artifact16-1.0.redhat-a.jar")
.build();

Artifact builtArtifact16b = Artifact.Builder.newBuilder()
.buildRecord(buildRecord7)
.identifier("demo:built-artifact16:jar:1.0.redhat-b")
.targetRepository(targetRepository)
.filename("demo built artifact 16b")
.md5("md5-fake-123abc")
.sha1("sha1-fake-123abc")
.sha256("sha256-fake-123abc")
.size(16L)
.artifactQuality(ArtifactQuality.NEW)
.deployPath("/demo/built-artifact16/1.0.redhat-b/built-artifact16-1.0.redhat-b.jar")
.build();

builtArtifact11 = artifactRepository.save(builtArtifact11);
builtArtifact12 = artifactRepository.save(builtArtifact12);
builtArtifact13 = artifactRepository.save(builtArtifact13);
builtArtifact14 = artifactRepository.save(builtArtifact14);
builtArtifact15 = artifactRepository.save(builtArtifact15);
builtArtifact16a = artifactRepository.save(builtArtifact16a);
builtArtifact16b = artifactRepository.save(builtArtifact16b);

demoProductMilestone1 = productMilestoneRepository.queryById(demoProductMilestone1.getId());
demoProductMilestone3 = productMilestoneRepository.queryById(demoProductMilestone3.getId());
Expand Down Expand Up @@ -1265,6 +1293,26 @@ public void initiliazeBuildRecordDemoData() {
.build();
operation4 = deliverableAnalyzerOperationRepository.save(operation4);

DeliverableAnalyzerOperation operation5 = DeliverableAnalyzerOperation.Builder.newBuilder()
.id(new Base32LongID(1000005l))
.progressStatus(ProgressStatus.FINISHED)
.submitTime(TODAY)
.startTime(TODAY)
.user(demoUser)
.productMilestone(demoProductMilestone1)
.build();
operation5 = deliverableAnalyzerOperationRepository.save(operation5);

DeliverableAnalyzerOperation operation6 = DeliverableAnalyzerOperation.Builder.newBuilder()
.id(new Base32LongID(1000006l))
.progressStatus(ProgressStatus.FINISHED)
.submitTime(TODAY)
.startTime(TODAY)
.user(demoUser)
.productMilestone(demoProductMilestone2)
.build();
operation6 = deliverableAnalyzerOperationRepository.save(operation6);

DeliverableAnalyzerReport report1 = DeliverableAnalyzerReport.builder()
.operation(operation2)
.labels(EnumSet.of(DeliverableAnalyzerReportLabel.RELEASED))
Expand All @@ -1283,6 +1331,18 @@ public void initiliazeBuildRecordDemoData() {
.build();
report3 = deliverableAnalyzerReportRepository.save(report3);

DeliverableAnalyzerReport report4 = DeliverableAnalyzerReport.builder()
.operation(operation5)
.labels(EnumSet.noneOf(DeliverableAnalyzerReportLabel.class))
.build();
report4 = deliverableAnalyzerReportRepository.save(report4);

DeliverableAnalyzerReport report5 = DeliverableAnalyzerReport.builder()
.operation(operation6)
.labels(EnumSet.noneOf(DeliverableAnalyzerReportLabel.class))
.build();
report5 = deliverableAnalyzerReportRepository.save(report5);

DeliverableAnalyzerLabelEntry report1LabelEntry1 = DeliverableAnalyzerLabelEntry.builder()
.report(report1)
.changeOrder(1)
Expand Down Expand Up @@ -1354,6 +1414,24 @@ public void initiliazeBuildRecordDemoData() {
.builtFromSource(true)
.brewBuildId(null)
.build();
DeliverableArtifact analyzedArtifact11a = DeliverableArtifact.builder()
.report(report4)
.artifact(builtArtifact16a)
.builtFromSource(true)
.brewBuildId(null)
.build();
DeliverableArtifact analyzedArtifact11b = DeliverableArtifact.builder()
.report(report4)
.artifact(builtArtifact16b)
.builtFromSource(true)
.brewBuildId(null)
.build();
DeliverableArtifact analyzedArtifact12 = DeliverableArtifact.builder()
.report(report5)
.artifact(builtArtifact16b)
.builtFromSource(true)
.brewBuildId(null)
.build();

deliverableArtifactRepository.save(analyzedArtifact1);
deliverableArtifactRepository.save(analyzedArtifact2);
Expand All @@ -1365,6 +1443,9 @@ public void initiliazeBuildRecordDemoData() {
deliverableArtifactRepository.save(analyzedArtifact8);
deliverableArtifactRepository.save(analyzedArtifact9);
deliverableArtifactRepository.save(analyzedArtifact10);
deliverableArtifactRepository.save(analyzedArtifact11a);
deliverableArtifactRepository.save(analyzedArtifact11b);
deliverableArtifactRepository.save(analyzedArtifact12);
}

private RepositoryConfiguration createRepositoryConfiguration(String internalScmUrl, String externalUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testGetAllArtifacts() throws RemoteResourceException {

RemoteCollection<Artifact> all = client.getAll(null, null, null);

assertThat(all).hasSize(17); // from DatabaseDataInitializer
assertThat(all).hasSize(19); // from DatabaseDataInitializer
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void shouldGetDeliverableAnalyzerReports() throws RemoteResourceException
RestClientConfiguration.asAnonymous());
RemoteCollection<DeliverableAnalyzerReport> all = client.getAll();

assertThat(all).hasSize(3);
assertThat(all).hasSize(5);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.jboss.pnc.integration.endpoints;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
Expand All @@ -31,6 +33,8 @@
import org.jboss.pnc.dto.Artifact;
import org.jboss.pnc.dto.Build;
import org.jboss.pnc.dto.DeliverableAnalyzerOperation;
import org.jboss.pnc.dto.response.ArtifactVersion;
import org.jboss.pnc.dto.response.DeliveredArtifactInMilestones;
import org.jboss.pnc.dto.Product;
import org.jboss.pnc.dto.ProductMilestone;
import org.jboss.pnc.dto.ProductMilestoneCloseResult;
Expand Down Expand Up @@ -341,7 +345,7 @@ public void testGetDeliveredArtifacts() throws ClientException {

RemoteCollection<Artifact> all = client.getDeliveredArtifacts(milestoneId);

assertThat(all).hasSize(7);
assertThat(all).hasSize(9);
RemoteCollection<Artifact> built = client.getDeliveredArtifacts(
milestoneId,
Optional.empty(),
Expand All @@ -358,7 +362,7 @@ public void testGetDeliverableAnalyzerOperations() throws ClientException {

RemoteCollection<DeliverableAnalyzerOperation> all = client.getAllDeliverableAnalyzerOperations(milestoneId);

assertThat(all).hasSize(5);
assertThat(all).hasSize(6);

RemoteCollection<DeliverableAnalyzerOperation> allInProgress = client.getAllDeliverableAnalyzerOperations(
milestoneId,
Expand All @@ -378,18 +382,18 @@ public void testGetStatistics() throws ClientException {
.thisMilestone(2L) // builtArtifact1, builtArtifact9
.otherMilestones(1L) // builtArtifact10
.otherProducts(2L) // builtArtifact11, builtArtifact12
.noMilestone(1L) // builtArtifact5
.noMilestone(3L) // builtArtifact5
.noBuild(1L) // importedArtifact2
.build();

EnumMap<ArtifactQuality, Long> expectedArtifactQualities = Maps
.initEnumMapWithDefaultValue(ArtifactQuality.class, 0L);
expectedArtifactQualities.put(ArtifactQuality.NEW, 6L);
expectedArtifactQualities.put(ArtifactQuality.NEW, 8L);
expectedArtifactQualities.put(ArtifactQuality.VERIFIED, 1L);

EnumMap<RepositoryType, Long> expectedRepositoryTypes = Maps
.initEnumMapWithDefaultValue(RepositoryType.class, 0L);
expectedRepositoryTypes.put(RepositoryType.MAVEN, 7L);
expectedRepositoryTypes.put(RepositoryType.MAVEN, 9L);

ProductMilestoneStatistics expectedStats = ProductMilestoneStatistics.builder()
.artifactsInMilestone(3L) // builtArtifact1, builtArtifact2, builtArtifact9
Expand Down Expand Up @@ -418,6 +422,48 @@ public void testGetStatistics() throws ClientException {
assertThat(actualStats).isEqualTo(expectedStats);
}

@Test
public void testGetArtifactsDeliveredInMilestonesGroupedByPrefix_twoMilestones_foundArtifacts()
throws ClientException {
// arrange
ProductMilestoneClient client = new ProductMilestoneClient(RestClientConfiguration.asAnonymous());

ArtifactVersion artifactVersion1 = ArtifactVersion.builder()
.id("117")
.artifactVersion("1.0.redhat-a")
.type("jar")
.build();
ArtifactVersion artifactVersion2 = ArtifactVersion.builder()
.id("118")
.artifactVersion("1.0.redhat-b")
.type("jar")
.build();

DeliveredArtifactInMilestones expectedDeliveredArtifactsInMilestones = DeliveredArtifactInMilestones.builder()
.artifactIdentifierPrefix("demo:built-artifact16")
.productMilestoneArtifacts(
ImmutableMap.of(
"100",
Lists.newArrayList(artifactVersion1, artifactVersion2),
"101",
Lists.newArrayList(artifactVersion2)))
.build();

// act
List<DeliveredArtifactInMilestones> actualDeliveredArtifactsInMilestonesList = client
.getArtifactsDeliveredInMilestonesGroupedByPrefix(
Lists.newArrayList(milestone.getId(), milestone2.getId()));

// assert
assertThat(actualDeliveredArtifactsInMilestonesList).hasSize(1);
var actualDeliveredArtifactsInMilestones = actualDeliveredArtifactsInMilestonesList.iterator().next();

assertThat(actualDeliveredArtifactsInMilestones.getArtifactIdentifierPrefix())
.isEqualTo(expectedDeliveredArtifactsInMilestones.getArtifactIdentifierPrefix());
assertThat(actualDeliveredArtifactsInMilestones.getProductMilestoneArtifacts())
.isEqualTo(expectedDeliveredArtifactsInMilestones.getProductMilestoneArtifacts());
}

@Test
public void shouldScratchFlagBeFalseImplicitly() throws ClientException {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public void testGetStatisticsForExistingProductVersion() throws ClientException
.thisVersion(3L) // bA1, bA9, bA10
.otherVersions(1L) // bA13
.otherProducts(2L) // bA11, bA12
.noMilestone(1L) // bA5
.noMilestone(4L) // bA5
.noBuild(1L) // iA2
.build();

Expand Down Expand Up @@ -508,7 +508,7 @@ public void testGetArtifactQualitiesStatisticsForExistingProductVersion() throws

EnumMap<ArtifactQuality, Long> expectedArtifactQualities = Maps
.initEnumMapWithDefaultValue(ArtifactQuality.class, 0L);
expectedArtifactQualities.put(ArtifactQuality.NEW, 6L);
expectedArtifactQualities.put(ArtifactQuality.NEW, 8L);
expectedArtifactQualities.put(ArtifactQuality.VERIFIED, 1L);

ProductMilestoneArtifactQualityStatistics expectedArtQualityStats = ProductMilestoneArtifactQualityStatistics
Expand Down Expand Up @@ -557,7 +557,7 @@ public void testGetRepositoryTypesStatisticsForExistingProductVersion() throws C

EnumMap<RepositoryType, Long> expectedRepositoryTypes = Maps
.initEnumMapWithDefaultValue(RepositoryType.class, 0L);
expectedRepositoryTypes.put(RepositoryType.MAVEN, 7L);
expectedRepositoryTypes.put(RepositoryType.MAVEN, 9L);

ProductMilestoneRepositoryTypeStatistics expectedRepoTypeStats = ProductMilestoneRepositoryTypeStatistics
.builder()
Expand Down Expand Up @@ -597,5 +597,4 @@ public void testGetRepositoryTypesStatisticsForNonexistingProductVersion() throw
// then
assertThat(all).isEmpty();
}

}

0 comments on commit e00eeec

Please sign in to comment.