use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class SecurityServiceTest method setUpGroupWithAuthorization.
private void setUpGroupWithAuthorization(CruiseConfig config, Authorization authorization) {
new GoConfigMother().addPipelineWithGroup(config, "group", "pipeline", "stage", "job");
config.getGroups().findGroup("group").setAuthorization(authorization);
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnInvalidWhenPipelineGroupPartialXmlIsInvalid.
@Test
public void shouldReturnInvalidWhenPipelineGroupPartialXmlIsInvalid() 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);
GoConfigValidity validity = goConfigService.groupSaver(groupName).saveXml("<foobar>", "md5");
assertThat(validity.isValid(), Matchers.is(false));
assertThat(validity.errorMessage(), containsString("XML document structures must start and end within the same entity"));
verify(goConfigDao, never()).updateConfig(any(UpdateConfigCommand.class));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldUpdateXmlUsingNewFlowIfEnabled.
@Test
public void shouldUpdateXmlUsingNewFlowIfEnabled() throws Exception {
String groupName = "group_name";
String md5 = "md5";
cruiseConfig = new BasicCruiseConfig();
ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
expectLoad(cruiseConfig);
new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
expectLoadForEditing(cruiseConfig);
when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
when(systemEnvironment.optimizeFullConfigSave()).thenReturn(true);
when(goConfigDao.updateFullConfig(commandArgumentCaptor.capture())).thenReturn(null);
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(""));
CruiseConfig updatedConfig = commandArgumentCaptor.getValue().configForEdit();
PipelineConfigs group = updatedConfig.findGroup(renamedGroupName);
PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("new_name"));
assertThat(pipeline.name(), is(new CaseInsensitiveString("new_name")));
assertThat(pipeline.getLabelTemplate(), is("${COUNT}-#{foo}"));
assertThat(pipeline.materialConfigs().first(), is(IsInstanceOf.instanceOf(SvnMaterialConfig.class)));
assertThat(pipeline.materialConfigs().first().getUriForDisplay(), is("file:///tmp/foo"));
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldThrowExceptionIfGroupDoesNotExist_WhenUserIsNonAdmin.
@Test
public void shouldThrowExceptionIfGroupDoesNotExist_WhenUserIsNonAdmin() {
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));
try {
goConfigService.isUserAdminOfGroup(new CaseInsensitiveString("foo"), groupName);
fail("Should fail since group does not exist");
} catch (Exception e) {
assertThat(e, is(instanceOf(PipelineGroupNotFoundException.class)));
}
}
use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.
the class GoConfigServiceTest method shouldThrowExceptionIfGroupDoesNotExist_WhenUserIsAdmin.
@Test
public void shouldThrowExceptionIfGroupDoesNotExist_WhenUserIsAdmin() {
CaseInsensitiveString adminName = new CaseInsensitiveString("admin");
GoConfigMother mother = new GoConfigMother();
mother.enableSecurityWithPasswordFilePlugin(cruiseConfig);
cruiseConfig.server().security().adminsConfig().add(new AdminUser(adminName));
String groupName = String.format("group_%s", UUID.randomUUID());
try {
goConfigService.isUserAdminOfGroup(adminName, groupName);
fail("Should fail since group does not exist");
} catch (Exception e) {
assertThat(e, is(instanceOf(PipelineGroupNotFoundException.class)));
}
}
Aggregations