Search in sources :

Example 36 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class PipelineConfigValidationTest method setup.

@Before
public void setup() {
    config = GoConfigMother.configWithPipelines("pipeline1", "pipeline2", "pipeline3", "go");
    pipeline = config.pipelineConfigByName(new CaseInsensitiveString("go"));
    goConfigMother = new GoConfigMother();
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

Example 37 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class ConfigMaterialUpdaterIntegrationTest method shouldCheckoutChangedInExistingMaterial.

@Test
public void shouldCheckoutChangedInExistingMaterial() throws Exception {
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush("pipe1.gocd.xml", pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    configTestRepo.addPipelineToRepositoryAndPush("pipe2.gocd.xml", pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    File flyweightDir = materialRepository.folderFor(material);
    Assert.assertThat(flyweightDir.exists(), is(true));
    Assert.assertThat(new File(flyweightDir, "pipe1.gocd.xml").exists(), is(true));
    Assert.assertThat("shouldContainFilesAddedLater", new File(flyweightDir, "pipe2.gocd.xml").exists(), is(true));
}
Also used : File(java.io.File) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother)

Example 38 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class TemplateConfigServiceTest method shouldReturnASubsetOfTemplatesWithAssociatedPipelinesForGroupAdmin.

@Test
public void shouldReturnASubsetOfTemplatesWithAssociatedPipelinesForGroupAdmin() {
    BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
    CaseInsensitiveString groupAdmin = new CaseInsensitiveString("group-admin");
    new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
    // defaultGroup is set in GoConfigMother
    PipelineConfigs pipelineConfigs = cruiseConfig.findGroup("defaultGroup");
    pipelineConfigs.setAuthorization(new Authorization(new AdminsConfig(new AdminUser(groupAdmin))));
    Username groupAdminUser = new Username(groupAdmin);
    when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
    when(goConfigService.isPipelineEditable(new CaseInsensitiveString("p1"))).thenReturn(true);
    when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t1"), groupAdminUser)).thenReturn(true);
    List<TemplateToPipelines> templateToPipelines = new ArrayList<>();
    TemplateToPipelines t1 = new TemplateToPipelines(new CaseInsensitiveString("t1"), false, false);
    t1.add(new PipelineEditabilityInfo(new CaseInsensitiveString("p1"), true, true));
    templateToPipelines.add(t1);
    assertThat(service.getTemplatesList(groupAdminUser), is(templateToPipelines));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 39 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class TemplateConfigServiceTest method shouldReturnASubsetOfTemplatesToPipelinesMapForTemplateAdmin.

@Test
public void shouldReturnASubsetOfTemplatesToPipelinesMapForTemplateAdmin() {
    BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
    CaseInsensitiveString templateAdmin = new CaseInsensitiveString("template-admin");
    new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
    PipelineTemplateConfig template2 = PipelineTemplateConfigMother.createTemplate("t2", new Authorization(new AdminsConfig(new AdminUser(templateAdmin))), StageConfigMother.manualStage("foo"));
    cruiseConfig.addTemplate(template2);
    Username admin = new Username(templateAdmin);
    when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
    when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t2"), admin)).thenReturn(true);
    Map<CaseInsensitiveString, List<CaseInsensitiveString>> templatesWithAssociatedPipelinesForUser = new HashMap<>();
    templatesWithAssociatedPipelinesForUser.put(new CaseInsensitiveString("t2"), new ArrayList<>());
    assertThat(service.templatesWithPipelinesForUser(templateAdmin), is(templatesWithAssociatedPipelinesForUser));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 40 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class TemplateConfigServiceTest method shouldReturnASubsetOfTemplatesToPipelinesMapForGroupAdmin.

@Test
public void shouldReturnASubsetOfTemplatesToPipelinesMapForGroupAdmin() {
    BasicCruiseConfig cruiseConfig = getCruiseConfigWithSecurityEnabled();
    CaseInsensitiveString groupAdmin = new CaseInsensitiveString("group-admin");
    new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
    // defaultGroup is set in GoConfigMother
    PipelineConfigs pipelineConfigs = cruiseConfig.findGroup("defaultGroup");
    pipelineConfigs.setAuthorization(new Authorization(new AdminsConfig(new AdminUser(groupAdmin))));
    PipelineTemplateConfig template2 = PipelineTemplateConfigMother.createTemplate("t2", StageConfigMother.manualStage("foo"));
    cruiseConfig.addTemplate(template2);
    Username groupAdminUser = new Username(groupAdmin);
    when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
    when(securityService.isAuthorizedToViewTemplate(new CaseInsensitiveString("t1"), groupAdminUser)).thenReturn(true);
    when(securityService.isAuthorizedToEditTemplate(new CaseInsensitiveString("t2"), groupAdminUser)).thenReturn(false);
    when(securityService.isUserAdmin(groupAdminUser)).thenReturn(false);
    Map<CaseInsensitiveString, List<CaseInsensitiveString>> templatesWithAssociatedPipelinesForUser = new HashMap<>();
    templatesWithAssociatedPipelinesForUser.put(new CaseInsensitiveString("t1"), new ArrayList<>());
    templatesWithAssociatedPipelinesForUser.get(new CaseInsensitiveString("t1")).add(new CaseInsensitiveString("p1"));
    assertThat(service.templatesWithPipelinesForUser(groupAdmin), is(templatesWithAssociatedPipelinesForUser));
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Username(com.thoughtworks.go.server.domain.Username) 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