Search in sources :

Example 66 with Username

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

the class EnvironmentConfigServiceTest method shouldReturnResultWithMessageThatConfigisUpdated_WhenUpdatingLatestConfiguration_NewUpdateEnvironmentMethod.

@Test
public void shouldReturnResultWithMessageThatConfigisUpdated_WhenUpdatingLatestConfiguration_NewUpdateEnvironmentMethod() {
    String environmentName = "env_name";
    EnvironmentConfig environmentConfig = new BasicEnvironmentConfig(new CaseInsensitiveString(environmentName));
    Username user = new Username(new CaseInsensitiveString("user"));
    when(securityService.isUserAdmin(user)).thenReturn(true);
    when(mockGoConfigService.updateConfig(any(UpdateConfigCommand.class))).thenReturn(ConfigSaveState.UPDATED);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String md5 = "md5";
    environmentConfigService.updateEnvironment(environmentConfig.name().toString(), environmentConfig, user, md5, result);
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("UPDATE_ENVIRONMENT_SUCCESS"));
    assertThat(result.toString(), containsString(environmentName));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 67 with Username

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

the class EnvironmentConfigServiceTest method getAllLocalPipelinesForUser_shouldReturnOnlyLocalPipelines.

@Test
public void getAllLocalPipelinesForUser_shouldReturnOnlyLocalPipelines() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(mockGoConfigService.getAllLocalPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
    when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
    environmentConfigService.sync(environmentsConfig("foo-env", "foo"));
    List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllLocalPipelinesForUser(user);
    assertThat(pipelines.size(), is(2));
    assertThat(pipelines, is(asList(new EnvironmentPipelineModel("bar"), new EnvironmentPipelineModel("foo", "foo-env"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel) Test(org.junit.Test)

Example 68 with Username

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

the class EnvironmentConfigServiceTest method getAllRemotePipelinesForUserInEnvironment_shouldReturnOnlyRemotelyAssignedPipelinesWhichUserHasPermsToView.

@Test
public void getAllRemotePipelinesForUserInEnvironment_shouldReturnOnlyRemotelyAssignedPipelinesWhichUserHasPermsToView() throws NoSuchEnvironmentException {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(mockGoConfigService.getAllPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
    when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
    EnvironmentsConfig environmentConfigs = environmentsConfig("foo-env", "foo");
    EnvironmentConfig fooEnv = environmentConfigs.named(new CaseInsensitiveString("foo-env"));
    fooEnv.setOrigins(new RepoConfigOrigin());
    environmentConfigService.sync(environmentConfigs);
    List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllRemotePipelinesForUserInEnvironment(user, fooEnv);
    assertThat(pipelines.size(), is(1));
    assertThat(pipelines, is(asList(new EnvironmentPipelineModel("foo", "foo-env"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 69 with Username

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

the class EnvironmentConfigServiceTest method getAllLocalPipelinesForUser_shouldReturnAllPipelinesToWhichAlongWithTheEnvironmentsToWhichTheyBelong.

@Test
public void getAllLocalPipelinesForUser_shouldReturnAllPipelinesToWhichAlongWithTheEnvironmentsToWhichTheyBelong() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(mockGoConfigService.getAllLocalPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
    when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
    environmentConfigService.sync(environmentsConfig("foo-env", "foo"));
    List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllLocalPipelinesForUser(user);
    assertThat(pipelines.size(), is(2));
    assertThat(pipelines, is(asList(new EnvironmentPipelineModel("bar"), new EnvironmentPipelineModel("foo", "foo-env"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel) Test(org.junit.Test)

Example 70 with Username

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

the class EnvironmentServiceTest method stubPipelineHistoryServiceToReturnPipelines.

private PipelineInstanceModel stubPipelineHistoryServiceToReturnPipelines(final String pipelineName) {
    PipelineInstanceModel pipelineInstanceModel = PipelineInstanceModel.createPipeline(pipelineName, -1, "1", BuildCause.createManualForced(), new StageInstanceModels());
    PipelineModel pipelineModel = new PipelineModel(pipelineInstanceModel.getName(), true, true, PipelinePauseInfo.notPaused());
    pipelineModel.addPipelineInstance(pipelineInstanceModel);
    when(pipelineHistoryService.latestPipelineModel(new Username(new CaseInsensitiveString("Foo")), pipelineName)).thenReturn(pipelineModel);
    return pipelineInstanceModel;
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel)

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