use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldPersistInvertedListOfPipelineSelections_WhenBlacklistIsSelected.
@Test
public void shouldPersistInvertedListOfPipelineSelections_WhenBlacklistIsSelected() {
Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
when(clock.currentTime()).thenReturn(date);
mockConfigWithSecurity();
User user = getUser("badger", 10L);
PipelineSelections blacklistPipelineSelections = new PipelineSelections(new ArrayList<>(), date, user.getId(), false);
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(blacklistPipelineSelections);
goConfigService.persistSelectedPipelines(null, user.getId(), Arrays.asList("pipelineX", "pipeline3"), true);
verify(pipelineRepository).saveSelectedPipelines(argThat(isAPipelineSelectionsInstanceWith(true, "pipeline1", "pipeline2")));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnPersistedPipelineSelectionsAgainstUser_WhenSecurityIsEnabled.
@Test
public void shouldReturnPersistedPipelineSelectionsAgainstUser_WhenSecurityIsEnabled() {
User loser = getUser("loser", 10L);
User newUser = getUser("new user", 20L);
when(userDao.findUser("new user")).thenReturn(newUser);
mockConfigWithSecurity();
PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pip1"));
when(pipelineRepository.findPipelineSelectionsByUserId(loser.getId())).thenReturn(pipelineSelections);
assertThat(goConfigService.getSelectedPipelines("1", loser.getId()), is(pipelineSelections));
assertThat(goConfigService.getSelectedPipelines("1", newUser.getId()), is(PipelineSelections.ALL));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldPersistPipelineSelectionsAgainstUser_AlreadyHavingSelections.
@Test
public void shouldPersistPipelineSelectionsAgainstUser_AlreadyHavingSelections() {
Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
when(clock.currentTime()).thenReturn(date);
mockConfigWithSecurity();
User user = getUser("badger", 10L);
PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pipeline2"), new Date(), user.getId(), true);
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(pipelineSelections);
when(pipelineRepository.saveSelectedPipelines(pipelineSelections)).thenReturn(2L);
long pipelineSelectionId = goConfigService.persistSelectedPipelines("1", user.getId(), Arrays.asList("pipelineX", "pipeline3"), true);
assertThat(pipelineSelections.getSelections(), is("pipeline1,pipeline2"));
assertThat(pipelineSelectionId, is(2l));
verify(pipelineRepository).saveSelectedPipelines(pipelineSelections);
verify(pipelineRepository).findPipelineSelectionsByUserId(user.getId());
verify(pipelineRepository, never()).findPipelineSelectionsById("1");
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method isAPipelineSelectionsInstanceWith.
private Matcher<PipelineSelections> isAPipelineSelectionsInstanceWith(final boolean isBlacklist, final String... pipelineSelectionsInInstance) {
return new BaseMatcher<PipelineSelections>() {
public boolean matches(Object o) {
PipelineSelections pipelineSelections = (PipelineSelections) o;
assertThat(pipelineSelections.isBlacklist(), is(isBlacklist));
List<String> expectedSelectionsAsList = Arrays.asList(pipelineSelectionsInInstance);
assertEquals(pipelineSelections.getSelections(), ListUtil.join(expectedSelectionsAsList, ","));
return true;
}
public void describeTo(Description description) {
}
};
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldPersistNonInvertedListOfPipelineSelections_WhenWhitelistIsSelected.
@Test
public void shouldPersistNonInvertedListOfPipelineSelections_WhenWhitelistIsSelected() {
Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
when(clock.currentTime()).thenReturn(date);
mockConfigWithSecurity();
User user = getUser("badger", 10L);
PipelineSelections whitelistPipelineSelections = new PipelineSelections(new ArrayList<>(), date, user.getId(), true);
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(whitelistPipelineSelections);
goConfigService.persistSelectedPipelines(null, user.getId(), Arrays.asList("pipelineX", "pipeline3"), false);
verify(pipelineRepository).saveSelectedPipelines(argThat(isAPipelineSelectionsInstanceWith(false, "pipelineX", "pipeline3")));
}
Aggregations