diff --git a/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CompletedBakeTaskSpec.groovy b/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CompletedBakeTaskSpec.groovy index 4c52c3d0d2..5f0274ffeb 100644 --- a/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CompletedBakeTaskSpec.groovy +++ b/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CompletedBakeTaskSpec.groovy @@ -79,7 +79,7 @@ class CompletedBakeTaskSpec extends Specification { region = "us-west-1" bakeId = "b-5af233wjj78mwt2f420wt8ey3w" ami = "ami-280c3b6d" - artifact = new Artifact(reference: ami) + artifact = Artifact.builder().reference(ami).build() } def "fails if the bake is not found"() { diff --git a/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CreateBakeTaskSpec.groovy b/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CreateBakeTaskSpec.groovy index 888659cc31..df7977c333 100644 --- a/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CreateBakeTaskSpec.groovy +++ b/orca-bakery/src/test/groovy/com/netflix/spinnaker/orca/bakery/tasks/CreateBakeTaskSpec.groovy @@ -1107,7 +1107,7 @@ class CreateBakeTaskSpec extends Specification { def bakeResult = task.bakeFromContext(stage, selectedBakeryService) then: - 2 * task.artifactResolver.getBoundArtifactForId(stage, _) >> new Artifact() + 2 * task.artifactResolver.getBoundArtifactForId(stage, _) >> Artifact.builder().build() 1 * task.artifactResolver.getAllArtifacts(_) >> [] bakeResult.getPackageArtifacts().size() == 2 } @@ -1135,7 +1135,7 @@ class CreateBakeTaskSpec extends Specification { def bakeResult = task.bakeFromContext(stage, selectedBakeryService) then: - 0 * task.artifactResolver.getBoundArtifactForId(*_) >> new Artifact() + 0 * task.artifactResolver.getBoundArtifactForId(*_) >> Artifact.builder().build() 1 * task.artifactResolver.getAllArtifacts(_) >> [] bakeResult.getPackageArtifacts().size() == 0 } @@ -1164,7 +1164,7 @@ class CreateBakeTaskSpec extends Specification { then: noExceptionThrown() - 2 * task.artifactResolver.getBoundArtifactForId(stage, _) >> new Artifact() + 2 * task.artifactResolver.getBoundArtifactForId(stage, _) >> Artifact.builder().build() 1 * task.artifactResolver.getAllArtifacts(_) >> [] bakeResult.getPackageArtifacts().size() == 2 } diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/cluster/FindImageFromClusterTask.groovy b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/cluster/FindImageFromClusterTask.groovy index 3323e5c6bc..79d980428c 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/cluster/FindImageFromClusterTask.groovy +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/cluster/FindImageFromClusterTask.groovy @@ -257,7 +257,7 @@ class FindImageFromClusterTask extends AbstractCloudProviderAwareTask implements }.flatten() List artifacts = imageSummaries.collect { placement, summaries -> - Artifact artifact = new Artifact() + Artifact artifact = Artifact.builder().build() summaries.findResults { summary -> if (config.imageNamePattern && !(summary.imageName ==~ config.imageNamePattern)) { return null @@ -282,12 +282,14 @@ class FindImageFromClusterTask extends AbstractCloudProviderAwareTask implements log.error("Unable to merge server group image/build info (summary: ${summary})", e) } - artifact.metadata = metadata - artifact.name = summary.imageName - artifact.location = location - artifact.type = "${cloudProvider}/image" - artifact.reference = "${summary.imageId}" - artifact.uuid = UUID.randomUUID().toString() + artifact = Artifact.builder() + .metadata(metadata) + .name(summary.imageName) + .location(location) + .type("${cloudProvider}/image") + .reference("${cloudProvider}/image") + .uuid(UUID.randomUUID().toString()) + .build() } return artifact }.flatten() diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/image/FindImageFromTagsTask.java b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/image/FindImageFromTagsTask.java index 4637c33dba..7e97b09bbf 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/image/FindImageFromTagsTask.java +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/image/FindImageFromTagsTask.java @@ -99,15 +99,14 @@ private Artifact generateArtifactFrom( // This is either all or nothing } - Artifact artifact = new Artifact(); - artifact.setName(imageDetails.getImageName()); - artifact.setReference(imageDetails.getImageId()); - artifact.setLocation(imageDetails.getRegion()); - artifact.setType(cloudProvider + "/image"); - artifact.setMetadata(metadata); - artifact.setUuid(UUID.randomUUID().toString()); - - return artifact; + return Artifact.builder() + .name(imageDetails.getImageName()) + .reference(imageDetails.getImageId()) + .location(imageDetails.getRegion()) + .type(cloudProvider + "/image") + .metadata(metadata) + .uuid(UUID.randomUUID().toString()) + .build(); } @Override diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/strategies/CFRollingRedBlackStrategyTest.java b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/strategies/CFRollingRedBlackStrategyTest.java index ecd34aca0c..6f020c92bc 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/strategies/CFRollingRedBlackStrategyTest.java +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/strategies/CFRollingRedBlackStrategyTest.java @@ -286,7 +286,7 @@ void composeFlowWithNoSourceAndManifestArtifactConvertsManifestToDirect() throws List targetPercentageList = Stream.of(50, 75, 100).collect(Collectors.toList()); context.put("manifest", manifest); context.put("targetPercentages", targetPercentageList); - Artifact boundArtifactForStage = new Artifact(); + Artifact boundArtifactForStage = Artifact.builder().build(); Map application = new HashMap<>(); application.put("instances", "4"); application.put("memory", "64M"); @@ -325,7 +325,7 @@ void composeFlowWithNoSourceAndManifestArtifactConvertsManifestToDirect() throws assertThat(deployServerGroupStage.getContext().get("capacity")).isEqualTo(zeroCapacity); assertThat(deployServerGroupStage.getContext().get("manifest")).isEqualTo(expectedManifest); verify(artifactResolver) - .getBoundArtifactForStage(deployServerGroupStage, artifactId, new Artifact()); + .getBoundArtifactForStage(deployServerGroupStage, artifactId, Artifact.builder().build()); verify(oortService).fetchArtifact(boundArtifactForStage); } @@ -352,7 +352,7 @@ void composeFlowWithSourceAndManifestArtifactConvertsManifestToDirect() throws I new ResizeStrategy.Capacity(initialSourceCapacity.getMax(), 0, 0); Stage deployServerGroupStage = new Stage(new Execution(PIPELINE, "unit"), "type", context); - Artifact boundArtifactForStage = new Artifact(); + Artifact boundArtifactForStage = Artifact.builder().build(); Map application = new HashMap<>(); application.put("instances", "4"); application.put("memory", "64M"); @@ -402,7 +402,7 @@ void composeFlowWithSourceAndManifestArtifactConvertsManifestToDirect() throws I assertThat(deployServerGroupStage.getContext().get("capacity")).isEqualTo(zeroCapacity); assertThat(deployServerGroupStage.getContext().get("manifest")).isEqualTo(expectedManifest); verify(artifactResolver) - .getBoundArtifactForStage(deployServerGroupStage, artifactId, new Artifact()); + .getBoundArtifactForStage(deployServerGroupStage, artifactId, Artifact.builder().build()); verify(oortService).fetchArtifact(boundArtifactForStage); } diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ConsumeArtifactTaskSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ConsumeArtifactTaskSpec.groovy index 737d6e7282..d2496875d8 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ConsumeArtifactTaskSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ConsumeArtifactTaskSpec.groovy @@ -33,7 +33,7 @@ class ConsumeArtifactTaskSpec extends Specification { def oortService = Mock(OortService) def artifactResolver = Stub(ArtifactResolver) { - getBoundArtifactForId(*_) >> new Artifact() + getBoundArtifactForId(*_) >> Artifact.builder().build() } @Subject diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/pipeline/GetPipelinesFromArtifactTaskSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/pipeline/GetPipelinesFromArtifactTaskSpec.groovy index 2776843777..0c3a78ecb6 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/pipeline/GetPipelinesFromArtifactTaskSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/pipeline/GetPipelinesFromArtifactTaskSpec.groovy @@ -47,7 +47,7 @@ class GetPipelinesFromArtifactTaskSpec extends Specification { def result = task.execute(new Stage(Execution.newPipeline("orca"), "whatever", context)) then: - 1 * artifactResolver.getBoundArtifactForStage(_, '123', _) >> new Artifact().builder().type('http/file') + 1 * artifactResolver.getBoundArtifactForStage(_, '123', _) >> Artifact.builder().type('http/file') .reference('url1').build() 1 * oortService.fetchArtifact(_) >> new Response("url1", 200, "reason1", [], new TypedString(pipelineJson)) @@ -66,7 +66,7 @@ class GetPipelinesFromArtifactTaskSpec extends Specification { def result = task.execute(new Stage(Execution.newPipeline("orca"), "whatever", context)) then: - 1 * artifactResolver.getBoundArtifactForStage(_, '123', _) >> new Artifact().builder().type('http/file') + 1 * artifactResolver.getBoundArtifactForStage(_, '123', _) >> Artifact.builder().type('http/file') .reference('url1').build() 1 * oortService.fetchArtifact(_) >> new Response("url1", 200, "reason1", [], new TypedString(pipelineJson)) diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/aws/cloudformation/DeployCloudFormationTaskSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/aws/cloudformation/DeployCloudFormationTaskSpec.groovy index 0534ee22bf..2e44904e21 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/aws/cloudformation/DeployCloudFormationTaskSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/aws/cloudformation/DeployCloudFormationTaskSpec.groovy @@ -106,7 +106,7 @@ class DeployCloudFormationTaskSpec extends Specification { def result = deployCloudFormationTask.execute(stage) then: - (_..1) * artifactResolver.getBoundArtifactForStage(stage, 'id', null) >> new Artifact() + (_..1) * artifactResolver.getBoundArtifactForStage(stage, 'id', null) >> Artifact.builder().build() (_..1) * oortService.fetchArtifact(_) >> new Response("url", 200, "reason", Collections.emptyList(), template) thrown(expectedException) @@ -141,7 +141,7 @@ class DeployCloudFormationTaskSpec extends Specification { def result = deployCloudFormationTask.execute(stage) then: - 1 * artifactResolver.getBoundArtifactForStage(stage, stackArtifactId, _) >> new Artifact() + 1 * artifactResolver.getBoundArtifactForStage(stage, stackArtifactId, _) >> Artifact.builder().build() 1 * oortService.fetchArtifact(_) >> new Response("url", 200, "reason", Collections.emptyList(), new TypedString(template)) 1 * katoService.requestOperations("aws", { it.get(0).get("deployCloudFormation").containsKey("templateBody") diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/ecs/EcsServerGroupCreatorSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/ecs/EcsServerGroupCreatorSpec.groovy index 3778773f28..4e0c6ee2ab 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/ecs/EcsServerGroupCreatorSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/ecs/EcsServerGroupCreatorSpec.groovy @@ -140,7 +140,7 @@ class EcsServerGroupCreatorSpec extends Specification { def taskDefArtifact = [ artifactId: testArtifactId ] - Artifact resolvedArtifact = new Artifact().builder().type('s3/object').name('s3://testfile.json').build() + Artifact resolvedArtifact = Artifact.builder().type('s3/object').name('s3://testfile.json').build() mockResolver.getBoundArtifactForStage(stage, testArtifactId, null) >> resolvedArtifact // define container mappings inputs def (testReg,testRepo,testTag) = ["myregistry.io","myrepo","latest"] diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy index 99d11fbd0b..6995d465dd 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/gce/GoogleServerGroupCreatorSpec.groovy @@ -137,9 +137,7 @@ class GoogleServerGroupCreatorSpec extends Specification { context.putAll(ctx) } artifactResolver.getBoundArtifactForId(*_) >> { - Artifact artifact = new Artifact(); - artifact.setName("santaImage") - return artifact + return Artifact.builder().name("santaImage").build() } ops = new GoogleServerGroupCreator(artifactResolver: artifactResolver).getOperations(stage) diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/kubernetes/KubernetesJobRunnerSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/kubernetes/KubernetesJobRunnerSpec.groovy index 922e05af12..ea6a850fff 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/kubernetes/KubernetesJobRunnerSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/providers/kubernetes/KubernetesJobRunnerSpec.groovy @@ -140,7 +140,7 @@ class KubernetesJobRunnerSpec extends Specification { ) } 1 * artifactResolver.getBoundArtifactForStage(_, _, _) >> { - return new Artifact() + return Artifact.builder().build() } op.manifest == manifest op.requiredArtifacts == [] diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/tasks/artifacts/FindArtifactFromExecutionTaskSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/tasks/artifacts/FindArtifactFromExecutionTaskSpec.groovy index a7f24e031f..be93ff89bc 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/tasks/artifacts/FindArtifactFromExecutionTaskSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/tasks/artifacts/FindArtifactFromExecutionTaskSpec.groovy @@ -30,8 +30,8 @@ import spock.lang.Subject class FindArtifactFromExecutionTaskSpec extends Specification { def PIPELINE = "my pipeline" def EXECUTION_CRITERIA = new ExecutionRepository.ExecutionCriteria().setStatuses(Collections.singletonList("SUCCEEDED")) - def ARTIFACT_A = new Artifact(type: "kubernetes/replicaSet") - def ARTIFACT_B = new Artifact(type: "kubernetes/configMap") + def ARTIFACT_A = Artifact.builder().type("kubernetes/replicaSet").build() + def ARTIFACT_B = Artifact.builder().type("kubernetes/configMap").build() ArtifactResolver artifactResolver = Mock(ArtifactResolver) Execution execution = Mock(Execution) @@ -41,7 +41,7 @@ class FindArtifactFromExecutionTaskSpec extends Specification { def "finds a single artifact"() { given: - def expectedArtifacts = [new ExpectedArtifact(matchArtifact: ARTIFACT_A)] + def expectedArtifacts = [ExpectedArtifact.builder().matchArtifact(ARTIFACT_A).build()] def pipelineArtifacts = [ARTIFACT_A, ARTIFACT_B] Set resolvedArtifacts = [ARTIFACT_A] def stage = new Stage(execution, "findArtifactFromExecution", [ @@ -64,7 +64,7 @@ class FindArtifactFromExecutionTaskSpec extends Specification { def "finds multiple artifacts"() { given: - def expectedArtifacts = [new ExpectedArtifact(matchArtifact: ARTIFACT_A), new ExpectedArtifact(matchArtifact: ARTIFACT_B)] + def expectedArtifacts = [ExpectedArtifact.builder().matchArtifact(ARTIFACT_A).build(), ExpectedArtifact.builder().matchArtifact(ARTIFACT_B).build()] def pipelineArtifacts = [ARTIFACT_A, ARTIFACT_B] Set resolvedArtifacts = [ARTIFACT_A, ARTIFACT_B] def stage = new Stage(execution, "findArtifactFromExecution", [ diff --git a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/expressions/functions/ArtifactExpressionFunctionProviderSpec.groovy b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/expressions/functions/ArtifactExpressionFunctionProviderSpec.groovy index 32d230a848..7397f546a5 100644 --- a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/expressions/functions/ArtifactExpressionFunctionProviderSpec.groovy +++ b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/expressions/functions/ArtifactExpressionFunctionProviderSpec.groovy @@ -31,12 +31,12 @@ import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline class ArtifactExpressionFunctionProviderSpec extends Specification { @Shared def pipeline1 = pipeline { - def matchArtifact1 = new Artifact(type: "docker/image", "name": "artifact1") - def boundArtifact = new Artifact(type: "docker/image", "name": "artifact1", "reference": "artifact1") + def matchArtifact1 = Artifact.builder().type("docker/image").name("artifact1").build() + def boundArtifact = Artifact.builder().type("docker/image").name("artifact1").reference("artifact1").build() trigger = new DefaultTrigger("manual", "artifact1") trigger.resolvedExpectedArtifacts = [ - new ExpectedArtifact(matchArtifact: matchArtifact1, boundArtifact: boundArtifact), + ExpectedArtifact.builder().matchArtifact(matchArtifact1).boundArtifact(boundArtifact).build() ] } diff --git a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactResolverSpec.groovy b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactResolverSpec.groovy index b3bfe6af44..d25afcdcf7 100644 --- a/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactResolverSpec.groovy +++ b/orca-core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/util/ArtifactResolverSpec.groovy @@ -100,14 +100,14 @@ class ArtifactResolverSpec extends Specification { name = "upstream stage" type = "stage1" refId = "1" - outputs.artifacts = [new Artifact(type: "1")] + outputs.artifacts = [Artifact.builder().type("1").build()] } stage { name = "upstream stage" type = "stage2" refId = "2" requisiteStageRefIds = ["1"] - outputs.artifacts = [new Artifact(type: "2"), new Artifact(type: "extra")] + outputs.artifacts = [Artifact.builder().type("2").build(), Artifact.builder().type("extra").build()] } stage { name = "desired" @@ -132,14 +132,14 @@ class ArtifactResolverSpec extends Specification { name = "upstream stage" type = "stage1" refId = "1" - outputs.artifacts = [new Artifact(type: "1")] + outputs.artifacts = [Artifact.builder().type("1").build()] } stage { name = "upstream stage" type = "stage2" refId = "2" requisiteStageRefIds = ["1"] - outputs.artifacts = [new Artifact(type: "2")] + outputs.artifacts = [Artifact.builder().type("2").build()] } stage { name = "desired" @@ -155,14 +155,14 @@ class ArtifactResolverSpec extends Specification { name = "upstream stage" type = "stage1" refId = "1" - outputs.artifacts = [new Artifact(type: "1")] + outputs.artifacts = [Artifact.builder().type("1").build()] } stage { name = "desired" requisiteStageRefIds = ["1"] } } - execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [new Artifact(type: "trigger")]) + execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [Artifact.builder().type("trigger").build()]) def desired = execution.getStages().find { it.name == "desired" } def artifactResolver = makeArtifactResolver() @@ -204,8 +204,8 @@ class ArtifactResolverSpec extends Specification { type = "stage1" refId = "1" outputs.resolvedExpectedArtifacts = [ - new ExpectedArtifact(id: "1", boundArtifact: new Artifact(type: "correct")), - new ExpectedArtifact(id: "2", boundArtifact: new Artifact(type: "incorrect")) + ExpectedArtifact.builder().id("1").boundArtifact(Artifact.builder().type("correct").build()).build(), + ExpectedArtifact.builder().id("2").boundArtifact(Artifact.builder().type("incorrect").build()).build() ] } stage { @@ -226,6 +226,10 @@ class ArtifactResolverSpec extends Specification { } def "should find a bound artifact from a trigger"() { + given: + def correctArtifact = Artifact.builder().type("correct").build() + def incorrectArtifact = Artifact.builder().type("incorrect").build() + when: def execution = pipeline { stage { @@ -233,7 +237,7 @@ class ArtifactResolverSpec extends Specification { type = "stage1" refId = "1" outputs.resolvedExpectedArtifacts = [ - new ExpectedArtifact(id: "2", boundArtifact: new Artifact(type: "incorrect")) + ExpectedArtifact.builder().id("2").boundArtifact(incorrectArtifact).build() ] } stage { @@ -244,7 +248,7 @@ class ArtifactResolverSpec extends Specification { } } execution.trigger = new DefaultTrigger("webhook") - execution.trigger.resolvedExpectedArtifacts = [new ExpectedArtifact(id: "1", boundArtifact: new Artifact(type: "correct"))] + execution.trigger.resolvedExpectedArtifacts = [ExpectedArtifact.builder().id("1").boundArtifact(correctArtifact).build()] def desired = execution.getStages().find { it.name == "desired" } def artifactResolver = makeArtifactResolver() @@ -259,32 +263,34 @@ class ArtifactResolverSpec extends Specification { def "should find a matching artifact for #expected"() { when: def artifactResolver = makeArtifactResolver() + def expected = ExpectedArtifact.builder().matchArtifact(matchArtifact).build() def artifact = artifactResolver.resolveSingleArtifact(expected, existing, null, true) then: artifact == desired where: - expected | existing || desired - new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/image")) | [new Artifact(type: "docker/image"), new Artifact(type: "amazon/ami")] || new Artifact(type: "docker/image") - new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*")) | [new Artifact(type: "docker/image"), new Artifact(type: "amazon/ami")] || new Artifact(type: "docker/image") - new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*", name: "image")) | [new Artifact(type: "docker/image", name: "bad"), new Artifact(type: "docker/image", name: "image")] || new Artifact(type: "docker/image", name: "image") + matchArtifact | existing || desired + Artifact.builder().type("docker/image").build() | [Artifact.builder().type("docker/image").build(), Artifact.builder().type("amazon/ami").build()] || Artifact.builder().type("docker/image").build() + Artifact.builder().type("docker/.*").build() | [Artifact.builder().type("docker/image").build(), Artifact.builder().type("amazon/ami").build()] || Artifact.builder().type("docker/image").build() + Artifact.builder().type("docker/.*").name("image").build() | [Artifact.builder().type("docker/image").name("bad").build(), Artifact.builder().type("docker/image").name("image").build()] || Artifact.builder().type("docker/image").name("image").build() } @Unroll def "should fail find a matching artifact for #expected"() { when: def artifactResolver = makeArtifactResolver() + def expected = ExpectedArtifact.builder().matchArtifact(matchArtifact).build() def artifact = artifactResolver.resolveSingleArtifact(expected, existing, null, true) then: artifact == null where: - expected | existing - new ExpectedArtifact(matchArtifact: new Artifact(type: "image/image")) | [new Artifact(type: "docker/image"), new Artifact(type: "amazon/ami")] - new ExpectedArtifact(matchArtifact: new Artifact(type: "flocker/.*")) | [new Artifact(type: "docker/image"), new Artifact(type: "amazon/ami")] - new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*", name: "none")) | [new Artifact(type: "docker/image", name: "bad"), new Artifact(type: "docker/image", name: "image")] + matchArtifact | existing + Artifact.builder().type("image/image").build() | [Artifact.builder().type("docker/image").build(), Artifact.builder().type("amazon/ami").build()] + Artifact.builder().type("flocker/.*").build() | [Artifact.builder().type("docker/image").build(), Artifact.builder().type("amazon/ami").build()] + Artifact.builder().type("docker/.*").name("none").build() | [Artifact.builder().type("docker/image").name("bad").build(), Artifact.builder().type("docker/image").name("image").build()] } def "should find all artifacts from an execution, in reverse order"() { @@ -292,19 +298,19 @@ class ArtifactResolverSpec extends Specification { def execution = pipeline { stage { refId = "1" - outputs.artifacts = [new Artifact(type: "1")] + outputs.artifacts = [Artifact.builder().type("1").build()] } stage { refId = "2" requisiteStageRefIds = ["1"] - outputs.artifacts = [new Artifact(type: "2")] + outputs.artifacts = [Artifact.builder().type("2").build()] } stage { // This stage does not emit an artifact requisiteStageRefIds = ["2"] } } - execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [new Artifact(type: "trigger")]) + execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [Artifact.builder().type("trigger").build()]) def artifactResolver = makeArtifactResolver() @@ -321,19 +327,19 @@ class ArtifactResolverSpec extends Specification { status: ExecutionStatus.SUCCEEDED stage { refId = "1" - outputs.artifacts = [new Artifact(type: "1")] + outputs.artifacts = [Artifact.builder().type("1").build()] } stage { refId = "2" requisiteStageRefIds = ["1"] - outputs.artifacts = [new Artifact(type: "2")] + outputs.artifacts = [Artifact.builder().type("2").build()] } stage { // This stage does not emit an artifacts requisiteStageRefIds = ["2"] } } - execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [new Artifact(type: "trigger")]) + execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [Artifact.builder().type("trigger").build()]) def executionCriteria = new ExecutionRepository.ExecutionCriteria() executionCriteria.setStatuses(ExecutionStatus.SUCCEEDED) @@ -366,19 +372,19 @@ class ArtifactResolverSpec extends Specification { id: pipelineId stage { refId = "1" - outputs.artifacts = [new Artifact(type: "1")] + outputs.artifacts = [Artifact.builder().type("1").build()] } stage { refId = "2" requisiteStageRefIds = ["1"] - outputs.artifacts = [new Artifact(type: "2")] + outputs.artifacts = [Artifact.builder().type("2").build()] } stage { // This stage does not emit an artifacts requisiteStageRefIds = ["2"] } } - execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [new Artifact(type: "trigger")]) + execution.trigger = new DefaultTrigger("webhook", null, "user", [:], [Artifact.builder().type("trigger").build()]) def executionRepositoryStub = Stub(ExecutionRepository) { // only a call to retrievePipelinesForPipelineConfigId() with these argument values is expected @@ -394,22 +400,66 @@ class ArtifactResolverSpec extends Specification { artifacts.size == 2 artifacts*.type == ["1", "trigger"] } + @Unroll - def "should resolve expected artifacts from pipeline for #expectedArtifacts using #available and prior #prior"() { + def "should resolve expected artifacts from pipeline for default #defaultArtifact, available #available, and prior #prior"() { + given: + def matchArtifact = Artifact.builder().type("docker/.*").build() when: def artifactResolver = makeArtifactResolver() - def bound = artifactResolver.resolveExpectedArtifacts(expectedArtifacts, available, prior, true) + def expectedArtifact = ExpectedArtifact.builder() + .matchArtifact(matchArtifact) + .defaultArtifact(defaultArtifact) + .useDefaultArtifact(defaultArtifact != null) + .usePriorArtifact(usePriorArtifact) + .build() + def bound = artifactResolver.resolveExpectedArtifacts([expectedArtifact], available, prior, true) then: bound.size() == expectedBound.size() bound.findAll({ a -> expectedBound.contains(a) }).size() == bound.size() where: - expectedArtifacts | available | prior || expectedBound - [new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*"))] | [new Artifact(type: "docker/image")] | null || [new Artifact(type: "docker/image")] - [new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*"), useDefaultArtifact: true, defaultArtifact: new Artifact(type: "google/image"))] | [new Artifact(type: "bad")] | null || [new Artifact(type: "google/image")] - [new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*"), usePriorArtifact: true)] | [new Artifact(type: "bad")] | [new Artifact(type: "docker/image")] || [new Artifact(type: "docker/image")] - [new ExpectedArtifact(matchArtifact: new Artifact(type: "google/.*"), usePriorArtifact: true), new ExpectedArtifact(matchArtifact: new Artifact(type: "docker/.*"), useDefaultArtifact: true, defaultArtifact: new Artifact(type: "docker/image"))] | [new Artifact(type: "bad"), new Artifact(type: "more bad")] | [new Artifact(type: "google/image")] || [new Artifact(type: "docker/image"), new Artifact(type: "google/image")] + defaultArtifact | usePriorArtifact | available | prior || expectedBound + null | false | [Artifact.builder().type("docker/image").build()] | null || [Artifact.builder().type("docker/image").build()] + Artifact.builder().type("google/image").build() | false | [Artifact.builder().type("bad").build()] | null || [Artifact.builder().type("google/image").build()] + null | true | [Artifact.builder().type("bad").build()] | [Artifact.builder().type("docker/image").build()] || [Artifact.builder().type("docker/image").build()] + } + + def "can resolve both a prior artifact and a default artifact from the same pipeline"() { + given: + def dockerArtifact = Artifact.builder().type("docker/image").build() + def gceImage = Artifact.builder().type("google/image").build() + def expectedArtifacts = [ + ExpectedArtifact.builder() + .matchArtifact(Artifact.builder().type("google/.*").build()) + .usePriorArtifact(true) + .build(), + ExpectedArtifact.builder() + .matchArtifact(Artifact.builder().type("docker/.*").build()) + .useDefaultArtifact(true) + .defaultArtifact(dockerArtifact) + .build() + ] + def availableArtifacts = [ + Artifact.builder().type("bad").build(), + Artifact.builder().type("more bad").build() + ] + def priorArtifacts = [ + gceImage + ] + def expectedBound = [ + dockerArtifact, + gceImage + ] + + when: + def artifactResolver = makeArtifactResolver() + def bound = artifactResolver.resolveExpectedArtifacts(expectedArtifacts, availableArtifacts, priorArtifacts, true) + + then: + bound.size() == expectedBound.size() + bound.findAll({ a -> expectedBound.contains(a) }).size() == bound.size() } def "resolveArtifacts sets the bound artifact on an expected artifact"() { diff --git a/orca-front50/src/test/groovy/com/netflix/spinnaker/orca/front50/DependentPipelineStarterSpec.groovy b/orca-front50/src/test/groovy/com/netflix/spinnaker/orca/front50/DependentPipelineStarterSpec.groovy index 593e923326..2f866db66a 100644 --- a/orca-front50/src/test/groovy/com/netflix/spinnaker/orca/front50/DependentPipelineStarterSpec.groovy +++ b/orca-front50/src/test/groovy/com/netflix/spinnaker/orca/front50/DependentPipelineStarterSpec.groovy @@ -182,10 +182,7 @@ class DependentPipelineStarterSpec extends Specification { ] ]] ]; - Artifact testArtifact = new Artifact( - type: "gcs/object", - name: "gs://test/file.yaml" - ) + Artifact testArtifact = Artifact.builder().type("gcs/object").name("gs://test/file.yaml").build() def parentPipeline = pipeline { name = "parent" trigger = new DefaultTrigger("webhook", null, "test", [:], [testArtifact]); @@ -244,10 +241,7 @@ class DependentPipelineStarterSpec extends Specification { ] ]] ]; - Artifact testArtifact = new Artifact( - type: "gcs/object", - name: "gs://test/file.yaml" - ) + Artifact testArtifact = Artifact.builder().type("gcs/object").name("gs://test/file.yaml").build() def parentPipeline = pipeline { name = "parent" trigger = new DefaultTrigger("webhook", null, "test") @@ -316,14 +310,8 @@ class DependentPipelineStarterSpec extends Specification { ] ]] ] - Artifact testArtifact1 = new Artifact( - type: "gcs/object", - name: "gs://test/file.yaml" - ) - Artifact testArtifact2 = new Artifact( - type: "docker/image", - name: "gcr.io/project/image" - ) + Artifact testArtifact1 = Artifact.builder().type("gcs/object").name("gs://test/file.yaml").build() + Artifact testArtifact2 = Artifact.builder().type("docker/image").name("gcr.io/project/image").build() def parentPipeline = pipeline { name = "parent" trigger = new DefaultTrigger("webhook", null, "test", [:], [testArtifact1, testArtifact2]) @@ -511,16 +499,14 @@ class DependentPipelineStarterSpec extends Specification { def priorExecution = pipeline { id = "01DCKTEZPRCMFV1H35EDFC62RG" trigger = new DefaultTrigger("manual", null, "user@acme.com", [:], [ - new Artifact([ - customKind: false, - metadata: [ - fileName: "wait.0.1.yml", - ], - name: "wait", - reference: "https://artifactory.acme.com/spinnaker-pac/wait.0.1.yml", - type: "spinnaker-pac", - version: "0.1" - ]) + Artifact.builder() + .customKind(false) + .metadata([fileName: "wait.0.1.yml"]) + .name("wait") + .reference("https://artifactory.acme.com/spinnaker-pac/wait.0.1.yml") + .type("spinnaker-pac") + .version("spinnaker-pac") + .build() ]) } def parentPipeline = pipeline { @@ -649,12 +635,12 @@ class DependentPipelineStarterSpec extends Specification { ], PipelineTemplate) - Artifact testArtifact = new Artifact( - type: "http/file", - name: "artifact-name", - customKind: true, - reference: "a-reference" - ) + Artifact testArtifact = Artifact.builder() + .type("http/file") + .name("artifact-name") + .customKind(true) + .reference("a-reference") + .build() def parentPipeline = pipeline { name = "parent" trigger = new DefaultTrigger("webhook", null, "test", [:], [testArtifact])