Search in sources :

Example 56 with PipelineSelections

use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.

the class PipelineSelectionsServiceTest 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);
    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);
    when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
    when(goConfigService.isSecurityEnabled()).thenReturn(true);
    long pipelineSelectionsId = pipelineSelectionsService.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 : User(com.thoughtworks.go.domain.User) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 57 with PipelineSelections

use of com.thoughtworks.go.server.domain.user.PipelineSelections in project gocd by gocd.

the class PipelineSelectionsServiceTest 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)

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