@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 shouldValidateTree() { ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.add(new BuildArtifactConfig("src", "../a")); artifactConfigs.validateTree(null); assertThat(artifactConfigs.get(0).errors().on(BuiltinArtifactConfig.DEST), is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(0).errors().on(BuiltinArtifactConfig.SRC), is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(1).errors().on(BuiltinArtifactConfig.DEST), is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(1).errors().on(BuiltinArtifactConfig.SRC), is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(2).errors().on(BuiltinArtifactConfig.DEST), is("Invalid destination path. Destination path should match the pattern " + FilePathTypeValidator.PATH_PATTERN)); }
@Test public void shouldErrorOutWhenDuplicateArtifactConfigExists() { final ArtifactConfigs artifactConfigs = new ArtifactConfigs(new BuildArtifactConfig("src", "dest")); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.validate(null); assertFalse(artifactConfigs.get(0).errors().isEmpty()); assertThat(artifactConfigs.get(0).errors().on(BuiltinArtifactConfig.SRC), Matchers.is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(0).errors().on(BuiltinArtifactConfig.DEST), Matchers.is("Duplicate artifacts defined.")); assertFalse(artifactConfigs.get(1).errors().isEmpty()); assertThat(artifactConfigs.get(1).errors().on(BuiltinArtifactConfig.SRC), Matchers.is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(1).errors().on(BuiltinArtifactConfig.DEST), Matchers.is("Duplicate artifacts defined.")); assertFalse(artifactConfigs.get(2).errors().isEmpty()); assertThat(artifactConfigs.get(2).errors().on(BuiltinArtifactConfig.SRC), Matchers.is("Duplicate artifacts defined.")); assertThat(artifactConfigs.get(2).errors().on(BuiltinArtifactConfig.DEST), Matchers.is("Duplicate artifacts defined.")); }
@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")); }
PluggableArtifactConfig artifactConfig = (PluggableArtifactConfig) artifactConfigs.get(0); assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external)); assertThat(artifactConfig.getId(), is("artifactId"));
@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)); }