@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 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"))); }
@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 shouldLoadBuildPlanFromXmlPartial() throws Exception { String buildXmlPartial = "<job name=\"functional\">\n" + " <artifacts>\n" + " <artifact type=\"build\" src=\"artifact1.xml\" dest=\"cruise-output\" />\n" + " </artifacts>\n" + "</job>"; JobConfig build = xmlLoader.fromXmlPartial(buildXmlPartial, JobConfig.class); assertThat(build.name(), is(new CaseInsensitiveString("functional"))); assertThat(build.artifactConfigs().size(), is(1)); }
@Test public void setConfigAttributes_shouldSetConfigurationAsIsIfPluginIdIsBlank() throws CryptoException { HashMap<Object, Object> imageMap = new HashMap<>(); imageMap.put("value", new GoCipher().encrypt("some-encrypted-value")); imageMap.put("isSecure", "true"); HashMap<Object, Object> tagMap = new HashMap<>(); tagMap.put("value", "18.6.0"); tagMap.put("isSecure", "false"); HashMap<Object, Object> configurationMap1 = new HashMap<>(); configurationMap1.put("Image", imageMap); configurationMap1.put("Tag", tagMap); HashMap<String, Object> artifactPlan1 = new HashMap<>(); artifactPlan1.put("artifactTypeValue", "Pluggable Artifact"); artifactPlan1.put("id", "artifactId"); artifactPlan1.put("storeId", "storeId"); artifactPlan1.put("pluginId", ""); artifactPlan1.put("configuration", configurationMap1); List<Map> artifactPlansList = new ArrayList<>(); artifactPlansList.add(artifactPlan1); ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.setConfigAttributes(artifactPlansList); assertThat(artifactConfigs.size(), is(1)); PluggableArtifactConfig artifactConfig = (PluggableArtifactConfig) artifactConfigs.get(0); assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external)); assertThat(artifactConfig.getId(), is("artifactId")); assertThat(artifactConfig.getStoreId(), is("storeId")); assertThat(artifactConfig.getConfiguration().getProperty("Image").getValue(), is("some-encrypted-value")); assertThat(artifactConfig.getConfiguration().getProperty("Tag").getValue(), is("18.6.0")); }
@Test public void shouldClearAllArtifactsWhenTheMapIsNull() { ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.setConfigAttributes(null); assertThat(artifactConfigs.size(), is(0)); }
artifactConfigs.setConfigAttributes(artifactPlansList); assertThat(artifactConfigs.size(), is(1));
@Test public void shouldLoadAntBuilder() throws Exception { CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(CONFIG_WITH_ANT_BUILDER).config; JobConfig plan = cruiseConfig.jobConfigByName("pipeline1", "mingle", "cardlist", true); assertThat(plan.tasks(), iterableWithSize(1)); AntTask builder = (AntTask) plan.tasks().first(); assertThat(builder.getTarget(), is("all")); final ArtifactConfigs cardListArtifacts = cruiseConfig.jobConfigByName("pipeline1", "mingle", "cardlist", true).artifactConfigs(); assertThat(cardListArtifacts.size(), is(1)); ArtifactConfig artifactConfigPlan = cardListArtifacts.get(0); assertThat(artifactConfigPlan.getArtifactType(), is(ArtifactType.test)); }