use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class PipelineSelectionsServiceTest method shouldReturnPersistedPipelineSelectionsAgainstUserId_WhenSecurityIsEnabled_AndUserSelectionsDoesNotExist.
@Test
public void shouldReturnPersistedPipelineSelectionsAgainstUserId_WhenSecurityIsEnabled_AndUserSelectionsDoesNotExist() {
User user = getUser("loser", 10L);
when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
when(goConfigService.isSecurityEnabled()).thenReturn(true);
PipelineSelections pipelineSelectionsForCookie = new PipelineSelections(Arrays.asList("pipeline2"));
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(null);
when(pipelineRepository.findPipelineSelectionsById("1")).thenReturn(pipelineSelectionsForCookie);
assertThat(pipelineSelectionsService.getPersistedSelectedPipelines("1", user.getId()), is(PipelineSelections.ALL));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class PipelineSelectionsServiceTest method shouldReturnSelectedPipelinesRegardlessOfPersistedPipelineSelections.
@Test
public void shouldReturnSelectedPipelinesRegardlessOfPersistedPipelineSelections() throws Exception {
User user = getUser("loser", 10L);
when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
when(goConfigService.isSecurityEnabled()).thenReturn(true);
PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pipeline2"));
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(pipelineSelections);
PipelineSelections selectedPipelines = pipelineSelectionsService.getSelectedPipelines("1", user.getId());
assertThat(selectedPipelines.isBlacklist(), is(true));
assertThat(selectedPipelines.pipelineList(), is(Arrays.asList("pipeline1", "pipelineX", "pipeline3")));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class PipelineSelectionsServiceTest method shouldReturnAllPipelinesWhenThereAreNoPreviouslyPersistedPipelineSelections.
@Test
public void shouldReturnAllPipelinesWhenThereAreNoPreviouslyPersistedPipelineSelections() {
User user = getUser("loser", 10L);
when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
when(goConfigService.isSecurityEnabled()).thenReturn(true);
List<String> expectedPipelineList = Arrays.asList("pipeline1", "pipeline2", "pipelineX", "pipeline3");
when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(null);
PipelineSelections selectedPipelines = pipelineSelectionsService.getSelectedPipelines("1", user.getId());
List<String> actualPipelineList = selectedPipelines.pipelineList();
assertThat(actualPipelineList, is(expectedPipelineList));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class PipelineSelectionsServiceTest method shouldPersistPipelineSelections_WhenSecurityIsDisabled.
@Test
public void shouldPersistPipelineSelections_WhenSecurityIsDisabled() {
Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
when(clock.currentTime()).thenReturn(date);
when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
Matcher<PipelineSelections> pipelineSelectionsMatcher = hasValues(Arrays.asList("pipelineX", "pipeline3"), Arrays.asList("pipeline1", "pipeline2"), date, null);
when(pipelineRepository.saveSelectedPipelines(argThat(pipelineSelectionsMatcher))).thenReturn(2L);
assertThat(pipelineSelectionsService.persistSelectedPipelines(null, null, Arrays.asList("pipelineX", "pipeline3"), true), is(2l));
verify(pipelineRepository).saveSelectedPipelines(argThat(pipelineSelectionsMatcher));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class PipelineSelectionsServiceTest method shouldUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithWhitelist.
@Test
public void shouldUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithWhitelist() {
when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
when(goConfigService.isSecurityEnabled()).thenReturn(true);
when(pipelineRepository.findPipelineSelectionsByUserId(1L)).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, false));
pipelineSelectionsService.updateUserPipelineSelections(null, 1L, new CaseInsensitiveString("pipelineNew"));
verify(pipelineRepository).findPipelineSelectionsByUserId(1L);
verify(pipelineRepository, times(1)).saveSelectedPipelines(argThat(isAPipelineSelectionsInstanceWith(false, "pipeline1", "pipeline2", "pipelineNew")));
}
Aggregations