Search in sources :

Example 26 with Username

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)));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 27 with Username

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));
}
Also used : TestSuite(com.thoughtworks.go.domain.testinfo.TestSuite) Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 28 with Username

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();
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 29 with Username

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());
}
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 30 with Username

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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)331 Test (org.junit.Test)268 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)133 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)84 Before (org.junit.Before)39 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)35 Pipeline (com.thoughtworks.go.domain.Pipeline)34 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)28 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)18 Modification (com.thoughtworks.go.domain.materials.Modification)17 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)15 ArrayList (java.util.ArrayList)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 EmptyPipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12