Search in sources :

Example 11 with GoConfigMother

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

Example 12 with GoConfigMother

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

Example 13 with GoConfigMother

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")));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 14 with GoConfigMother

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}")));
}
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 15 with GoConfigMother

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));
}
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)

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