Search in sources :

Example 41 with Username

use of com.thoughtworks.go.server.domain.Username 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);
}
Also used : TestSuite(com.thoughtworks.go.domain.testinfo.TestSuite) Username(com.thoughtworks.go.server.domain.Username) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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 42 with Username

use of com.thoughtworks.go.server.domain.Username 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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 43 with Username

use of com.thoughtworks.go.server.domain.Username 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);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Gson(com.google.gson.Gson) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 44 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class AuthorityGranterTest method shouldGrantTemplateViewUserRoleToTemplateViewUsers.

@Test
public void shouldGrantTemplateViewUserRoleToTemplateViewUsers() {
    String templateViewUser = "templateViewUser";
    when(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString(templateViewUser)))).thenReturn(false);
    when(securityService.isAuthorizedToViewTemplates(new Username(templateViewUser))).thenReturn(true);
    GrantedAuthority[] authorities = authorityGranter.authorities(templateViewUser);
    assertThat(authorities, hasItemInArray(GoAuthority.ROLE_TEMPLATE_VIEW_USER.asAuthority()));
    assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_TEMPLATE_SUPERVISOR.asAuthority())));
    assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority())));
    assertThat(authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 45 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class AuthorityGranterTest method shouldGrantGroupSupervisorRoleToPipelineGroupAdmins.

@Test
public void shouldGrantGroupSupervisorRoleToPipelineGroupAdmins() {
    when(securityService.isUserGroupAdmin(new Username(new CaseInsensitiveString("group-admin")))).thenReturn(true);
    GrantedAuthority[] authorities = authorityGranter.authorities("group-admin");
    assertThat("Should not have " + GoAuthority.ROLE_SUPERVISOR + " authority", authorities, not(hasItemInArray(GoAuthority.ROLE_SUPERVISOR.asAuthority())));
    assertThat("Should have " + GoAuthority.ROLE_GROUP_SUPERVISOR + " authority", authorities, hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority()));
    assertThat("Should have " + GoAuthority.ROLE_USER + " authority", authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10