Search in sources :

Example 16 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 17 with PipelineSelections

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

the class PipelineHistoryServiceTest method allActivePipelines_shouldRemove_EmptyGroups.

@Test
public void allActivePipelines_shouldRemove_EmptyGroups() {
    Username bar = new Username(new CaseInsensitiveString("non-existant"));
    CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(pipelineDao.loadActivePipelines()).thenReturn(createPipelineInstanceModels());
    when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
    List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(bar, new PipelineSelections());
    assertThat(groups.isEmpty(), is(true));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 18 with PipelineSelections

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

the class PipelineHistoryServiceTest method allActivePipelines_shouldOnlyKeepSelectedPipelines.

@Test
public void allActivePipelines_shouldOnlyKeepSelectedPipelines() {
    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("pipeline1", "pipeline2")));
    assertThat(groups.size(), is(2));
    assertThat(groups.get(0).getName(), is("defaultGroup"));
    assertThat(groups.get(0).containsPipeline("pipeline1"), is(false));
    assertThat(groups.get(0).containsPipeline("pipeline2"), is(false));
    assertThat(groups.get(0).containsPipeline("pipeline3"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline4"), is(true));
    assertThat(groups.get(1).getName(), is("foo"));
    assertThat(groups.get(1).containsPipeline("non-operatable-pipeline"), 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 19 with PipelineSelections

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

the class PipelineSelectionsServiceTest method shouldNotUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithBlacklist.

@Test
public void shouldNotUpdatePipelineSelectionsWhenTheUserIsAnonymousAndHasSelectedPipelines_WithBlacklist() {
    when(pipelineRepository.findPipelineSelectionsById("1")).thenReturn(new PipelineSelections(Arrays.asList("pipeline1", "pipeline2"), null, null, true));
    pipelineSelectionsService.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 20 with PipelineSelections

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

the class PipelineSelectionsServiceTest 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);
    when(goConfigService.getAllPipelineConfigs()).thenReturn(Arrays.asList(pipelineConfig("pipeline1"), pipelineConfig("pipeline2"), pipelineConfig("pipelineX"), pipelineConfig("pipeline3")));
    PipelineSelections pipelineSelections = new PipelineSelections(Arrays.asList("pip1"));
    when(pipelineRepository.findPipelineSelectionsById("123")).thenReturn(pipelineSelections);
    List<String> newPipelines = Arrays.asList("pipeline1", "pipeline2");
    pipelineSelectionsService.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) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

PipelineSelections (com.thoughtworks.go.server.domain.user.PipelineSelections)57 Test (org.junit.Test)44 DateTime (org.joda.time.DateTime)12 Username (com.thoughtworks.go.server.domain.Username)9 User (com.thoughtworks.go.domain.User)8 Date (java.util.Date)8 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)5 BaseMatcher (org.hamcrest.BaseMatcher)4 Description (org.hamcrest.Description)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 Permissions (com.thoughtworks.go.config.security.Permissions)2 PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 PipelineSelectionResponse (com.thoughtworks.go.apiv1.pipelineselection.representers.PipelineSelectionResponse)1 DashboardFor (com.thoughtworks.go.apiv2.dashboard.representers.DashboardFor)1 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)1 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)1 GoDashboardPipelineGroup (com.thoughtworks.go.server.dashboard.GoDashboardPipelineGroup)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1