Search in sources :

Example 26 with HttpLocalizedOperationResult

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

the class StageServiceTest method shouldFindStageSummaryModelForGivenStageIdentifier.

@Test
public void shouldFindStageSummaryModelForGivenStageIdentifier() throws Exception {
    SecurityService securityService = alwaysAllow();
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    Stage stageRun1 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
    stageRun1.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"));
    stageRun1.setCounter(1);
    Stage stageRun2 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
    stageRun2.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/2"));
    stageRun2.setCounter(2);
    Stages stages = new Stages(stageRun1, stageRun2);
    StageIdentifier stageId = new StageIdentifier("pipeline_name/10/stage_name/2");
    when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
    StageSummaryModel stageForView = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, new HttpLocalizedOperationResult());
    assertThat(stageForView.getName(), is(stageRun2.getName()));
    assertThat(stageForView.getState(), is(stageRun2.stageState()));
    assertThat(stageForView.getStageCounter(), is(String.valueOf(stageRun2.getCounter())));
    assertThat(stageForView.getTotalRuns(), is(2));
}
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 27 with HttpLocalizedOperationResult

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

the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith404WhenNoStagesFound.

@Test
public void findStageSummaryByIdentifierShouldRespondWith404WhenNoStagesFound() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_does_not_exist")).thenReturn(true);
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    StageIdentifier stageId = new StageIdentifier("pipeline_does_not_exist/10/stage_name/1");
    when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(new Stages());
    StageSummaryModel model = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, result);
    assertThat(result.httpCode(), is(404));
    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 28 with HttpLocalizedOperationResult

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

the class UserServiceTest method shouldFailWithErrorWhenDeletingAnEnabledUserFails.

@Test
public void shouldFailWithErrorWhenDeletingAnEnabledUserFails() {
    String username = "username";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(userDao.deleteUser(username)).thenThrow(new UserEnabledException());
    userService.deleteUser(username, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.hasMessage(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserEnabledException(com.thoughtworks.go.server.exceptions.UserEnabledException) Test(org.junit.Test)

Example 29 with HttpLocalizedOperationResult

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

the class ServerConfigServiceTest method shouldSetMessageAsMergedWhenMergingServerConfigChanges.

@Test
public void shouldSetMessageAsMergedWhenMergingServerConfigChanges() {
    GoConfigService goConfigService = mock(GoConfigService.class);
    UserService userService = mock(UserService.class);
    ServerConfigService serverConfigService = new ServerConfigService(goConfigService, userService);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    MailHost mailHost = new MailHost(new GoCipher());
    when(goConfigService.updateServerConfig(mailHost, null, null, true, "md5", null, null, null, null, "http://site", "https://site", "location")).thenReturn(ConfigSaveState.MERGED);
    serverConfigService.updateServerConfig(mailHost, null, null, null, null, null, null, true, "http://site", "https://site", "location", result, "md5");
    assertThat(result.localizable(), Is.is(LocalizedMessage.composite(LocalizedMessage.string("SAVED_CONFIGURATION_SUCCESSFULLY"), LocalizedMessage.string("CONFIG_MERGED"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) MailHost(com.thoughtworks.go.config.MailHost) Test(org.junit.Test)

Example 30 with HttpLocalizedOperationResult

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

the class PackageRepositoryService method savePackageRepositoryToConfig.

public ConfigUpdateAjaxResponse savePackageRepositoryToConfig(PackageRepository packageRepository, final String md5, Username username) {
    performPluginValidationsFor(packageRepository);
    UpdateConfigFromUI updateCommand = getPackageRepositoryUpdateCommand(packageRepository, username);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(updateCommand, md5, username, result);
    if (result.isSuccessful()) {
        ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.success(packageRepository.getId(), result.httpCode(), configUpdateResponse.wasMerged() ? localizer.localize("CONFIG_MERGED") : localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY"));
        return response;
    } else {
        List<String> globalErrors = globalErrors(configUpdateResponse.getCruiseConfig().getAllErrorsExceptFor(configUpdateResponse.getSubject()));
        HashMap<String, List<String>> fieldErrors = fieldErrors(configUpdateResponse.getSubject(), "package_repository");
        String message = result.message(localizer);
        ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.failure(packageRepository.getId(), result.httpCode(), message, fieldErrors, globalErrors);
        return response;
    }
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) List(java.util.List)

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