use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class PipelineRepositoryIntegrationTest method shouldFindSelectedPipelinesByUserId.
@Test
public void shouldFindSelectedPipelinesByUserId() {
User user = createUser();
List<String> unSelected = Arrays.asList("pipeline1", "pipeline2");
long id = pipelineRepository.saveSelectedPipelines(new PipelineSelections(unSelected, new Date(), user.getId(), true));
assertThat(pipelineRepository.findPipelineSelectionsByUserId(user.getId()).getId(), is(id));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigService method persistSelectedPipelines.
public long persistSelectedPipelines(String id, Long userId, List<String> selectedPipelines, boolean isBlacklist) {
PipelineSelections pipelineSelections = findOrCreateCurrentPipelineSelectionsFor(id, userId);
if (isBlacklist) {
List<String> unselectedPipelines = invertSelections(selectedPipelines);
pipelineSelections.update(unselectedPipelines, clock.currentTime(), userId, isBlacklist);
} else {
pipelineSelections.update(selectedPipelines, clock.currentTime(), userId, isBlacklist);
}
return pipelineRepository.saveSelectedPipelines(pipelineSelections);
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldNotUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithBlacklist.
@Test
public void shouldNotUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithBlacklist() {
when(pipelineRepository.findPipelineSelectionsById("1")).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, true));
goConfigService.updateUserPipelineSelections("1", null, new CaseInsensitiveString("pipelineNew"));
verify(pipelineRepository).findPipelineSelectionsById("1");
verify(pipelineRepository, times(0)).saveSelectedPipelines(argThat(Matchers.any(PipelineSelections.class)));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithWhitelist.
@Test
public void shouldUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithWhitelist() {
mockConfigWithSecurity();
when(pipelineRepository.findPipelineSelectionsByUserId(1L)).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, false));
goConfigService.updateUserPipelineSelections(null, 1L, new CaseInsensitiveString("pipelineNew"));
verify(pipelineRepository).findPipelineSelectionsByUserId(1L);
verify(pipelineRepository, times(1)).saveSelectedPipelines(argThat(isAPipelineSelectionsInstanceWith(false, "pipeline1", "pipeline2", "pipelineNew")));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method shouldPersistPipelineSelectionsAgainstUser_WhenUserHasNoSelections.
@Test
public void shouldPersistPipelineSelectionsAgainstUser_WhenUserHasNoSelections() {
Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
when(clock.currentTime()).thenReturn(date);
mockConfigWithSecurity();
User user = getUser("badger", 10L);
Matcher<PipelineSelections> pipelineSelectionsMatcher = hasValues(Arrays.asList("pipelineX", "pipeline3"), Arrays.asList("pipeline1", "pipeline2"), date, user.getId());
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(null);
when(pipelineRepository.saveSelectedPipelines(argThat(pipelineSelectionsMatcher))).thenReturn(2L);
long pipelineSelectionsId = goConfigService.persistSelectedPipelines("1", user.getId(), Arrays.asList("pipelineX", "pipeline3"), true);
assertThat(pipelineSelectionsId, is(2l));
verify(pipelineRepository).saveSelectedPipelines(argThat(pipelineSelectionsMatcher));
verify(pipelineRepository).findPipelineSelectionsByUserId(user.getId());
verify(pipelineRepository, never()).findPipelineSelectionsById("1");
}
Aggregations