@Test public void shouldUpdateEnvironmentVariablesWhenSourceIsEditable() { BasicEnvironmentConfig uatLocalPart = new BasicEnvironmentConfig(new CaseInsensitiveString("UAT")); uatLocalPart.setOrigins(new FileConfigOrigin()); BasicEnvironmentConfig uatRemotePart = new BasicEnvironmentConfig(new CaseInsensitiveString("UAT")); uatRemotePart.setOrigins(new RepoConfigOrigin()); uatLocalPart.addEnvironmentVariable("hello", "world"); environmentConfig = new MergeEnvironmentConfig(uatLocalPart, uatRemotePart); environmentConfig.setConfigAttributes(new SingletonMap(BasicEnvironmentConfig.VARIABLES_FIELD, Arrays.asList(envVar("foo", "bar"), envVar("baz", "quux"),envVar("hello", "you")))); assertThat(environmentConfig.getVariables(), hasItem(new EnvironmentVariableConfig("hello", "you"))); assertThat(environmentConfig.getVariables(), hasItem(new EnvironmentVariableConfig("foo", "bar"))); assertThat(environmentConfig.getVariables(), hasItem(new EnvironmentVariableConfig("baz", "quux"))); assertThat(environmentConfig.getVariables().size(), is(3)); assertThat("ChangesShouldBeInLocalConfig",uatLocalPart.getVariables(), hasItem(new EnvironmentVariableConfig("hello", "you"))); assertThat("ChangesShouldBeInLocalConfig",uatLocalPart.getVariables(), hasItem(new EnvironmentVariableConfig("foo", "bar"))); assertThat("ChangesShouldBeInLocalConfig",uatLocalPart.getVariables(), hasItem(new EnvironmentVariableConfig("baz", "quux"))); assertThat("ChangesShouldBeInLocalConfig",uatLocalPart.getVariables().size(), is(3)); }
private void addTable(final TableStats table, final Set<TableColumn> dv) { final MultiMap<TableColumn, ScoreBonus> columnMap = new MultiMap<TableColumn, ScoreBonus>( new LinkedHashMapFactory<TableColumn, Collection<ScoreBonus>>(), new HashSetFactory<ScoreBonus>() ); for (final TableColumn column : dv) { columnMap.putAll(column, AiTemplateBuilder.getBonusesForColumn(column, this.isSafeMode())); } this.table = new SingletonMap(table, columnMap); }
@Test public void shouldSetFilterToNullWhenBlank() { material.setFilter(new Filter(new IgnoredFiles("*.*"))); material.setConfigAttributes(new SingletonMap(ScmMaterialConfig.FILTER, "")); assertThat(material.filter(), is(new Filter())); assertThat(material.getFilterAsString(), is("")); }
@Test public void shouldSetFolderToNullWhenBlank() { material.setConfigAttributes(Collections.singletonMap(FOLDER, "foo")); assertThat(material.getFolder(), is(not(nullValue()))); material.setConfigAttributes(new SingletonMap(FOLDER, "")); assertThat(material.getFolder(), is(nullValue())); }
@Test public void shouldUpdateAutoUpdateFieldFromConfigAttributes() { material.setConfigAttributes(new SingletonMap(AUTO_UPDATE, "false")); assertThat(material.isAutoUpdate(), is(false)); material.setConfigAttributes(new SingletonMap(AUTO_UPDATE, null)); assertThat(material.isAutoUpdate(), is(false)); material.setConfigAttributes(new SingletonMap(AUTO_UPDATE, "true")); assertThat(material.isAutoUpdate(), is(true)); material.setConfigAttributes(new HashMap()); assertThat(material.isAutoUpdate(), is(false)); material.setConfigAttributes(new SingletonMap(AUTO_UPDATE, null)); assertThat(material.isAutoUpdate(), is(false)); material.setConfigAttributes(new SingletonMap(AUTO_UPDATE, "random-stuff")); assertThat(material.isAutoUpdate(), is(false)); }
@Test public void shouldUpdateAgents() { environmentConfig.addAgent("uuid-1"); environmentConfig.setConfigAttributes(new SingletonMap(BasicEnvironmentConfig.AGENTS_FIELD, Arrays.asList(new SingletonMap("uuid", "uuid-2"), new SingletonMap("uuid", "uuid-3")))); EnvironmentAgentsConfig expectedAgents = new EnvironmentAgentsConfig(); expectedAgents.add(new EnvironmentAgentConfig("uuid-2")); expectedAgents.add(new EnvironmentAgentConfig("uuid-3")); assertThat(environmentConfig.getAgents(), is(expectedAgents)); }
@Test public void shouldUpdateEnvironmentVariables() { environmentConfig.addEnvironmentVariable("hello", "world"); environmentConfig.setConfigAttributes(new SingletonMap(BasicEnvironmentConfig.VARIABLES_FIELD, Arrays.asList(envVar("foo", "bar"), envVar("baz", "quux")))); assertThat(environmentConfig.getVariables(), hasItem(new EnvironmentVariableConfig("foo", "bar"))); assertThat(environmentConfig.getVariables(), hasItem(new EnvironmentVariableConfig("baz", "quux"))); assertThat(environmentConfig.getVariables().size(), is(2)); }
@Test public void shouldNotSetEnvironmentVariableFromConfigAttributesIfNameAndValueIsEmpty() { environmentConfig.setConfigAttributes(new SingletonMap(BasicEnvironmentConfig.VARIABLES_FIELD, Arrays.asList(envVar("", "anything"), envVar("", "")))); assertThat(environmentConfig.errors().isEmpty(), is(true)); assertThat(environmentConfig.getVariables(), hasItem(new EnvironmentVariableConfig("", "anything"))); assertThat(environmentConfig.getVariables().size(), is(1)); }
@Test public void shouldNotAssignType() throws Exception { Approval approval = new Approval(); approval.setConfigAttributes(new SingletonMap(Approval.TYPE, Approval.SUCCESS)); assertThat(approval.getType(), is(Approval.SUCCESS)); approval.setConfigAttributes(new HashMap()); assertThat(approval.getType(), is(Approval.SUCCESS)); approval.setConfigAttributes(new SingletonMap(Approval.TYPE, Approval.MANUAL)); assertThat(approval.getType(), is(Approval.MANUAL)); approval.setConfigAttributes(new HashMap()); assertThat(approval.getType(), is(Approval.MANUAL)); }
@Test public void shouldValidateApprovalType() throws Exception { Approval approval = new Approval(); approval.setConfigAttributes(new SingletonMap(Approval.TYPE, "not-manual-or-success")); assertThat(approval.getType(), is("not-manual-or-success")); approval.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig(), new BasicPipelineConfigs())); assertThat(approval.errors().firstError(), is("You have defined approval type as 'not-manual-or-success'. Approval can only be of the type 'manual' or 'success'.")); }
@Test public void shouldSetPrimitiveAttributes() throws Exception{ StageConfig config = new StageConfig(); config.setConfigAttributes(new SingletonMap(StageConfig.NAME, "foo_bar")); config.setConfigAttributes(new SingletonMap(StageConfig.FETCH_MATERIALS, "0")); config.setConfigAttributes(new SingletonMap(StageConfig.CLEAN_WORKING_DIR, "1")); assertThat(config.name(), is(new CaseInsensitiveString("foo_bar"))); assertThat(config.isFetchMaterials(), is(false)); assertThat(config.isCleanWorkingDir(), is(true)); }
@Test public void shouldSetArtifactCleanupOptOutAttribute() throws Exception{ StageConfig config = new StageConfig(); assertThat(config.isArtifactCleanupProhibited(), is(false)); config.setConfigAttributes(new SingletonMap(StageConfig.ARTIFACT_CLEANUP_PROHIBITED, "1")); assertThat(config.isArtifactCleanupProhibited(), is(true)); config.setConfigAttributes(new HashMap()); assertThat(config.isArtifactCleanupProhibited(), is(true)); config.setConfigAttributes(new SingletonMap(StageConfig.ARTIFACT_CLEANUP_PROHIBITED, "0")); assertThat(config.isArtifactCleanupProhibited(), is(false)); }
@Test public void shouldSetApprovalFromConfigAttrs() throws Exception{ StageConfig config = new StageConfig(); config.setConfigAttributes(new SingletonMap(StageConfig.APPROVAL, new SingletonMap(Approval.TYPE, Approval.MANUAL))); assertThat(config.getApproval().getType(), is(Approval.MANUAL)); config.setConfigAttributes(new HashMap()); assertThat(config.getApproval().getType(), is(Approval.MANUAL)); config.setConfigAttributes(new SingletonMap(StageConfig.APPROVAL, new SingletonMap(Approval.TYPE, Approval.SUCCESS))); assertThat(config.getApproval().getType(), is(Approval.SUCCESS)); config.setConfigAttributes(new HashMap()); assertThat(config.getApproval().getType(), is(Approval.SUCCESS)); }
@Test public void shouldSetMingleConfigFromConfigAttributes() { MingleConfig mingleConfig = new MingleConfig(); Map configMap = new HashMap(); configMap.put(MingleConfig.BASE_URL, "http://mingle01.tw.com/mingle"); configMap.put(MingleConfig.PROJECT_IDENTIFIER, "go"); configMap.put(MingleConfig.MQL_GROUPING_CONDITIONS, new SingletonMap(MqlCriteria.MQL, "Some MQL")); mingleConfig.setConfigAttributes(configMap); assertThat(mingleConfig.getBaseUrl(), is("http://mingle01.tw.com/mingle")); assertThat(mingleConfig.getProjectIdentifier(), is("go")); assertThat(mingleConfig.getMqlCriteria().getMql(), is("Some MQL")); }
@Test public void shouldUpdatePipelines() { environmentConfig.addPipeline(new CaseInsensitiveString("baz")); environmentConfig.setConfigAttributes(new SingletonMap(BasicEnvironmentConfig.PIPELINES_FIELD, Arrays.asList(new SingletonMap("name", "foo"), new SingletonMap("name", "bar")))); assertThat(environmentConfig.getPipelineNames(), is(Arrays.asList(new CaseInsensitiveString("foo"), new CaseInsensitiveString("bar")))); }
@Test public void shouldUpdateName() { environmentConfig.setConfigAttributes(new SingletonMap(BasicEnvironmentConfig.NAME_FIELD, "PROD")); assertThat(environmentConfig.name(), is(new CaseInsensitiveString("PROD"))); }