Search in sources :

Example 41 with PipelineSelections

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

Example 42 with PipelineSelections

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) {
        }
    };
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher)

Example 43 with PipelineSelections

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

Example 44 with PipelineSelections

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

Example 45 with PipelineSelections

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));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Username(com.thoughtworks.go.server.domain.Username) 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