Search in sources :

Example 51 with PipelineSelections

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));
}
Also used : User(com.thoughtworks.go.domain.User) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Test(org.junit.Test)

Example 52 with PipelineSelections

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")));
}
Also used : User(com.thoughtworks.go.domain.User) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Test(org.junit.Test)

Example 53 with PipelineSelections

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));
}
Also used : User(com.thoughtworks.go.domain.User) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Test(org.junit.Test)

Example 54 with PipelineSelections

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));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 55 with PipelineSelections

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")));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Test(org.junit.Test)

Aggregations

PipelineSelections (com.thoughtworks.go.server.domain.user.PipelineSelections)57 Test (org.junit.Test)44 DateTime (org.joda.time.DateTime)12 Username (com.thoughtworks.go.server.domain.Username)9 User (com.thoughtworks.go.domain.User)8 Date (java.util.Date)8 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)5 BaseMatcher (org.hamcrest.BaseMatcher)4 Description (org.hamcrest.Description)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 Permissions (com.thoughtworks.go.config.security.Permissions)2 PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 PipelineSelectionResponse (com.thoughtworks.go.apiv1.pipelineselection.representers.PipelineSelectionResponse)1 DashboardFor (com.thoughtworks.go.apiv2.dashboard.representers.DashboardFor)1 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)1 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)1 GoDashboardPipelineGroup (com.thoughtworks.go.server.dashboard.GoDashboardPipelineGroup)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1