Search in sources :

Example 21 with PipelineSelections

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

the class PipelineRepositoryIntegrationTest method shouldFindSelectedPipelinesByUserId.

@Test
public void shouldFindSelectedPipelinesByUserId() {
    User user = createUser();
    List<String> unSelected = Arrays.asList("pipeline1", "pipeline2");
    long id = pipelineRepository.saveSelectedPipelines(new PipelineSelections(unSelected, new Date(), user.getId(), true));
    assertThat(pipelineRepository.findPipelineSelectionsByUserId(user.getId()).getId(), is(id));
}
Also used : User(com.thoughtworks.go.domain.User) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Date(java.util.Date) Test(org.junit.Test)

Example 22 with PipelineSelections

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

the class GoConfigService method persistSelectedPipelines.

public long persistSelectedPipelines(String id, Long userId, List<String> selectedPipelines, boolean isBlacklist) {
    PipelineSelections pipelineSelections = findOrCreateCurrentPipelineSelectionsFor(id, userId);
    if (isBlacklist) {
        List<String> unselectedPipelines = invertSelections(selectedPipelines);
        pipelineSelections.update(unselectedPipelines, clock.currentTime(), userId, isBlacklist);
    } else {
        pipelineSelections.update(selectedPipelines, clock.currentTime(), userId, isBlacklist);
    }
    return pipelineRepository.saveSelectedPipelines(pipelineSelections);
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections)

Example 23 with PipelineSelections

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

the class GoConfigServiceTest method shouldNotUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithBlacklist.

@Test
public void shouldNotUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithBlacklist() {
    when(pipelineRepository.findPipelineSelectionsById("1")).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, true));
    goConfigService.updateUserPipelineSelections("1", null, new CaseInsensitiveString("pipelineNew"));
    verify(pipelineRepository).findPipelineSelectionsById("1");
    verify(pipelineRepository, times(0)).saveSelectedPipelines(argThat(Matchers.any(PipelineSelections.class)));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Test(org.junit.Test)

Example 24 with PipelineSelections

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

the class GoConfigServiceTest method shouldUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithWhitelist.

@Test
public void shouldUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithWhitelist() {
    mockConfigWithSecurity();
    when(pipelineRepository.findPipelineSelectionsByUserId(1L)).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, false));
    goConfigService.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)

Example 25 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)

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