this.add(new TestArtifactConfig(source, destination)); } else { this.add(new BuildArtifactConfig(source, destination));
@Test public void shouldAllowOverridingDefaultArtifactDestination() { BuildArtifactConfig artifactConfig = new BuildArtifactConfig("src", "dest"); assertThat(artifactConfig.getDestination(), is("dest")); TestArtifactConfig testArtifactConfig = new TestArtifactConfig("src", "destination"); assertThat(testArtifactConfig.getDestination(), is("destination")); }
@Test public void validate_shouldNotFailWhenDestinationIsNotSet() { BuildArtifactConfig artifactPlan = new BuildArtifactConfig(null, null); artifactPlan.setSource("source"); artifactPlan.validate(null); assertThat(artifactPlan.errors().isEmpty(), is(true)); }
public BuildArtifactConfig(String source, String destination) { setSource(source); setDestination(destination); }
@Test public void validate_shouldFailIfDestDoesNotMatchAFilePattern() { BuildArtifactConfig artifactPlan = new BuildArtifactConfig("foo/bar", ".."); artifactPlan.validate(null); assertThat(artifactPlan.errors().on(BuiltinArtifactConfig.DEST), is("Invalid destination path. Destination path should match the pattern (([.]\\/)?[.][^. ]+)|([^. ].+[^. ])|([^. ][^. ])|([^. ])")); }
@Test public void validate_shouldNotFailWhenComparingBuildAndTestArtifacts() { List<ArtifactConfig> plans = new ArrayList<>(); TestArtifactConfig testArtifactConfig = new TestArtifactConfig("src", "dest"); plans.add(testArtifactConfig); BuildArtifactConfig buildArtifactConfig = new BuildArtifactConfig("src", "dest"); buildArtifactConfig.validateUniqueness(plans); assertThat(buildArtifactConfig.errors().isEmpty(), is(true)); }
public static CruiseConfig pipelineHavingJob(String pipelineName, String stageName, String jobPlanName, String filePath, String directoryPath) { CruiseConfig config = new BasicCruiseConfig(); config.server().setArtifactsDir("logs"); JobConfig job = new JobConfig(jobPlanName); String workingDir = new File("testdata/" + CruiseConfig.WORKING_BASE_DIR + stageName).getPath(); AntTask task = new AntTask(); task.setWorkingDirectory(workingDir); job.addTask(task); final BuildArtifactConfig artifactFile = new BuildArtifactConfig(); artifactFile.setSource(filePath); job.artifactConfigs().add(artifactFile); BuildArtifactConfig artifactDir = new BuildArtifactConfig(); artifactFile.setSource(directoryPath); job.artifactConfigs().add(artifactDir); PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString(pipelineName), new MaterialConfigs(new SvnMaterialConfig("file:///foo", null, null, false)), new StageConfig( new CaseInsensitiveString(stageName), new JobConfigs(job))); config.addPipeline(BasicPipelineConfigs.DEFAULT_GROUP, pipelineConfig); return config; }
private CRArtifact artifactConfigToCRArtifact(ArtifactConfig artifactConfig) { if (artifactConfig instanceof BuildArtifactConfig) { BuildArtifactConfig buildArtifact = (BuildArtifactConfig) artifactConfig; return new CRBuiltInArtifact(buildArtifact.getSource(), buildArtifact.getDestination()); } else if (artifactConfig instanceof TestArtifactConfig) { TestArtifactConfig testArtifact = (TestArtifactConfig) artifactConfig; return new CRBuiltInArtifact(testArtifact.getSource(), testArtifact.getDestination(), CRArtifactType.test); } else if (artifactConfig instanceof PluggableArtifactConfig) { PluggableArtifactConfig pluggableArtifact = (PluggableArtifactConfig) artifactConfig; List<CRConfigurationProperty> crConfigurationProperties = configurationToCRConfiguration(pluggableArtifact.getConfiguration()); return new CRPluggableArtifact(pluggableArtifact.getId(), pluggableArtifact.getStoreId(), crConfigurationProperties); } else { throw new RuntimeException(String.format("Unsupported Artifact Type: %s.", artifactConfig.getArtifactType())); } }
@Test public void validate_shouldFailIfSourceIsEmpty() { BuildArtifactConfig artifactPlan = new BuildArtifactConfig(null, "bar"); artifactPlan.validate(ConfigSaveValidationContext.forChain(new JobConfig("jobname"))); assertThat(artifactPlan.errors().on(BuiltinArtifactConfig.SRC), is("Job 'jobname' has an artifact with an empty source")); }
@Test public void shouldErrorOutWhenDuplicateArtifactConfigsExists() { List<ArtifactConfig> plans = new ArrayList<>(); BuildArtifactConfig existingPlan = new BuildArtifactConfig("src", "dest"); plans.add(existingPlan); BuildArtifactConfig artifactPlan = new BuildArtifactConfig("src", "dest"); artifactPlan.validateUniqueness(plans); assertThat(artifactPlan.errors().isEmpty(), is(false)); assertThat(artifactPlan.errors().on(BuiltinArtifactConfig.SRC), is("Duplicate artifacts defined.")); assertThat(artifactPlan.errors().on(BuiltinArtifactConfig.DEST), is("Duplicate artifacts defined.")); assertThat(existingPlan.errors().isEmpty(), is(false)); assertThat(existingPlan.errors().on(BuiltinArtifactConfig.SRC), is("Duplicate artifacts defined.")); assertThat(existingPlan.errors().on(BuiltinArtifactConfig.DEST), is("Duplicate artifacts defined.")); }
public static ArtifactConfig fromJSON(JsonReader jsonReader) { String type = jsonReader.getString("type"); ArtifactConfig artifactConfig; switch (type) { case "build": artifactConfig = BuiltinArtifactConfigRepresenter.fromJSON(jsonReader, new BuildArtifactConfig()); break; case "test": artifactConfig = BuiltinArtifactConfigRepresenter.fromJSON(jsonReader, new TestArtifactConfig()); break; case "external": artifactConfig = ExternalArtifactConfigRepresenter.fromJSON(jsonReader, new PluggableArtifactConfig()); break; default: throw new UnprocessableEntityException(String.format("Invalid Artifact type: '%s'. It has to be one of %s.", type, String.join(",", "build", "test", "external"))); } return artifactConfig; } }
@Test public void shouldNotOverrideDefaultArtifactDestinationWhenNotSpecified() { BuildArtifactConfig artifactConfig = new BuildArtifactConfig("src", null); assertThat(artifactConfig.getDestination(), is("")); TestArtifactConfig testArtifactConfig = new TestArtifactConfig("src", null); assertThat(testArtifactConfig.getDestination(), is("testoutput")); } }
public static ArtifactConfig fromJSON(JsonReader jsonReader) { String type = jsonReader.getString("type"); ArtifactConfig artifactConfig; switch (type) { case "build": artifactConfig = BuiltinArtifactConfigRepresenter.fromJSON(jsonReader, new BuildArtifactConfig()); break; case "test": artifactConfig = BuiltinArtifactConfigRepresenter.fromJSON(jsonReader, new TestArtifactConfig()); break; case "external": artifactConfig = ExternalArtifactConfigRepresenter.fromJSON(jsonReader, new PluggableArtifactConfig()); break; default: throw new UnprocessableEntityException(String.format("Invalid Artifact type: '%s'. It has to be one of %s.", type, String.join(",", "build", "test", "external"))); } return artifactConfig; } }
private static ArtifactConfig createBuiltInArtifactConfig(ArtifactType artifactType, String src, String dest) { if (artifactType == ArtifactType.build) { return new BuildArtifactConfig(src, dest); } else if (artifactType == ArtifactType.test) { return new TestArtifactConfig(src, dest); } else { throw bomb("ArtifactType not specified"); } }
@Test public void getArtifactConfigs_shouldReturnBuiltinArtifactConfigs() { ArtifactConfigs allConfigs = new ArtifactConfigs(); allConfigs.add(new BuildArtifactConfig("src", "dest")); allConfigs.add(new BuildArtifactConfig("java", null)); allConfigs.add(new PluggableArtifactConfig("s3", "cd.go.s3")); allConfigs.add(new PluggableArtifactConfig("docker", "cd.go.docker")); final List<BuiltinArtifactConfig> artifactConfigs = allConfigs.getBuiltInArtifactConfigs(); assertThat(artifactConfigs, hasSize(2)); assertThat(artifactConfigs, containsInAnyOrder( new BuildArtifactConfig("src", "dest"), new BuildArtifactConfig("java", null) )); }
@Test public void shouldAddDuplicatedArtifactSoThatValidationKicksIn() throws Exception { final ArtifactConfigs artifactConfigs = new ArtifactConfigs(); assertThat(artifactConfigs.size(), is(0)); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); assertThat(artifactConfigs.size(), is(2)); }
@Test public void setConfigAttributes_shouldIgnoreEmptySourceAndDest() { HashMap<String, String> artifactPlan1 = new HashMap<>(); artifactPlan1.put(SRC, "blah"); artifactPlan1.put(DEST, "something"); artifactPlan1.put("artifactTypeValue", TestArtifactConfig.TEST_PLAN_DISPLAY_NAME); HashMap<String, String> artifactPlan2 = new HashMap<>(); artifactPlan2.put(SRC, "blah2"); artifactPlan2.put(DEST, "something2"); artifactPlan2.put("artifactTypeValue", BuildArtifactConfig.ARTIFACT_PLAN_DISPLAY_NAME); HashMap<String, String> artifactPlan3 = new HashMap<>(); artifactPlan3.put(SRC, ""); artifactPlan3.put(DEST, ""); artifactPlan3.put("artifactTypeValue", BuildArtifactConfig.ARTIFACT_PLAN_DISPLAY_NAME); List<HashMap> artifactPlansList = new ArrayList<>(); artifactPlansList.add(artifactPlan1); artifactPlansList.add(artifactPlan3); artifactPlansList.add(artifactPlan2); ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.setConfigAttributes(artifactPlansList); assertThat(artifactConfigs.size(), is(2)); TestArtifactConfig plan = new TestArtifactConfig(); plan.setSource("blah"); plan.setDestination("something"); assertThat(artifactConfigs.get(0), is(plan)); assertThat(artifactConfigs.get(1), is(new BuildArtifactConfig("blah2", "something2"))); }
@Test public void shouldLoadArtifactPlans() { HashMap<String, String> artifactPlan1 = new HashMap<>(); artifactPlan1.put(SRC, "blah"); artifactPlan1.put(DEST, "something"); artifactPlan1.put("artifactTypeValue", TestArtifactConfig.TEST_PLAN_DISPLAY_NAME); HashMap<String, String> artifactPlan2 = new HashMap<>(); artifactPlan2.put(SRC, "blah2"); artifactPlan2.put(DEST, "something2"); artifactPlan2.put("artifactTypeValue", BuildArtifactConfig.ARTIFACT_PLAN_DISPLAY_NAME); List<HashMap> artifactPlansList = new ArrayList<>(); artifactPlansList.add(artifactPlan1); artifactPlansList.add(artifactPlan2); ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.setConfigAttributes(artifactPlansList); assertThat(artifactConfigs.size(), is(2)); TestArtifactConfig plan = new TestArtifactConfig(); plan.setSource("blah"); plan.setDestination("something"); assertThat(artifactConfigs.get(0), is(plan)); assertThat(artifactConfigs.get(1), is(new BuildArtifactConfig("blah2", "something2"))); }
public ArtifactConfig toArtifactConfig(CRArtifact crArtifact) { switch (crArtifact.getType()) { case build: CRBuiltInArtifact crBuildArtifact = (CRBuiltInArtifact) crArtifact; return new BuildArtifactConfig(crBuildArtifact.getSource(), crBuildArtifact.getDestination()); case test: CRBuiltInArtifact crTestArtifact = (CRBuiltInArtifact) crArtifact; return new TestArtifactConfig(crTestArtifact.getSource(), crTestArtifact.getDestination()); case external: CRPluggableArtifact crPluggableArtifact = (CRPluggableArtifact) crArtifact; Configuration configuration = toConfiguration(crPluggableArtifact.getConfiguration()); ConfigurationProperty[] configProperties = new ConfigurationProperty[configuration.size()]; return new PluggableArtifactConfig(crPluggableArtifact.getId(), crPluggableArtifact.getStoreId(), configuration.toArray(configProperties)); default: throw new RuntimeException(String.format("Unsupported CR Artifact Type: %s.", crArtifact.getType())); } }
public static JobConfig createJobConfigWithResourceAndArtifactPlans() { return new JobConfig(new CaseInsensitiveString("defaultJob"), new ResourceConfigs(new ResourceConfig("Linux"), new ResourceConfig("Java")), new ArtifactConfigs(Arrays.asList(new BuildArtifactConfig("src", "dest")))); }