Search in sources :

Example 61 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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 62 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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 63 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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 64 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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 65 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class FailureServiceTest method setUp.

@Before
public void setUp() {
    shineDao = mock(ShineDao.class);
    securityService = mock(SecurityService.class);
    stageFinder = mock(StageFinder.class);
    failureService = new FailureService(securityService, shineDao, stageFinder);
    username = new Username(new CaseInsensitiveString("foo"));
    jobIdentifier = new JobIdentifier(new StageIdentifier("pipeline", 10, "stage", "5"), "job");
    result = new HttpLocalizedOperationResult();
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ShineDao(com.thoughtworks.go.server.dao.sparql.ShineDao) Username(com.thoughtworks.go.server.domain.Username) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) StageFinder(com.thoughtworks.go.domain.StageFinder) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)437 Test (org.junit.Test)394 Username (com.thoughtworks.go.server.domain.Username)168 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)41 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)26 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)24 Pipeline (com.thoughtworks.go.domain.Pipeline)24 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 GoCipher (com.thoughtworks.go.security.GoCipher)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)15 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14