Search in sources :

Example 26 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 27 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 28 with PipelineSelections

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

the class GoConfigServiceTest method shouldUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithWhitelist.

@Test
public void shouldUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithWhitelist() {
    when(pipelineRepository.findPipelineSelectionsById("1")).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, false));
    goConfigService.updateUserPipelineSelections("1", null, new CaseInsensitiveString("pipelineNew"));
    verify(pipelineRepository).findPipelineSelectionsById("1");
    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 29 with PipelineSelections

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

the class GoConfigServiceTest method shouldNotUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithBlacklist.

@Test
public void shouldNotUpdatePipelineSelectionsWhenTheUserIsLoggedIn_WithBlacklist() {
    mockConfigWithSecurity();
    when(pipelineRepository.findPipelineSelectionsByUserId(1L)).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, true));
    goConfigService.updateUserPipelineSelections(null, 1L, new CaseInsensitiveString("pipelineNew"));
    verify(pipelineRepository).findPipelineSelectionsByUserId(1L);
    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 30 with PipelineSelections

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

the class GoConfigServiceTest method shouldReturnPersistedPipelineSelectionsAgainstCookieId_WhenSecurityisDisabled.

@Test
public void shouldReturnPersistedPipelineSelectionsAgainstCookieId_WhenSecurityisDisabled() {
    PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pip1"));
    when(pipelineRepository.findPipelineSelectionsById("123")).thenReturn(pipelineSelections);
    assertThat(goConfigService.getSelectedPipelines("123", null), is(pipelineSelections));
    assertThat(goConfigService.getSelectedPipelines("", null), is(PipelineSelections.ALL));
    assertThat(goConfigService.getSelectedPipelines("345", null), is(PipelineSelections.ALL));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) 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