Search in sources :

Example 1 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)

Example 2 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 3 with Localizer

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

the class ScheduleServiceTest method setup.

@Before
public void setup() {
    jobInstanceService = mock(JobInstanceService.class);
    goConfigService = mock(GoConfigService.class);
    environmentConfigService = mock(EnvironmentConfigService.class);
    serverHealthService = mock(ServerHealthService.class);
    final TestTransactionSynchronizationManager synchronizationManager = new TestTransactionSynchronizationManager();
    schedulingChecker = mock(SchedulingCheckerService.class);
    pipelineScheduleQueue = mock(PipelineScheduleQueue.class);
    consoleActivityMonitor = mock(ConsoleActivityMonitor.class);
    pipelinePauseService = mock(PipelinePauseService.class);
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    pipelineService = mock(PipelineService.class);
    localizer = mock(Localizer.class);
    timeProvider = new TimeProvider();
    schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    elasticProfileService = mock(ElasticProfileService.class);
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineScheduledTopic.class), mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, mock(PipelineLockService.class), serverHealthService, new TestTransactionTemplate(synchronizationManager), mock(AgentService.class), synchronizationManager, timeProvider, consoleActivityMonitor, pipelinePauseService, instanceFactory, schedulingPerformanceLogger, elasticProfileService);
}
Also used : TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Localizer(com.thoughtworks.go.i18n.Localizer) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

Example 4 with Localizer

use of com.thoughtworks.go.i18n.Localizer 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 5 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)

Aggregations

Localizer (com.thoughtworks.go.i18n.Localizer)20 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 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 AuthenticationPluginRegistry (com.thoughtworks.go.plugin.access.authentication.AuthenticationPluginRegistry)1 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 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 TestTransactionTemplate (com.thoughtworks.go.server.transaction.TestTransactionTemplate)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1