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));
}
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));
}
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));
}
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)));
}
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)));
}
Aggregations