Search in sources :

Example 36 with HttpLocalizedOperationResult

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

the class ScheduleServiceTest method shouldNotCancelStageIfItsNotActive.

@Test
public void shouldNotCancelStageIfItsNotActive() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Pipeline pipeline = PipelineMother.pipeline("pipeline-name", StageMother.passedStageInstance("mingle", "job-bar", "pipeline-name"));
    Stage firstStage = pipeline.getFirstStage();
    long stageId = firstStage.getId();
    Username admin = new Username(new CaseInsensitiveString("admin"));
    when(stageService.stageById(stageId)).thenReturn(firstStage);
    Stage resultStage = service.cancelAndTriggerRelevantStages(stageId, admin, result);
    assertThat(resultStage, is(firstStage));
    assertThat(result.httpCode(), is(SC_OK));
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.hasMessage(), is(true));
    Localizer localizer = mock(Localizer.class);
    String respMsg = "Stage is not active. Cancellation Ignored";
    String stageNotActiveKey = "STAGE_IS_NOT_ACTIVE_FOR_CANCELLATION";
    when(localizer.localize(eq(stageNotActiveKey), anyVararg())).thenReturn(respMsg);
    assertThat(result.message(localizer), is(respMsg));
    verify(stageService).stageById(stageId);
    verify(localizer).localize(eq(stageNotActiveKey), anyVararg());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Localizer(com.thoughtworks.go.i18n.Localizer) Test(org.junit.Test)

Example 37 with HttpLocalizedOperationResult

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

the class SecurityAuthConfigServiceTest method shouldPerformPluginValidationsBeforeAddingSecurityAuthConfig.

@Test
public void shouldPerformPluginValidationsBeforeAddingSecurityAuthConfig() {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap", create("key", false, "value"));
    Username username = new Username("username");
    securityAuthConfigService.create(username, securityAuthConfig, new HttpLocalizedOperationResult());
    verify(extension).validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 38 with HttpLocalizedOperationResult

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

the class SecurityAuthConfigServiceTest method shouldAddSecurityAuthConfigToConfig.

@Test
public void shouldAddSecurityAuthConfigToConfig() {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
    Username username = new Username("username");
    securityAuthConfigService.create(username, securityAuthConfig, new HttpLocalizedOperationResult());
    verify(goConfigService).updateConfig(any(SecurityAuthConfigCreateCommand.class), eq(username));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) SecurityAuthConfigCreateCommand(com.thoughtworks.go.config.update.SecurityAuthConfigCreateCommand) Test(org.junit.Test)

Example 39 with HttpLocalizedOperationResult

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

the class SecurityAuthConfigServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginId.

@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginId() throws Exception {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("some-id", "non-existent-plugin", create("key", false, "value"));
    Username username = new Username("username");
    when(extension.validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("plugin not found"));
    securityAuthConfigService.update(username, "md5", securityAuthConfig, new HttpLocalizedOperationResult());
    assertThat(securityAuthConfig.errors().isEmpty(), is(false));
    assertThat(securityAuthConfig.errors().on("pluginId"), is("Plugin with id `non-existent-plugin` is not found."));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) Test(org.junit.Test)

Example 40 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, true, "md5", null, null, null, null, "http://site", "https://site", "location")).thenReturn(ConfigSaveState.MERGED);
    serverConfigService.updateServerConfig(mailHost, 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)

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