Search in sources :

Example 6 with PipelineSelections

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

the class PipelineHistoryServiceTest method allActivePipelines_shouldOnlyKeepSelectedPipelines_andRemove_EmptyGroups.

@Test
public void allActivePipelines_shouldOnlyKeepSelectedPipelines_andRemove_EmptyGroups() {
    Username foo = new Username(new CaseInsensitiveString("foo"));
    CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    PipelineInstanceModels activePipelineInstances = createPipelineInstanceModels(activePipeline("pipeline1", 1, 1.0), activePipeline("pipeline2", 1, 1.0), activePipeline("pipeline4", 1, 1.0), activePipeline("non-operatable-pipeline", 1, 1.0));
    for (String pipeline : new String[] { "pipeline1", "pipeline2", "pipeline3", "pipeline4", "non-operatable-pipeline" }) {
        stubPermisssionsForActivePipeline(foo, cruiseConfig, pipeline, true, true);
        when(pipelineDao.loadHistory(pipeline, 1, 0)).thenReturn(createPipelineInstanceModels());
    }
    when(pipelineDao.loadActivePipelines()).thenReturn(activePipelineInstances);
    when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
    List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(foo, new PipelineSelections(Arrays.asList("non-operatable-pipeline")));
    assertThat(groups.size(), is(1));
    assertThat(groups.get(0).getName(), is("defaultGroup"));
    assertThat(groups.get(0).containsPipeline("pipeline1"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline2"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline3"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline4"), is(true));
}
Also used : PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 7 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 8 with PipelineSelections

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

the class PipelineRepositoryIntegrationTest method shouldSaveSelectedPipelinesWithoutUserId.

@Test
public void shouldSaveSelectedPipelinesWithoutUserId() {
    Date date = new Date();
    List<String> unSelected = Arrays.asList("pipeline1", "pipeline2");
    long id = pipelineRepository.saveSelectedPipelines(new PipelineSelections(unSelected, date, null, true));
    PipelineSelections found = pipelineRepository.findPipelineSelectionsById(id);
    assertHasPipelines(found, new String[] { "pipeline3", "pipeline4" });
    assertHasPipelines(found, new String[] { "pipeline1", "pipeline2" }, false);
    assertThat(found.userId(), is(nullValue()));
    assertEquals(date, found.lastUpdated());
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Date(java.util.Date) Test(org.junit.Test)

Example 9 with PipelineSelections

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

the class PipelineRepositoryIntegrationTest method shouldSaveSelectedPipelinesWithBlacklistPreferenceTrue.

@Test
public void shouldSaveSelectedPipelinesWithBlacklistPreferenceTrue() {
    User user = createUser();
    List<String> unSelected = Arrays.asList("pipeline1", "pipeline2");
    long id = pipelineRepository.saveSelectedPipelines(new PipelineSelections(unSelected, new Date(), user.getId(), true));
    assertThat(pipelineRepository.findPipelineSelectionsById(id).isBlacklist(), is(true));
}
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 10 with PipelineSelections

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

the class PipelineRepositoryIntegrationTest method shouldSaveSelectedPipelinesWithBlacklistPreferenceFalse.

@Test
public void shouldSaveSelectedPipelinesWithBlacklistPreferenceFalse() {
    User user = createUser();
    List<String> unSelected = Arrays.asList("pipeline1", "pipeline2");
    long id = pipelineRepository.saveSelectedPipelines(new PipelineSelections(unSelected, new Date(), user.getId(), false));
    assertThat(pipelineRepository.findPipelineSelectionsById(id).isBlacklist(), is(false));
}
Also used : User(com.thoughtworks.go.domain.User) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Date(java.util.Date) 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