Search in sources :

Example 76 with HttpLocalizedOperationResult

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

the class PipelinePauseServiceTest method shouldPopulatePausePipelineSuccessResult.

@Test
public void shouldPopulatePausePipelineSuccessResult() throws Exception {
    setUpValidPipelineWithAuth();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    pipelinePauseService.pause(VALID_PIPELINE, null, VALID_USER, result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.httpCode(), is(SC_OK));
    assertThat(result.localizable(), is(LocalizedMessage.string("PIPELINE_PAUSE_SUCCESSFUL", VALID_PIPELINE)));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 77 with HttpLocalizedOperationResult

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

the class PipelineStagesFeedServiceTest method setUp.

@Before
public void setUp() throws Exception {
    user = new Username(new CaseInsensitiveString("barrow"));
    expected = new FeedEntries();
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    operationResult = new HttpLocalizedOperationResult();
    pipelineStagesFeedResolver = new PipelineStagesFeedService(stageService, securityService).feedResolverFor("cruise");
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Example 78 with HttpLocalizedOperationResult

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

the class PluginServiceTest method shouldNotSavePluginSettingsIfPluginDoesNotExist.

@Test
public void shouldNotSavePluginSettingsIfPluginDoesNotExist() {
    PluginSettings pluginSettings = new PluginSettings("non-existent-plugin");
    Username currentUser = new Username("admin");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(securityService.isUserAdmin(currentUser)).thenReturn(true);
    for (GoPluginExtension extension : extensions) {
        when(extension.canHandlePlugin("non-existent-plugin")).thenReturn(false);
    }
    pluginService.savePluginSettings(currentUser, result, pluginSettings);
    assertThat(result.httpCode(), is(422));
    assertThat(result.toString(), containsString("Plugin 'non-existent-plugin' does not exist or does not implement settings validation"));
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) Test(org.junit.Test)

Example 79 with HttpLocalizedOperationResult

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

the class BackupsControllerDelegate method create.

public String create(Request request, Response response) throws IOException {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ServerBackup backup = backupService.startBackup(currentUsername(), result);
    if (result.isSuccessful()) {
        return writerForTopLevelObject(request, response, outputWriter -> BackupRepresenter.toJSON(outputWriter, backup));
    }
    return renderHTTPOperationResult(result, request, response, localizer);
}
Also used : ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 80 with HttpLocalizedOperationResult

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

the class CurrentUserControllerDelegate method update.

public String update(Request req, Response res) throws IOException {
    User user = userService.findUserByName(currentUserLoginName().toString());
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Map map = readRequestBodyAsJSON(req);
    String checkinAliases = null;
    if (map.containsKey("checkin_aliases")) {
        Object newAliases = map.get("checkin_aliases");
        if (newAliases instanceof Collection) {
            checkinAliases = StringUtils.join((Collection) newAliases, ", ");
        } else if (newAliases instanceof String) {
            checkinAliases = (String) newAliases;
        }
    }
    TriState emailMe = TriState.from(String.valueOf(map.get("email_me")));
    String email = (String) map.get("email");
    User serializedUser = userService.save(user, TriState.from(null), emailMe, email, checkinAliases, result);
    String json = jsonizeAsTopLevelObject(req, writer -> UserRepresenter.toJSON(writer, serializedUser));
    String etag = etagFor(json);
    setEtagHeader(res, etag);
    return json;
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) User(com.thoughtworks.go.domain.User) Collection(java.util.Collection) TriState(com.thoughtworks.go.util.TriState) Map(java.util.Map)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)437 Test (org.junit.Test)394 Username (com.thoughtworks.go.server.domain.Username)168 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)41 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)26 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)24 Pipeline (com.thoughtworks.go.domain.Pipeline)24 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 GoCipher (com.thoughtworks.go.security.GoCipher)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)15 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14