public void setConfigAttributes(Object attributes) { setConfigAttributes(attributes, null); }
public static PipelineConfig renamePipeline(PipelineConfig oldConfig, String newPipelineName) { PipelineConfig newConfig = new Cloner().deepClone(oldConfig); HashMap attributes = new HashMap(); attributes.put(PipelineConfig.NAME, newPipelineName); newConfig.setConfigAttributes(attributes); return newConfig; }
@Test public void shouldNotPopulateParamsFromAttributeMapIfConfigurationTypeIsStages() { PipelineConfig pipelineConfig = new PipelineConfig(); HashMap map = new HashMap(); HashMap valueHashMap = new HashMap(); valueHashMap.put("param-name", "FOO"); valueHashMap.put("param-value", "BAR"); map.put(PipelineConfig.PARAMS, valueHashMap); map.put(PipelineConfig.CONFIGURATION_TYPE, PipelineConfig.CONFIGURATION_TYPE_STAGES); pipelineConfig.setParams(mockParamsConfig); pipelineConfig.setConfigAttributes(map); verify(mockParamsConfig, never()).setConfigAttributes(valueHashMap); }
@Test public void shouldPopulateParamsFromAttributeMapWhenConfigurationTypeIsNotSet() { PipelineConfig pipelineConfig = new PipelineConfig(); final HashMap map = new HashMap(); final HashMap valueHashMap = new HashMap(); valueHashMap.put("param-name", "FOO"); valueHashMap.put("param-value", "BAR"); map.put(PipelineConfig.PARAMS, valueHashMap); pipelineConfig.setParams(mockParamsConfig); pipelineConfig.setConfigAttributes(map); verify(mockParamsConfig).setConfigAttributes(valueHashMap); }
@Test public void shouldPopulateEnvironmentVariablesFromAttributeMap() { PipelineConfig pipelineConfig = new PipelineConfig(); HashMap map = new HashMap(); HashMap valueHashMap = new HashMap(); valueHashMap.put("name", "FOO"); valueHashMap.put("value", "BAR"); map.put(PipelineConfig.ENVIRONMENT_VARIABLES, valueHashMap); pipelineConfig.setVariables(mockEnvironmentVariablesConfig); pipelineConfig.setConfigAttributes(map); verify(mockEnvironmentVariablesConfig).setConfigAttributes(valueHashMap); }
@Test public void shouldPopulateParamsFromAttributeMapIfConfigurationTypeIsTemplate() { PipelineConfig pipelineConfig = new PipelineConfig(); HashMap map = new HashMap(); HashMap valueHashMap = new HashMap(); valueHashMap.put("param-name", "FOO"); valueHashMap.put("param-value", "BAR"); map.put(PipelineConfig.PARAMS, valueHashMap); map.put(PipelineConfig.CONFIGURATION_TYPE, PipelineConfig.CONFIGURATION_TYPE_TEMPLATE); map.put(PipelineConfig.TEMPLATE_NAME, "template"); pipelineConfig.setParams(mockParamsConfig); pipelineConfig.setConfigAttributes(map); verify(mockParamsConfig).setConfigAttributes(valueHashMap); }
@Test public void shouldSetLockStatusOnPipelineConfigWhenValueIsLockOnFailure() { Map configMap = new HashMap(); configMap.put(PipelineConfig.LOCK_BEHAVIOR, PipelineConfig.LOCK_VALUE_LOCK_ON_FAILURE); PipelineConfig pipelineConfig = new PipelineConfig(); pipelineConfig.setConfigAttributes(configMap); assertThat(pipelineConfig.isLockable(), is(true)); }
@Test public void shouldSetLabelTemplateToDefaultValueIfBlankIsEnteredWhileSettingConfigAttributes() { PipelineConfig pipelineConfig = new PipelineConfig(); Map configMap = new HashMap(); configMap.put(PipelineConfig.LABEL_TEMPLATE, ""); pipelineConfig.setConfigAttributes(configMap); assertThat(pipelineConfig.getLabelTemplate(), is(PipelineLabel.COUNT_TEMPLATE)); }
@Test public void shouldNotSetLockStatusOnPipelineConfigWhenValueIsNone() { Map configMap = new HashMap(); configMap.put(PipelineConfig.LOCK_BEHAVIOR, PipelineConfig.LOCK_VALUE_NONE); PipelineConfig pipelineConfig = new PipelineConfig(); pipelineConfig.setConfigAttributes(configMap); assertThat(pipelineConfig.isLockable(), is(false)); }
@Test public void shouldSetLockStatusOnPipelineConfigWhenValueIsUnlockWhenFinished() { Map configMap = new HashMap(); configMap.put(PipelineConfig.LOCK_BEHAVIOR, PipelineConfig.LOCK_VALUE_UNLOCK_WHEN_FINISHED); PipelineConfig pipelineConfig = new PipelineConfig(); pipelineConfig.setConfigAttributes(configMap); assertThat(pipelineConfig.isPipelineUnlockableWhenFinished(), is(true)); }
@Test public void shouldUseTemplateWhenSetConfigAttributesContainsTemplateName() { PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline"); assertThat(pipelineConfig.hasTemplate(), is(false)); Map map = new HashMap(); map.put(PipelineConfig.CONFIGURATION_TYPE, PipelineConfig.CONFIGURATION_TYPE_TEMPLATE); map.put(PipelineConfig.TEMPLATE_NAME, "foo-template"); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.getConfigurationType(), is(PipelineConfig.CONFIGURATION_TYPE_TEMPLATE)); assertThat(pipelineConfig.getTemplateName(), is(new CaseInsensitiveString("foo-template"))); }
@Test public void shouldResetTrackingToolWhenIntegrationTypeIsNone() { PipelineConfig pipelineConfig = new PipelineConfig(); pipelineConfig.setTrackingTool(new TrackingTool("link", "regex")); Map map = new HashMap(); map.put(PipelineConfig.INTEGRATION_TYPE, PipelineConfig.INTEGRATION_TYPE_NONE); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.getTrackingTool(), is(nullValue())); assertThat(pipelineConfig.getIntegrationType(), is(PipelineConfig.INTEGRATION_TYPE_NONE)); }
@Test public void shouldPopulateTrackingToolWhenIntegrationTypeIsTrackingToolAndLinkAndRegexAreDefined() { PipelineConfig pipelineConfig = new PipelineConfig(); pipelineConfig.setMingleConfig(new MingleConfig("baseUri", "go")); HashMap map = new HashMap(); HashMap valueHashMap = new HashMap(); valueHashMap.put("link", "GoleyLink"); valueHashMap.put("regex", "GoleyRegex"); map.put(PipelineConfig.TRACKING_TOOL, valueHashMap); map.put(PipelineConfig.INTEGRATION_TYPE, PipelineConfig.INTEGRATION_TYPE_TRACKING_TOOL); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.getTrackingTool(), is(new TrackingTool("GoleyLink", "GoleyRegex"))); assertThat(pipelineConfig.getMingleConfig(), is(new MingleConfig())); assertThat(pipelineConfig.getIntegrationType(), is(PipelineConfig.INTEGRATION_TYPE_TRACKING_TOOL)); }
@Test public void shouldResetMingleConfigWhenIntegrationTypeIsNone() { PipelineConfig pipelineConfig = new PipelineConfig(); pipelineConfig.setMingleConfig(new MingleConfig("baseUri", "go")); Map map = new HashMap(); map.put(PipelineConfig.INTEGRATION_TYPE, PipelineConfig.INTEGRATION_TYPE_NONE); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.getMingleConfig(), is(new MingleConfig())); assertThat(pipelineConfig.getIntegrationType(), is(PipelineConfig.INTEGRATION_TYPE_NONE)); }
@Test public void shouldValidateLockBehaviorValues() throws Exception { Map configMap = new HashMap(); configMap.put(PipelineConfig.LOCK_BEHAVIOR, "someRandomValue"); PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline1"); pipelineConfig.setConfigAttributes(configMap); pipelineConfig.validate(null); assertThat(pipelineConfig.errors().isEmpty(), is(false)); assertThat(pipelineConfig.errors().on(PipelineConfig.LOCK_BEHAVIOR), containsString("Lock behavior has an invalid value (someRandomValue). Valid values are: ")); }
@Test public void shouldAssignApprovalTypeOnFirstStageAsAuto() throws Exception { Map approvalAttributes = Collections.singletonMap(Approval.TYPE, Approval.SUCCESS); Map<String, Map> map = Collections.singletonMap(StageConfig.APPROVAL, approvalAttributes); PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("p1", "s1", "j1"); pipelineConfig.get(0).updateApproval(Approval.manualApproval()); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.get(0).getApproval().getType(), is(Approval.SUCCESS)); }
@Test public void shouldAssignApprovalTypeOnFirstStageAsManual() throws Exception { Map approvalAttributes = Collections.singletonMap(Approval.TYPE, Approval.MANUAL); Map<String, Map> map = Collections.singletonMap(StageConfig.APPROVAL, approvalAttributes); PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("p1", "s1", "j1"); pipelineConfig.get(0).updateApproval(Approval.manualApproval()); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.get(0).getApproval().getType(), is(Approval.MANUAL)); }
@Test public void shouldUpdateStageOnAttributes() { PipelineConfig pipelineConfig = new PipelineConfig(); HashMap stageMap = new HashMap(); List jobList = a(m(JobConfig.NAME, "JobName")); stageMap.put(StageConfig.NAME, "someStage"); stageMap.put(StageConfig.JOBS, jobList); HashMap attributeMap = new HashMap(); attributeMap.put(PipelineConfig.NAME, "startup"); attributeMap.put(PipelineConfig.STAGE, stageMap); pipelineConfig.setConfigAttributes(attributeMap); assertThat(pipelineConfig.name(), is(new CaseInsensitiveString("startup"))); assertThat(pipelineConfig.get(0).name(), is(new CaseInsensitiveString("someStage"))); assertThat(pipelineConfig.get(0).getJobs().first().name(), is(new CaseInsensitiveString("JobName"))); }
@Test public void shouldAssignApprovalTypeOnFirstStageAsManualAndRestOfStagesAsUntouched() throws Exception { Map approvalAttributes = Collections.singletonMap(Approval.TYPE, Approval.MANUAL); Map<String, Map> map = Collections.singletonMap(StageConfig.APPROVAL, approvalAttributes); PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("p1", StageConfigMother.custom("s1", Approval.automaticApproval()), StageConfigMother.custom("s2", Approval.automaticApproval())); pipelineConfig.setConfigAttributes(map); assertThat(pipelineConfig.get(0).getApproval().getType(), is(Approval.MANUAL)); assertThat(pipelineConfig.get(1).getApproval().getType(), is(Approval.SUCCESS)); }
@Test public void shouldRemoveExistingStagesWhileDoingAStageUpdate() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("foo"), new MaterialConfigs(), new StageConfig(new CaseInsensitiveString("first"), new JobConfigs()), new StageConfig( new CaseInsensitiveString("second"), new JobConfigs())); HashMap stageMap = new HashMap(); List jobList = a(m(JobConfig.NAME, "JobName")); stageMap.put(StageConfig.NAME, "someStage"); stageMap.put(StageConfig.JOBS, jobList); HashMap attributeMap = new HashMap(); attributeMap.put(PipelineConfig.NAME, "startup"); attributeMap.put(PipelineConfig.STAGE, stageMap); pipelineConfig.setConfigAttributes(attributeMap); assertThat(pipelineConfig.name(), is(new CaseInsensitiveString("startup"))); assertThat(pipelineConfig.size(), is(1)); assertThat(pipelineConfig.get(0).name(), is(new CaseInsensitiveString("someStage"))); assertThat(pipelineConfig.get(0).getJobs().first().name(), is(new CaseInsensitiveString("JobName"))); }