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");
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoConfigServiceTest method hasValues.
private Matcher<PipelineSelections> hasValues(final List<String> isVisible, final List<String> isNotVisible, final Date today, final Long userId) {
return new BaseMatcher<PipelineSelections>() {
public boolean matches(Object o) {
PipelineSelections pipelineSelections = (PipelineSelections) o;
assertHasSelected(pipelineSelections, isVisible);
assertHasSelected(pipelineSelections, isNotVisible, false);
assertThat(pipelineSelections.lastUpdated(), is(today));
assertThat(pipelineSelections.userId(), is(userId));
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 shouldUpdateAlreadyPersistedSelection_WhenSecurityIsDisabled.
@Test
public void shouldUpdateAlreadyPersistedSelection_WhenSecurityIsDisabled() {
Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
when(clock.currentTime()).thenReturn(date);
mockConfig();
PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pip1"));
when(pipelineRepository.findPipelineSelectionsById("123")).thenReturn(pipelineSelections);
List<String> newPipelines = Arrays.asList("pipeline1", "pipeline2");
goConfigService.persistSelectedPipelines("123", null, newPipelines, true);
assertHasSelected(pipelineSelections, newPipelines);
assertThat(pipelineSelections.lastUpdated(), is(date));
verify(pipelineRepository).findPipelineSelectionsById("123");
verify(pipelineRepository).saveSelectedPipelines(argThat(hasValues(Arrays.asList("pipeline1", "pipeline2"), Arrays.asList("pipelineX", "pipeline3"), clock.currentTime(), null)));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoDashboardServiceTest method allPipelineGroupsForDashboard_shouldRetrieveOnlyPipelineGroupsViewableByTheUser.
@Test
public void allPipelineGroupsForDashboard_shouldRetrieveOnlyPipelineGroupsViewableByTheUser() throws Exception {
PipelineSelections pipelineSelections = mock(PipelineSelections.class);
PipelineConfig pipelineConfig4 = configMother.addPipelineWithGroup(config, "group2", "pipeline4", "stage1A", "job1A1");
GoDashboardPipeline pipeline4 = pipeline("pipeline4", "group2");
PipelineConfig pipelineConfig3 = configMother.addPipelineWithGroup(config, "group2", "pipeline3", "stage1A", "job1A1");
GoDashboardPipeline pipeline3 = pipeline("pipeline3", "group2");
PipelineConfig pipelineConfig2 = configMother.addPipelineWithGroup(config, "group1", "pipeline2", "stage1A", "job1A1");
GoDashboardPipeline pipeline2 = pipeline("pipeline2", "group1");
PipelineConfig pipelineConfig1 = configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1A", "job1A1");
GoDashboardPipeline pipeline1 = pipeline("pipeline1", "group1");
addPipelinesToCache(pipeline1, pipeline2, pipeline3, pipeline4);
when(pipelineSelections.includesPipeline(pipelineConfig1)).thenReturn(true);
when(pipelineSelections.includesPipeline(pipelineConfig2)).thenReturn(false);
when(pipelineSelections.includesPipeline(pipelineConfig3)).thenReturn(true);
when(pipelineSelections.includesPipeline(pipelineConfig4)).thenReturn(false);
List<GoDashboardPipelineGroup> pipelineGroups = allPipelineGroupsForDashboard(pipelineSelections, new Username("user1"));
assertThat(pipelineGroups.size(), is(2));
assertThat(pipelineGroups.get(0).allPipelineNames(), contains("pipeline1"));
assertThat(pipelineGroups.get(0).allPipelines(), contains(pipeline1));
assertThat(pipelineGroups.get(1).allPipelineNames(), contains("pipeline3"));
assertThat(pipelineGroups.get(1).allPipelines(), contains(pipeline3));
}
use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.
the class GoDashboardServiceTest method allPipelineGroupsForDashboard_shouldNotListEmptyPipelineGroup.
@Test
public void allPipelineGroupsForDashboard_shouldNotListEmptyPipelineGroup() throws Exception {
PipelineSelections pipelineSelections = mock(PipelineSelections.class);
configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1A", "job1A1");
when(pipelineSelections.includesPipeline(any(PipelineConfig.class))).thenReturn(true);
List<GoDashboardPipelineGroup> pipelineGroups = allPipelineGroupsForDashboard(pipelineSelections, new Username("user1"));
assertThat(pipelineGroups.size(), is(0));
}
Aggregations