Search in sources :

Example 6 with UpdateConfigFromUI

use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository.

@Test
public void shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository() throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    when(securityService.canViewAdminPage(username)).thenReturn(false);
    UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand(new PackageRepository(), username);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    updateCommand.checkPermission(GoConfigMother.configWithPipelines("sample"), result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(401));
    verify(securityService).canViewAdminPage(username);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 7 with UpdateConfigFromUI

use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldRespondWithNewConfigWhenSavedSuccessfully.

@Test
public void shouldRespondWithNewConfigWhenSavedSuccessfully() {
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    UpdateConfigFromUI pipelineAndStageRename = new PipelineStageRenamingCommand();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    PipelineConfig pipeline = goConfigService.getConfigForEditing().pipelineConfigByName(new CaseInsensitiveString("new-pipeline"));
    StageConfig stage = pipeline.getStage(new CaseInsensitiveString("new-stage"));
    assertThat(pipeline, not(nullValue()));
    assertThat(stage, not(nullValue()));
    assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("new-pipeline")));
    assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("new-stage")));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("new-pipeline"), new CaseInsensitiveString("new-stage"), false), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Matchers.containsString(org.hamcrest.Matchers.containsString) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 8 with UpdateConfigFromUI

use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldRespondWithModifiedConfigWhenSaveFailsBecauseOfValidationErrors.

@Test
public void shouldRespondWithModifiedConfigWhenSaveFailsBecauseOfValidationErrors() {
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    UpdateConfigFromUI pipelineAndStageRename = new PipelineStageRenamingCommand() {

        {
            newPipelineName = "pipeline!@foo - bar";
        }
    };
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline!@foo - bar")), is(false));
    assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline")), is(true));
    assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("pipeline!@foo - bar")));
    assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("new-stage")));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline!@foo - bar"), new CaseInsensitiveString("new-stage"), false), is(false));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Matchers.containsString(org.hamcrest.Matchers.containsString) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 9 with UpdateConfigFromUI

use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldSavePackageRepositoryAndReturnSuccess.

@Test
public void shouldSavePackageRepositoryAndReturnSuccess() throws Exception {
    service = spy(service);
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setId("repoid");
    Username username = new Username(new CaseInsensitiveString("user"));
    UpdateConfigFromUI updateConfigFromUI = mock(UpdateConfigFromUI.class);
    doNothing().when(service).performPluginValidationsFor(packageRepository);
    doReturn(updateConfigFromUI).when(service).getPackageRepositoryUpdateCommand(packageRepository, username);
    when(goConfigService.updateConfigFromUI(eq(updateConfigFromUI), eq("md5"), eq(username), any(LocalizedOperationResult.class))).then(new Answer<ConfigUpdateResponse>() {

        @Override
        public ConfigUpdateResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new ConfigUpdateResponse(null, null, null, mock(ConfigAwareUpdate.class), ConfigSaveState.UPDATED);
        }
    });
    when(localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY")).thenReturn("SAVED_CONFIGURATION_SUCCESSFULLY");
    ConfigUpdateAjaxResponse response = service.savePackageRepositoryToConfig(packageRepository, "md5", username);
    assertThat(response.isSuccessful(), is(true));
    assertThat(response.getMessage(), is("SAVED_CONFIGURATION_SUCCESSFULLY"));
    assertThat(response.getSubjectIdentifier(), is("repoid"));
    assertThat(response.getStatusCode(), is(HttpStatus.SC_OK));
    verify(service).performPluginValidationsFor(packageRepository);
    verify(service).getPackageRepositoryUpdateCommand(packageRepository, username);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) ConfigUpdateAjaxResponse(com.thoughtworks.go.config.update.ConfigUpdateAjaxResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 10 with UpdateConfigFromUI

use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldValidateUpdateCommandForPackageRepository.

@Test
public void shouldValidateUpdateCommandForPackageRepository() throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    Validatable packageRepository = new PackageRepository();
    ((PackageRepository) packageRepository).setId("id");
    Validatable cruiseConfig = GoConfigMother.configWithPipelines("sample");
    ((CruiseConfig) cruiseConfig).getPackageRepositories().add((PackageRepository) packageRepository);
    UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand((PackageRepository) packageRepository, username);
    assertThat(updateCommand.node((CruiseConfig) cruiseConfig), is(cruiseConfig));
    assertThat(updateCommand.updatedNode((CruiseConfig) cruiseConfig), is(cruiseConfig));
    assertThat(updateCommand.subject(cruiseConfig), is(packageRepository));
    assertThat(updateCommand.updatedSubject(cruiseConfig), is(packageRepository));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Aggregations

UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)10 Test (org.junit.Test)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)8 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)7 Username (com.thoughtworks.go.server.domain.Username)7 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 LocalizedOperationResult (com.thoughtworks.go.server.service.result.LocalizedOperationResult)4 ConfigUpdateAjaxResponse (com.thoughtworks.go.config.update.ConfigUpdateAjaxResponse)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1