use of com.thoughtworks.go.config.CaseInsensitiveString 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.config.CaseInsensitiveString in project gocd by gocd.
the class StageNotificationServiceTest method shouldSendEmailWithFailureDetails.
@Test
public void shouldSendEmailWithFailureDetails() throws Exception {
final String expectedBaseUrl = "http://test.host:8153";
String jezMail = prepareOneMatchedUser();
final Date date = new Date();
stubPipelineAndStage(date);
final TestSuite suite1 = new TestSuite("com.thoughtworks.go.FailOne");
suite1.addTest("shouldCompile", TestStatus.Error, new JobIdentifier(stageIdentifier, "compile"));
suite1.addTest("shouldPass", TestStatus.Failure, new JobIdentifier(stageIdentifier, "test"));
suite1.addTest("shouldPass", TestStatus.Failure, new JobIdentifier(stageIdentifier, "twist"));
suite1.addTest("shouldCompile2", TestStatus.Failure, new JobIdentifier(stageIdentifier, "compile"));
final TestSuite suite2 = new TestSuite("com.thoughtworks.go.FailTwo");
suite2.addTest("shouldCompile", TestStatus.Error, new JobIdentifier(stageIdentifier, "test"));
suite2.addTest("shouldTest", TestStatus.Failure, new JobIdentifier(stageIdentifier, "test"));
when(serverConfigService.siteUrlFor(anyString(), eq(false))).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return morphURl((String) args[0], expectedBaseUrl);
}
});
when(systemEnvironment.isShineEnabled()).thenReturn(true);
when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(Arrays.asList(suite1, suite2));
stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
String body = inMemoryEmailNotificationTopic.getBody(jezMail);
assertThat(body, containsString(StageNotificationService.FAILED_TEST_SECTION));
String restOfThebody = textAfter(body, StageNotificationService.FAILED_TEST_SECTION);
String failuresText = restOfThebody.substring(0, restOfThebody.indexOf(StageNotificationService.MATERIAL_SECTION_HEADER));
assertEquals("\n\nThe following tests failed in pipeline 'go' (instance 'go-1'):\n\n" + "* com.thoughtworks.go.FailOne\n" + " shouldCompile\n" + " Errored on 'compile' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/compile)\n" + " shouldCompile2\n" + " Failed on 'compile' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/compile)\n" + " shouldPass\n" + " Failed on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n" + " Failed on 'twist' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/twist)\n" + "\n\n* com.thoughtworks.go.FailTwo\n" + " shouldCompile\n" + " Errored on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n" + " shouldTest\n" + " Failed on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n\n\n", failuresText);
}
use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldPerformOperationInSequence.
@Test
public void authenticate_shouldPerformOperationInSequence() {
final InOrder inOrder = inOrder(authorizationExtension, pluginRoleService, authorityGranter, userService);
Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
authenticationProvider.authenticate(authenticationToken);
inOrder.verify(authorizationExtension).authenticateUser(eq(pluginId), eq(credentials), any(List.class), any(List.class));
inOrder.verify(pluginRoleService).updatePluginRoles(pluginId, user.getUsername(), asList(new CaseInsensitiveString("admin")));
inOrder.verify(authorityGranter).authorities(user.getUsername());
inOrder.verify(userService).addUserIfDoesNotExist(any(com.thoughtworks.go.domain.User.class));
}
use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class AgentServiceTest method shouldFailWhenDeleteIsNotSuccessful.
@Test
public void shouldFailWhenDeleteIsNotSuccessful() throws Exception {
SecurityService securityService = mock(SecurityService.class);
AgentConfigService agentConfigService = mock(AgentConfigService.class);
AgentInstance agentInstance = mock(AgentInstance.class);
String uuid = "1234";
Username username = new Username(new CaseInsensitiveString("test"));
HttpOperationResult operationResult = mock(HttpOperationResult.class);
when(securityService.hasOperatePermissionForAgents(username)).thenReturn(true);
when(agentInstance.canBeDeleted()).thenReturn(true);
doThrow(new RuntimeException()).when(agentConfigService).deleteAgents(username, agentInstance);
when(agentInstances.findAgentAndRefreshStatus(uuid)).thenReturn(agentInstance);
AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), agentInstances, mock(EnvironmentConfigService.class), securityService, agentDao, uuidGenerator, serverHealthService = mock(ServerHealthService.class), null);
agentService.deleteAgents(username, operationResult, Arrays.asList(uuid));
verify(operationResult).internalServerError(any(String.class), any(HealthStateType.class));
}
use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class StageJsonPresentationModelTest method shouldEscapeBuildCauseMessage.
@Test
public void shouldEscapeBuildCauseMessage() throws Exception {
String userWithHtmlCharacters = "<user>";
pipeline.setBuildCause(BuildCause.createManualForced(materialRevisions(userWithHtmlCharacters), new Username(new CaseInsensitiveString(userWithHtmlCharacters))));
StageJsonPresentationModel presenter = new StageJsonPresentationModel(pipeline, stage, null, agentService);
JSONAssert.assertEquals("{\n" + " \"buildCause\": \"Forced by \\u0026lt;user\\u0026gt;\"\n" + "}", new Gson().toJson(presenter.toJson()), false);
}
Aggregations