Search in sources :

Example 6 with GoConfigMother

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);
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother)

Example 7 with GoConfigMother

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));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 8 with GoConfigMother

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"));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 9 with GoConfigMother

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)));
    }
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) JDOMParseException(org.jdom2.input.JDOMParseException) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 10 with GoConfigMother

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)));
    }
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) JDOMParseException(org.jdom2.input.JDOMParseException) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)80 Test (org.junit.Test)48 Username (com.thoughtworks.go.server.domain.Username)33 Before (org.junit.Before)25 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)18 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)17 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)8 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 File (java.io.File)6 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)5 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 BasicEnvironmentConfig (com.thoughtworks.go.config.BasicEnvironmentConfig)3 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)3 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)3