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\"}]}]"));
}
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));
}
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);
}
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);
}
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)));
}
Aggregations