Search in sources :

Example 86 with Username

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));
}
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 87 with Username

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");
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Example 88 with Username

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)"));
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 89 with Username

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"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 90 with Username

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"));
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10