public void setConfigAttributes(Object attributes) { setConfigAttributes(attributes, null); }
public static void renameStage(StageConfig stageConfig, String stageName) { HashMap attributes = new HashMap(); attributes.put(StageConfig.NAME, stageName); stageConfig.setConfigAttributes(attributes); } }
clear(); StageConfig stageConfig = new StageConfig(); stageConfig.setConfigAttributes(attributeMap.get(STAGE), taskFactory); add(stageConfig); firstStage.setConfigAttributes(attributeMap);
@Test public void shouldPopulateEnvironmentVariablesFromAttributeMap() { StageConfig stageConfig = new StageConfig(); HashMap map = new HashMap(); HashMap valueHashMap = new HashMap(); valueHashMap.put("name", "FOO"); valueHashMap.put("value", "BAR"); map.put(StageConfig.ENVIRONMENT_VARIABLES, valueHashMap); EnvironmentVariablesConfig mockEnvironmentVariablesConfig = mock(EnvironmentVariablesConfig.class); stageConfig.setVariables(mockEnvironmentVariablesConfig); stageConfig.setConfigAttributes(map); verify(mockEnvironmentVariablesConfig).setConfigAttributes(valueHashMap); }
@Test public void shouldSetPrimitiveAttributes() throws Exception{ StageConfig config = new StageConfig(); config.setConfigAttributes(Collections.singletonMap(StageConfig.NAME, "foo_bar")); config.setConfigAttributes(Collections.singletonMap(StageConfig.FETCH_MATERIALS, "0")); config.setConfigAttributes(Collections.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(Collections.singletonMap(StageConfig.ARTIFACT_CLEANUP_PROHIBITED, "1")); assertThat(config.isArtifactCleanupProhibited(), is(true)); config.setConfigAttributes(new HashMap()); assertThat(config.isArtifactCleanupProhibited(), is(true)); config.setConfigAttributes(Collections.singletonMap(StageConfig.ARTIFACT_CLEANUP_PROHIBITED, "0")); assertThat(config.isArtifactCleanupProhibited(), is(false)); }
@Test public void shouldSetApprovalFromConfigAttrs() throws Exception{ StageConfig config = new StageConfig(); config.setConfigAttributes(Collections.singletonMap(StageConfig.APPROVAL, Collections.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(Collections.singletonMap(StageConfig.APPROVAL, Collections.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 shouldRemoveStageLevelAuthorizationWhenInheritingPermissionsFromGroup() { StageConfig config = new StageConfig(); StageConfigMother.addApprovalWithRoles(config, "role1"); StageConfigMother.addApprovalWithUsers(config, "user1"); HashMap map = new HashMap(); List operateUsers = new ArrayList(); operateUsers.add(nameMap("user1")); map.put(StageConfig.OPERATE_USERS, operateUsers); List operateRoles = new ArrayList(); operateRoles.add(nameMap("role1")); map.put(StageConfig.OPERATE_ROLES, operateRoles); map.put(StageConfig.SECURITY_MODE, "inherit"); config.setConfigAttributes(map); assertThat(config.getApproval().getAuthConfig().isEmpty(), is(true)); }
@Test public void shouldSetOperateRoles() { StageConfig config = new StageConfig(); HashMap map = new HashMap(); List operateRoles = new ArrayList(); operateRoles.add(nameMap("role1")); operateRoles.add(nameMap("role1")); operateRoles.add(nameMap("role2")); map.put(StageConfig.OPERATE_ROLES, operateRoles); map.put(StageConfig.OPERATE_USERS, new ArrayList()); map.put(StageConfig.SECURITY_MODE, "define"); config.setConfigAttributes(map); assertThat(config.getOperateRoles().size(), is(2)); assertThat(config.getOperateRoles(), hasItem(new AdminRole(new CaseInsensitiveString("role1")))); assertThat(config.getOperateRoles(), hasItem(new AdminRole(new CaseInsensitiveString("role2")))); }
@Test public void shouldSetOperateUsers() { StageConfig config = new StageConfig(); HashMap map = new HashMap(); List operateUsers = new ArrayList(); operateUsers.add(nameMap("user1")); operateUsers.add(nameMap("user1")); operateUsers.add(nameMap("user2")); map.put(StageConfig.OPERATE_USERS, operateUsers); map.put(StageConfig.OPERATE_ROLES, new ArrayList()); map.put(StageConfig.SECURITY_MODE, "define"); config.setConfigAttributes(map); assertThat(config.getOperateUsers().size(), is(2)); assertThat(config.getOperateUsers(), hasItem(new AdminUser(new CaseInsensitiveString("user1")))); assertThat(config.getOperateUsers(), hasItem(new AdminUser(new CaseInsensitiveString("user2")))); }
@Test public void shouldPickupJobConfigDetailsFromAttributeMap() throws Exception{ StageConfig config = new StageConfig(); Map stageAttrs = m(StageConfig.JOBS, a(m(JobConfig.NAME, "con-job"), m(JobConfig.NAME, "boring-job"))); config.setConfigAttributes(stageAttrs); assertThat(config.getJobs().get(0).name(), is(new CaseInsensitiveString("con-job"))); assertThat(config.getJobs().get(1).name(), is(new CaseInsensitiveString("boring-job"))); }