Search in sources :

Example 1 with PipelineSelections

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

the class GoConfigService method updateUserPipelineSelections.

public void updateUserPipelineSelections(String id, Long userId, CaseInsensitiveString pipelineToAdd) {
    PipelineSelections currentSelections = findOrCreateCurrentPipelineSelectionsFor(id, userId);
    if (!currentSelections.isBlacklist()) {
        currentSelections.addPipelineToSelections(pipelineToAdd);
        pipelineRepository.saveSelectedPipelines(currentSelections);
    }
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections)

Example 2 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 3 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 4 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 5 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)

Aggregations

PipelineSelections (com.thoughtworks.go.server.domain.user.PipelineSelections)57 Test (org.junit.Test)37 DateTime (org.joda.time.DateTime)12 User (com.thoughtworks.go.domain.User)8 Date (java.util.Date)8 Username (com.thoughtworks.go.server.domain.Username)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 BaseMatcher (org.hamcrest.BaseMatcher)4 Description (org.hamcrest.Description)4 GoDashboardPipelineGroup (com.thoughtworks.go.server.dashboard.GoDashboardPipelineGroup)3 Test (org.junit.jupiter.api.Test)3 PipelineSelectionResponse (com.thoughtworks.go.apiv1.pipelineselection.representers.PipelineSelectionResponse)2 PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)2 GoDashboardEnvironment (com.thoughtworks.go.server.dashboard.GoDashboardEnvironment)2 DashboardFilter (com.thoughtworks.go.server.domain.user.DashboardFilter)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 DashboardFor (com.thoughtworks.go.apiv2.dashboard.representers.DashboardFor)1 DashboardFor (com.thoughtworks.go.apiv3.dashboard.representers.DashboardFor)1 DashboardFor (com.thoughtworks.go.apiv4.dashboard.representers.DashboardFor)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1