@Test public void shouldReturnTheCorrectLocalizedMessageForDuplicatePipelinesInAnEnvironment() { BasicEnvironmentConfig environmentConfig = environmentConfig("uat"); goConfigService.addPipeline( PipelineConfigMother.createPipelineConfig("foo", "dev", "job"), "foo-grp"); environmentConfig.addPipeline(new CaseInsensitiveString("foo")); goConfigService.addEnvironment(environmentConfig); ArrayList<String> pipelines = new ArrayList<>(); pipelines.add("foo"); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); service.createEnvironment( env("foo-env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("any")), result); result = new HttpLocalizedOperationResult(); service.createEnvironment( env("env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("any")), result); assertThat( result.message(localizer), is( "Failed to add environment. Associating pipeline(s) which is already part of uat environment")); }
@Test public void shouldReturnBadRequestForInvalidEnvName() { HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); service.createEnvironment( env( "foo env", new ArrayList<String>(), new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("any")), result); assertThat(result.httpCode(), is(HttpServletResponse.SC_BAD_REQUEST)); assertThat(result.message(localizer), containsString("Failed to add environment.")); }
@Test public void shouldReturnTheCorrectLocalizedMessageForDuplicateEnvironment() { configHelper.addEnvironments("foo-env"); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); service.createEnvironment( env( "foo-env", new ArrayList<String>(), new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("any")), result); assertThat( result.message(localizer), is("Failed to add environment. Environment 'foo-env' already exists.")); }
@Test public void shouldReturnTheCorrectLocalizedMessageForNoPermission() throws IOException { configHelper.turnOnSecurity(); configHelper.addAdmins("super_hero"); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); service.createEnvironment( env( "foo-env", new ArrayList<String>(), new ArrayList<Map<String, String>>(), new ArrayList<String>()), new Username(new CaseInsensitiveString("evil_hacker")), result); assertThat( result.message(localizer), is( "Failed to add environment. User 'evil_hacker' does not have permission to add environments")); }