Search in sources :

Example 11 with PipelineSelections

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

the class GoConfigServiceTest method shouldPersistInvertedListOfPipelineSelections_WhenBlacklistIsSelected.

@Test
public void shouldPersistInvertedListOfPipelineSelections_WhenBlacklistIsSelected() {
    Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
    when(clock.currentTime()).thenReturn(date);
    mockConfigWithSecurity();
    User user = getUser("badger", 10L);
    PipelineSelections blacklistPipelineSelections = new PipelineSelections(new ArrayList<>(), date, user.getId(), false);
    when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(blacklistPipelineSelections);
    goConfigService.persistSelectedPipelines(null, user.getId(), Arrays.asList("pipelineX", "pipeline3"), true);
    verify(pipelineRepository).saveSelectedPipelines(argThat(isAPipelineSelectionsInstanceWith(true, "pipeline1", "pipeline2")));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with PipelineSelections

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

the class GoConfigServiceTest method shouldReturnPersistedPipelineSelectionsAgainstUser_WhenSecurityIsEnabled.

@Test
public void shouldReturnPersistedPipelineSelectionsAgainstUser_WhenSecurityIsEnabled() {
    User loser = getUser("loser", 10L);
    User newUser = getUser("new user", 20L);
    when(userDao.findUser("new user")).thenReturn(newUser);
    mockConfigWithSecurity();
    PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pip1"));
    when(pipelineRepository.findPipelineSelectionsByUserId(loser.getId())).thenReturn(pipelineSelections);
    assertThat(goConfigService.getSelectedPipelines("1", loser.getId()), is(pipelineSelections));
    assertThat(goConfigService.getSelectedPipelines("1", newUser.getId()), is(PipelineSelections.ALL));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Test(org.junit.Test)

Example 13 with PipelineSelections

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

the class GoConfigServiceTest method shouldPersistPipelineSelectionsAgainstUser_AlreadyHavingSelections.

@Test
public void shouldPersistPipelineSelectionsAgainstUser_AlreadyHavingSelections() {
    Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
    when(clock.currentTime()).thenReturn(date);
    mockConfigWithSecurity();
    User user = getUser("badger", 10L);
    PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pipeline2"), new Date(), user.getId(), true);
    when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(pipelineSelections);
    when(pipelineRepository.saveSelectedPipelines(pipelineSelections)).thenReturn(2L);
    long pipelineSelectionId = goConfigService.persistSelectedPipelines("1", user.getId(), Arrays.asList("pipelineX", "pipeline3"), true);
    assertThat(pipelineSelections.getSelections(), is("pipeline1,pipeline2"));
    assertThat(pipelineSelectionId, is(2l));
    verify(pipelineRepository).saveSelectedPipelines(pipelineSelections);
    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 14 with PipelineSelections

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

the class GoConfigServiceTest method isAPipelineSelectionsInstanceWith.

private Matcher<PipelineSelections> isAPipelineSelectionsInstanceWith(final boolean isBlacklist, final String... pipelineSelectionsInInstance) {
    return new BaseMatcher<PipelineSelections>() {

        public boolean matches(Object o) {
            PipelineSelections pipelineSelections = (PipelineSelections) o;
            assertThat(pipelineSelections.isBlacklist(), is(isBlacklist));
            List<String> expectedSelectionsAsList = Arrays.asList(pipelineSelectionsInInstance);
            assertEquals(pipelineSelections.getSelections(), ListUtil.join(expectedSelectionsAsList, ","));
            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) StringContains.containsString(org.hamcrest.core.StringContains.containsString)

Example 15 with PipelineSelections

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

the class GoConfigServiceTest method shouldPersistNonInvertedListOfPipelineSelections_WhenWhitelistIsSelected.

@Test
public void shouldPersistNonInvertedListOfPipelineSelections_WhenWhitelistIsSelected() {
    Date date = new DateTime(2000, 1, 1, 1, 1, 1, 1).toDate();
    when(clock.currentTime()).thenReturn(date);
    mockConfigWithSecurity();
    User user = getUser("badger", 10L);
    PipelineSelections whitelistPipelineSelections = new PipelineSelections(new ArrayList<>(), date, user.getId(), true);
    when(pipelineRepository.findPipelineSelectionsByUserId(user.getId())).thenReturn(whitelistPipelineSelections);
    goConfigService.persistSelectedPipelines(null, user.getId(), Arrays.asList("pipelineX", "pipeline3"), false);
    verify(pipelineRepository).saveSelectedPipelines(argThat(isAPipelineSelectionsInstanceWith(false, "pipelineX", "pipeline3")));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

PipelineSelections (com.thoughtworks.go.server.domain.user.PipelineSelections)30 Test (org.junit.Test)24 Date (java.util.Date)6 DateTime (org.joda.time.DateTime)6 User (com.thoughtworks.go.domain.User)4 Username (com.thoughtworks.go.server.domain.Username)3 PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matchers.anyString (org.mockito.Matchers.anyString)1