Search in sources :

Example 6 with Localizer

use of com.thoughtworks.go.i18n.Localizer in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldReturnUnauthorizedResultWhenUserIsNotAuthorizedToViewGroup_onUpdateXml.

@Test
public void shouldReturnUnauthorizedResultWhenUserIsNotAuthorizedToViewGroup_onUpdateXml() throws Exception {
    String groupName = "some-secret-group";
    Localizer localizer = mock(Localizer.class);
    when(localizer.localize("UNAUTHORIZED_TO_EDIT_GROUP", groupName)).thenReturn("Unauthorized!");
    Username invalidUser = new Username(new CaseInsensitiveString("invalidUser"));
    when(securityService.isUserAdminOfGroup(invalidUser.getUsername(), groupName)).thenReturn(false);
    when(goConfigService.configFileMd5()).thenReturn("md5");
    GoConfigOperationalResponse<PipelineConfigs> actual = service.updateXml(groupName, "", "md5", invalidUser, result);
    PipelineConfigs configElement = actual.getConfigElement();
    GoConfigValidity validity = actual.getValidity();
    assertThat(configElement, is(nullValue()));
    assertThat(result.httpCode(), is(401));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Unauthorized!"));
    assertThat(validity.isValid(), is(true));
    verify(securityService, times(1)).isUserAdminOfGroup(invalidUser.getUsername(), groupName);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Localizer(com.thoughtworks.go.i18n.Localizer) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 7 with Localizer

use of com.thoughtworks.go.i18n.Localizer in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldThrowExceptionWhenTheGroupIsNotFound_onGetXml.

@Test
public void shouldThrowExceptionWhenTheGroupIsNotFound_onGetXml() {
    String groupName = "non-existent-group_name";
    Localizer localizer = mock(Localizer.class);
    when(localizer.localize("PIPELINE_GROUP_NOT_FOUND", groupName)).thenReturn("Not found");
    when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenThrow(new PipelineGroupNotFoundException());
    service.getXml(groupName, validUser, result);
    assertThat(result.httpCode(), is(404));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Not found"));
    verify(securityService, times(1)).isUserAdminOfGroup(validUser.getUsername(), groupName);
    verify(goConfigService, never()).getConfigForEditing();
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) Test(org.junit.Test)

Example 8 with Localizer

use of com.thoughtworks.go.i18n.Localizer in project gocd by gocd.

the class PipelineStagesFeedServiceTest method verifyThatUserIsUnauthorized.

private void verifyThatUserIsUnauthorized() {
    assertThat(operationResult.isSuccessful(), is(false));
    // verify we are unauthorized
    assertThat(operationResult.httpCode(), is(401));
    Localizer localizer = mock(Localizer.class);
    operationResult.message(localizer);
    // Verify the message is right
    verify(localizer).localize(NO_VIEW_PERMISSION_ON_PIPELINE, user.getDisplayName(), "cruise");
    verifyNoMoreInteractions(localizer);
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer)

Example 9 with Localizer

use of com.thoughtworks.go.i18n.Localizer in project gocd by gocd.

the class HttpLocalizedOperationResultTest method shouldNotFailWhenNoMessageSet.

@Test
public void shouldNotFailWhenNoMessageSet() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Localizer localizer = mock(Localizer.class);
    assertThat(result.message(localizer), is(nullValue()));
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer) Test(org.junit.Test)

Example 10 with Localizer

use of com.thoughtworks.go.i18n.Localizer in project gocd by gocd.

the class HttpLocalizedOperationResultTest method shouldReturnMessageAndStatus501WhenNotImplemented.

@Test
public void shouldReturnMessageAndStatus501WhenNotImplemented() {
    Localizable message = mock(Localizable.class);
    Localizer localizer = mock(Localizer.class);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(message.localize(localizer)).thenReturn("Seriously, whateva");
    result.notImplemented(message);
    assertThat(result.httpCode(), is(501));
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer) Localizable(com.thoughtworks.go.i18n.Localizable) Test(org.junit.Test)

Aggregations

Localizer (com.thoughtworks.go.i18n.Localizer)21 Test (org.junit.Test)14 Username (com.thoughtworks.go.server.domain.Username)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)5 Before (org.junit.Before)5 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)3 PipelineGroupNotFoundException (com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException)2 Localizable (com.thoughtworks.go.i18n.Localizable)2 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)2 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)2 TestTransactionTemplate (com.thoughtworks.go.server.transaction.TestTransactionTemplate)2 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 TaskExtension (com.thoughtworks.go.plugin.access.pluggabletask.TaskExtension)1 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)1 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)1 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)1 SecurityAuthConfigService (com.thoughtworks.go.server.service.SecurityAuthConfigService)1