public void setConfigAttributes(Object attributes, TaskFactory taskFactory) { Map attributesMap = (Map) attributes; if (attributesMap.containsKey(NAME)) { String nameString = (String) attributesMap.get(NAME); jobName = nameString == null ? null : new CaseInsensitiveString(nameString); } if (attributesMap.containsKey("elasticProfileId")) { String elasticProfileId = (String) attributesMap.get("elasticProfileId"); setElasticProfileId(StringUtils.isBlank(elasticProfileId) ? null : elasticProfileId); } if (attributesMap.containsKey(TASKS)) { tasks.setConfigAttributes(attributesMap.get(TASKS), taskFactory); } if (attributesMap.containsKey(ENVIRONMENT_VARIABLES)) { variables.setConfigAttributes(attributesMap.get(ENVIRONMENT_VARIABLES)); } if (attributesMap.containsKey(TABS)) { tabs.setConfigAttributes(attributesMap.get(TABS)); } if (attributesMap.containsKey(RESOURCES)) { resourceConfigs.importFromCsv((String) attributesMap.get(RESOURCES)); } if (attributesMap.containsKey(ARTIFACT_CONFIGS)) { artifactConfigs.setConfigAttributes(attributesMap.get(ARTIFACT_CONFIGS)); } setTimeoutAttribute(attributesMap); setJobRunTypeAttribute(attributesMap); }
@Test public void shouldPopulateArtifactPlansFromAttributeMap() { HashMap map = new HashMap(); HashMap valueHashMap = new HashMap(); valueHashMap.put("src", "dest"); valueHashMap.put("src1", "dest1"); map.put(JobConfig.ARTIFACT_CONFIGS, valueHashMap); ArtifactConfigs mockArtifactConfigs = mock(ArtifactConfigs.class); JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job-name"), new ResourceConfigs(), mockArtifactConfigs); jobConfig.setConfigAttributes(map); verify(mockArtifactConfigs).setConfigAttributes(valueHashMap); }
@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 shouldClearAllArtifactsWhenTheMapIsNull() { ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.add(new BuildArtifactConfig("src", "dest")); artifactConfigs.setConfigAttributes(null); assertThat(artifactConfigs.size(), is(0)); }
@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")); }
artifactConfigs.setConfigAttributes(artifactPlansList);