use of com.thoughtworks.go.server.domain.Username 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.Username in project gocd by gocd.
the class PipelineStagesFeedServiceTest method setUp.
@Before
public void setUp() throws Exception {
user = new Username(new CaseInsensitiveString("barrow"));
expected = new FeedEntries();
stageService = mock(StageService.class);
securityService = mock(SecurityService.class);
operationResult = new HttpLocalizedOperationResult();
pipelineStagesFeedResolver = new PipelineStagesFeedService(stageService, securityService).feedResolverFor("cruise");
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineUnlockApiServiceTest method unlockShouldSetResultToNotAcceptableWhenAPipelineInstanceIsCurrentlyRunning.
@Test
public void unlockShouldSetResultToNotAcceptableWhenAPipelineInstanceIsCurrentlyRunning() throws Exception {
when(securityService.hasOperatePermissionForPipeline(new CaseInsensitiveString("username"), "pipeline-name")).thenReturn(true);
when(goConfigService.hasPipelineNamed(new CaseInsensitiveString("pipeline-name"))).thenReturn(true);
when(goConfigService.isLockable("pipeline-name")).thenReturn(true);
StageIdentifier identifier = new StageIdentifier("pipeline-name", 10, "10", "stage", "1");
when(pipelineLockService.lockedPipeline("pipeline-name")).thenReturn(identifier);
when(currentActivityService.isAnyStageActive(identifier.pipelineIdentifier())).thenReturn(true);
HttpOperationResult result = new HttpOperationResult();
pipelineUnlockApiService.unlock("pipeline-name", new Username(new CaseInsensitiveString("username")), result);
assertThat(result.httpCode(), is(409));
assertThat(result.message(), is("Locked pipeline instance is currently running (one of the stages is in progress)"));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineUnlockApiServiceTest method unlockShouldSetResultToNotAcceptableWhenNoPipelineInstanceIsCurrentlyLocked.
@Test
public void unlockShouldSetResultToNotAcceptableWhenNoPipelineInstanceIsCurrentlyLocked() throws Exception {
Mockito.when(securityService.hasOperatePermissionForPipeline(new CaseInsensitiveString("username"), "pipeline-name")).thenReturn(true);
Mockito.when(goConfigService.hasPipelineNamed(new CaseInsensitiveString("pipeline-name"))).thenReturn(true);
Mockito.when(goConfigService.isLockable("pipeline-name")).thenReturn(true);
Mockito.when(pipelineLockService.lockedPipeline("pipeline-name")).thenReturn(null);
HttpOperationResult result = new HttpOperationResult();
pipelineUnlockApiService.unlock("pipeline-name", new Username(new CaseInsensitiveString("username")), result);
assertThat(result.httpCode(), is(409));
assertThat(result.message(), is("Lock exists within the pipeline configuration but no pipeline instance is currently in progress"));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PluginServiceTest method shouldNotSavePluginSettingsIfPluginDoesNotExist.
@Test
public void shouldNotSavePluginSettingsIfPluginDoesNotExist() {
PluginSettings pluginSettings = new PluginSettings("non-existent-plugin");
Username currentUser = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(securityService.isUserAdmin(currentUser)).thenReturn(true);
for (GoPluginExtension extension : extensions) {
when(extension.canHandlePlugin("non-existent-plugin")).thenReturn(false);
}
pluginService.savePluginSettings(currentUser, result, pluginSettings);
assertThat(result.httpCode(), is(422));
assertThat(result.toString(), containsString("Plugin 'non-existent-plugin' does not exist or does not implement settings validation"));
}
Aggregations