Search in sources :

Example 21 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline.

@Test
public void findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_name")).thenReturn(false);
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    StageSummaryModel model = service.findStageSummaryByIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"), ALWAYS_ALLOW_USER, result);
    assertThat(result.httpCode(), is(401));
    assertThat(model, is(nullValue()));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) Test(org.junit.Test)

Example 22 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class TemplateConfigServiceTest method shouldLoadClonedTemplateForEdit.

@Test
public void shouldLoadClonedTemplateForEdit() {
    String templateName = "empty_template";
    CaseInsensitiveString templateAdminUser = new CaseInsensitiveString("templateAdminUser");
    Username templateUser = new Username(templateAdminUser);
    PipelineTemplateConfig emptyTemplate = PipelineTemplateConfigMother.createTemplate(templateName, new Authorization(new AdminsConfig(new AdminUser(templateAdminUser))), StageConfigMother.stageConfig("some_stage"));
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.addTemplate(emptyTemplate);
    when(securityService.isAuthorizedToEditTemplate(templateName, templateUser)).thenReturn(true);
    when(goConfigService.getConfigHolder()).thenReturn(new GoConfigHolder(cruiseConfig, cruiseConfig));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigForEdit<PipelineTemplateConfig> configForEdit = service.loadForEdit(templateName, templateUser, result);
    assertThat(configForEdit, is(not(nullValue())));
    CaseInsensitiveString empty_template = new CaseInsensitiveString(templateName);
    assertThat(configForEdit.getConfig().name(), is(empty_template));
    PipelineTemplateConfig template = configForEdit.getConfig();
    PipelineTemplateConfig templateForEdit = configForEdit.getCruiseConfig().findTemplate(empty_template);
    PipelineTemplateConfig processedTemplate = configForEdit.getProcessedConfig().findTemplate(empty_template);
    PipelineTemplateConfig serversTemplate = cruiseConfig.findTemplate(empty_template);
    //modify the server's copy
    serversTemplate.add(new StageConfig(new CaseInsensitiveString("stage-one"), new JobConfigs(new JobConfig("job"))));
    assertThat(serversTemplate.size(), is(2));
    //given copy should remain unmodified
    assertThat(template.size(), is(1));
    assertThat(templateForEdit.size(), is(1));
    assertThat(processedTemplate.size(), is(1));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 23 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class TemplateConfigServiceTest method shouldDeleteATemplateWithAGivenName.

@Test
public void shouldDeleteATemplateWithAGivenName() {
    PipelineTemplateConfig emptyTemplate = template("empty_template");
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.addTemplate(emptyTemplate);
    service.removeTemplate("empty_template", cruiseConfig, "md5", new HttpLocalizedOperationResult());
    verify(goConfigService).updateConfig(new DeleteTemplateCommand("empty_template", "md5"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 24 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class TemplateConfigServiceTest method shouldErrorOutIfTemplateIsNotFound.

@Test
public void shouldErrorOutIfTemplateIsNotFound() {
    PipelineTemplateConfig emptyTemplate = template("empty_template");
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.addTemplate(emptyTemplate);
    when(securityService.isAuthorizedToEditTemplate(anyString(), any(Username.class))).thenReturn(true);
    when(goConfigService.getConfigHolder()).thenReturn(new GoConfigHolder(cruiseConfig, cruiseConfig));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigForEdit<PipelineTemplateConfig> configForEdit = service.loadForEdit("blah", new Username(new CaseInsensitiveString("someuser")), result);
    assertThat(configForEdit, is(nullValue()));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(404));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 25 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class TemplateConfigServiceTest method shouldPopulateErrorInResultOnFailure.

@Test
public void shouldPopulateErrorInResultOnFailure() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    String templateName = "template-name";
    PipelineTemplateConfig pipelineTemplateConfig = new PipelineTemplateConfig(new CaseInsensitiveString(templateName), StageConfigMother.oneBuildPlanWithResourcesAndMaterials("stage", "job"));
    String errorMessage = "invalid template";
    doThrow(new GoConfigInvalidException(new GoConfigMother().defaultCruiseConfig(), errorMessage)).when(goConfigService).updateConfig(any(CreateTemplateConfigCommand.class), any(Username.class));
    service.createTemplateConfig(user, pipelineTemplateConfig, result);
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.unprocessableEntity(LocalizedMessage.string("ENTITY_CONFIG_VALIDATION_FAILED", "template", templateName, errorMessage));
    assertThat(result.toString(), is(expectedResult.toString()));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) CreateTemplateConfigCommand(com.thoughtworks.go.config.update.CreateTemplateConfigCommand) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)361 Test (org.junit.Test)329 Username (com.thoughtworks.go.server.domain.Username)131 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)36 Pipeline (com.thoughtworks.go.domain.Pipeline)27 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)22 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)17 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)15 GoCipher (com.thoughtworks.go.security.GoCipher)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)13 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)12