Search in sources :

Example 1 with Username

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

the class MyGoControllerTest method shouldRenderPipelineStageCombinationJSONSortedByPipelineNameIgnoringCase.

@Test
public void shouldRenderPipelineStageCombinationJSONSortedByPipelineNameIgnoringCase() {
    HttpServletRequest request = mock(HttpServletRequest.class);
    User user = new User(USERNAME, "Srikanth Maga", new String[] { "rope", "srikanth" }, "sriki@tw.com", true);
    user.addNotificationFilter(new NotificationFilter("p1", "s1", StageEvent.All, true));
    user.addNotificationFilter(new NotificationFilter("p2", "s2", StageEvent.Fails, true));
    when(userService.load(USERID)).thenReturn(user);
    List<PipelineConfigs> groups = new ArrayList<>();
    groups.add(PipelineConfigMother.createGroup("g3", PipelineConfigMother.createPipelineConfigWithStages("pipeline3-1", "stage3-1")));
    groups.add(PipelineConfigMother.createGroup("g1", PipelineConfigMother.createPipelineConfigWithStages("PIPELINE2-1", "stage2-1")));
    groups.add(PipelineConfigMother.createGroup("g1", PipelineConfigMother.createPipelineConfigWithStages("pipeline1-1", "stage1-1", "stage1-2")));
    when(pipelineConfigService.viewableGroupsFor(new Username(new CaseInsensitiveString(user.getName())))).thenReturn(groups);
    ModelAndView modelAndView = controller.handleRequest(null, request);
    assertThat(modelAndView.getModel().get("matchers"), is(new Matcher("rope,srikanth")));
    assertThat(modelAndView.getModel().get("email"), is("sriki@tw.com"));
    assertThat(modelAndView.getModel().get("emailMe"), is(true));
    assertThat(modelAndView.getModel().get("notificationFilters"), is(user.getNotificationFilters()));
    assertThat(modelAndView.getModel().get("l"), is(localizer));
    assertThat(modelAndView.getModel().get("pipelines"), is("[{\"name\":\"" + GoConstants.ANY_PIPELINE + "\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"}]}," + "{\"name\":\"pipeline1-1\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"},{\"stageName\":\"stage1-1\"},{\"stageName\":\"stage1-2\"}]}," + "{\"name\":\"PIPELINE2-1\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"},{\"stageName\":\"stage2-1\"}]}," + "{\"name\":\"pipeline3-1\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"},{\"stageName\":\"stage3-1\"}]}]"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.thoughtworks.go.domain.User) Username(com.thoughtworks.go.server.domain.Username) Matcher(com.thoughtworks.go.domain.Matcher) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) PipelineConfigs(com.thoughtworks.go.config.PipelineConfigs) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 2 with Username

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

the class FileAuthenticationProviderTest method shouldRetrieveDetailsIfUsernameSpecifiedInFile.

@Test
public void shouldRetrieveDetailsIfUsernameSpecifiedInFile() throws Exception {
    setupFile("jez=" + SHA1_BADGER);
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("jez")))).thenReturn(true);
    when(userService.findUserByName("jez")).thenReturn(new com.thoughtworks.go.domain.User("jez", "Jezz Humbles", "jez@humble.com"));
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    final UserDetails details = provider.retrieveUser("jez", null);
    assertThat(details.getAuthorities()[0].getAuthority(), is("ROLE_SUPERVISOR"));
    assertThat(details.isAccountNonExpired(), is(true));
    assertThat(details.isAccountNonLocked(), is(true));
    assertThat(details.isCredentialsNonExpired(), is(true));
    assertThat(details.isEnabled(), is(true));
    assertThat(details.getUsername(), is("jez"));
    assertThat(details.getPassword(), is(SHA1_BADGER));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 3 with Username

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

the class PluginServiceTest method shouldSavePluginSettingsToDbIfPluginSettingsAreValidated.

@Test
public void shouldSavePluginSettingsToDbIfPluginSettingsAreValidated() {
    Map<String, String> parameterMap = new HashMap<>();
    parameterMap.put("p2-k1", "v1");
    PluginSettings pluginSettings = new PluginSettings("plugin-id-2");
    pluginSettings.populateSettingsMap(parameterMap);
    Username currentUser = new Username("admin");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(securityService.isUserAdmin(currentUser)).thenReturn(true);
    when(configRepoExtension.canHandlePlugin("plugin-id-2")).thenReturn(true);
    when(configRepoExtension.validatePluginSettings(eq("plugin-id-2"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
    pluginService.savePluginSettings(currentUser, result, pluginSettings);
    Plugin plugin = new Plugin("plugin-id-2", toJSON(parameterMap));
    verify(pluginDao).saveOrUpdate(plugin);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

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

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

Aggregations

Username (com.thoughtworks.go.server.domain.Username)526 Test (org.junit.jupiter.api.Test)320 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)219 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)102 Test (org.junit.Test)102 BeforeEach (org.junit.jupiter.api.BeforeEach)65 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)37 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)30 Modification (com.thoughtworks.go.domain.materials.Modification)26 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)24 ArrayList (java.util.ArrayList)24 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)17 Pipeline (com.thoughtworks.go.domain.Pipeline)17 TimeProvider (com.thoughtworks.go.util.TimeProvider)16 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)15 Date (java.util.Date)14 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)13 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)12 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)12