Exemplo n.º 1
0
  @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"));
  }
Exemplo n.º 2
0
 @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."));
 }
Exemplo n.º 3
0
 @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."));
 }
Exemplo n.º 4
0
 @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"));
 }