use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnTrueIfUserIsTheAdminForGroup.
@Test
public void shouldReturnTrueIfUserIsTheAdminForGroup() {
CaseInsensitiveString adminName = new CaseInsensitiveString("admin");
String groupName = String.format("group_%s", UUID.randomUUID());
GoConfigMother mother = new GoConfigMother();
mother.enableSecurityWithPasswordFilePlugin(cruiseConfig);
cruiseConfig.server().security().adminsConfig().add(new AdminUser(adminName));
mother.addPipelineWithGroup(cruiseConfig, groupName, "pipeline", "stage");
mother.addAdminUserForPipelineGroup(cruiseConfig, "user", groupName);
assertThat(goConfigService.isUserAdminOfGroup(new CaseInsensitiveString("user"), groupName), is(true));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldFindGroupByPipelineName.
@Test
public void shouldFindGroupByPipelineName() throws Exception {
GoConfigMother configMother = new GoConfigMother();
BasicCruiseConfig config = GoConfigMother.defaultCruiseConfig();
configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1", "job1");
configMother.addPipelineWithGroup(config, "group1", "pipeline2", "stage1", "job1");
configMother.addPipelineWithGroup(config, "group2", "pipeline3", "stage1", "job1");
expectLoad(config);
assertThat(goConfigService.findGroupByPipeline(new CaseInsensitiveString("pipeline1")).getGroup(), is("group1"));
assertThat(goConfigService.findGroupByPipeline(new CaseInsensitiveString("pipeline2")).getGroup(), is("group1"));
assertThat(goConfigService.findGroupByPipeline(new CaseInsensitiveString("pipeline3")).getGroup(), is("group2"));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldBeAbleToEditAnExistentLocalPipelineWithAdminPrivileges.
@Test
public void shouldBeAbleToEditAnExistentLocalPipelineWithAdminPrivileges() throws Exception {
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
PipelineConfig pipeline = new PipelineConfig();
pipeline.setName("pipeline1");
pipeline.setOrigin(null);
when(goConfigDao.load()).thenReturn(cruiseConfig);
when(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1"))).thenReturn(pipeline);
when(cruiseConfig.getGroups()).thenReturn(new GoConfigMother().cruiseConfigWithOnePipelineGroup().getGroups());
when(cruiseConfig.isAdministrator("admin_user")).thenReturn(true);
assertTrue(goConfigService.canEditPipeline("pipeline1", new Username("admin_user")));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnValidOnUpdateXml.
@Test
public void shouldReturnValidOnUpdateXml() throws Exception {
String groupName = "group_name";
String md5 = "md5";
cruiseConfig = new BasicCruiseConfig();
expectLoad(cruiseConfig);
new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
expectLoadForEditing(cruiseConfig);
when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver(groupName);
String renamedGroupName = "renamed_group_name";
GoConfigValidity validity = partialSaver.saveXml(groupXml(renamedGroupName), md5);
assertThat(validity.isValid(), Matchers.is(true));
assertThat(validity.errorMessage(), Matchers.is(""));
verify(goConfigDao).updateConfig(argThat(cruiseConfigIsUpdatedWith(renamedGroupName, "new_name", "${COUNT}-#{foo}")));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnInvalidWhenPipelineGroupPartialIsInvalid.
@Test
public void shouldReturnInvalidWhenPipelineGroupPartialIsInvalid() throws Exception {
String groupName = "group_name";
String md5 = "md5";
cruiseConfig = new BasicCruiseConfig();
expectLoad(cruiseConfig);
new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
expectLoadForEditing(cruiseConfig);
when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
String pipelineGroupContent = groupXmlWithInvalidElement(groupName);
GoConfigValidity validity = goConfigService.groupSaver(groupName).saveXml(pipelineGroupContent, "md5");
assertThat(validity.isValid(), Matchers.is(false));
assertThat(validity.errorMessage(), containsString("Invalid content was found starting with element 'unknown'"));
verify(goConfigDao, never()).updateConfig(any(UpdateConfigCommand.class));
}
Aggregations