use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method shouldNotHaveFailedTestsSectionWhenThereAreNoFailedTests.
@Test
public void shouldNotHaveFailedTestsSectionWhenThereAreNoFailedTests() {
String jezMail = prepareOneMatchedUser();
stubPipelineAndStage(new Date());
when(systemEnvironment.isShineEnabled()).thenReturn(true);
when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(new ArrayList<>());
stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
String body = inMemoryEmailNotificationTopic.getBody(jezMail);
assertThat(body, not(containsString(StageNotificationService.FAILED_TEST_SECTION)));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method shouldHaveFailedTestsSectionWhenShineIsEnabledAndThereAreFailedTests.
@Test
public void shouldHaveFailedTestsSectionWhenShineIsEnabledAndThereAreFailedTests() {
String mail = prepareOneMatchedUser();
stubPipelineAndStage(new Date());
when(systemEnvironment.isShineEnabled()).thenReturn(true);
ArrayList<TestSuite> testSuites = new ArrayList<>();
testSuites.add(new TestSuite("blah"));
when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(testSuites);
stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
String body = inMemoryEmailNotificationTopic.getBody(mail);
assertThat(body, containsString(StageNotificationService.FAILED_TEST_SECTION));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class ScheduleServiceTest method shouldNotCancelStageWhenTheUserDoesNotHaveOperatePermission.
@Test
public void shouldNotCancelStageWhenTheUserDoesNotHaveOperatePermission() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Pipeline pipeline = PipelineMother.pipeline("pipeline-name", StageMother.passedStageInstance("mingle", "job-bar", "pipeline-name"));
Stage spiedStage = spy(pipeline.getFirstStage());
long stageId = spiedStage.getId();
Username admin = new Username(new CaseInsensitiveString("admin"));
doReturn(true).when(spiedStage).isActive();
when(stageService.stageById(stageId)).thenReturn(spiedStage);
when(securityService.hasOperatePermissionForStage(pipeline.getName(), spiedStage.getName(), admin.getUsername().toString())).thenReturn(false);
Stage resultStage = service.cancelAndTriggerRelevantStages(stageId, admin, result);
assertThat(resultStage, is(nullValue()));
assertThat(result.httpCode(), is(SC_UNAUTHORIZED));
assertThat(result.isSuccessful(), is(false));
verify(securityService).hasOperatePermissionForStage(pipeline.getName(), spiedStage.getName(), admin.getUsername().toString());
verify(stageService, never()).cancelStage(spiedStage);
verify(spiedStage).isActive();
}
use of com.thoughtworks.go.server.domain.Username 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());
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class ScheduleServiceTest method shouldCancelStageUsingPipelineNameAndStageName.
@Test
public void shouldCancelStageUsingPipelineNameAndStageName() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String pipelineName = "pipeline-name";
Username admin = new Username(new CaseInsensitiveString("admin"));
String stageName = "mingle";
Pipeline pipeline = PipelineMother.pipeline(pipelineName, StageMother.passedStageInstance(stageName, "job-bar", pipelineName));
Stage firstStage = pipeline.getFirstStage();
long stageId = firstStage.getId();
when(stageService.findLatestStage(pipelineName, stageName)).thenReturn(firstStage);
ScheduleService spyedService = spy(service);
doReturn(firstStage).when(spyedService).cancelAndTriggerRelevantStages(stageId, admin, result);
Stage resultStage = spyedService.cancelAndTriggerRelevantStages(pipelineName, stageName, admin, result);
assertThat(resultStage, is(firstStage));
assertThat(result.httpCode(), is(SC_OK));
assertThat(result.isSuccessful(), is(true));
verify(stageService).findLatestStage(pipelineName, stageName);
}
Aggregations