Ejemplo n.º 1
0
 @Test
 public void shouldReturnTheCorrectLocalizedMessageWhenUserDoesNotHavePermissionToDelete()
     throws IOException, NoSuchEnvironmentException {
   configHelper.addEnvironments("foo");
   configHelper.turnOnSecurity();
   configHelper.addAdmins("super_hero");
   HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
   service.deleteEnvironment(
       service.getEnvironmentConfig("foo"),
       new Username(new CaseInsensitiveString("evil_hacker")),
       result);
   assertThat(
       result.message(localizer),
       is(
           "Failed to delete environment 'foo'. User 'evil_hacker' does not have permission to update environments"));
 }
Ejemplo n.º 2
0
  @Test
  public void shouldDeleteAnEnvironment() throws Exception {
    String environmentName = "dev";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    goConfigService.addEnvironment(
        new BasicEnvironmentConfig(new CaseInsensitiveString(environmentName)));

    assertTrue(goConfigService.hasEnvironmentNamed(new CaseInsensitiveString(environmentName)));
    service.deleteEnvironment(
        service.getEnvironmentConfig(environmentName),
        new Username(new CaseInsensitiveString("foo")),
        result);
    assertFalse(goConfigService.hasEnvironmentNamed(new CaseInsensitiveString(environmentName)));
    assertThat(
        result.message(localizer), containsString("Environment 'dev' was deleted successfully."));
  }
Ejemplo n.º 3
0
 @Test
 public void
     shouldReturnBadRequestForUpdateWhenUsingInvalidEnvName_ForNewUpdateEnvironmentMethod_ForNewUpdateEnvironmentMethod()
         throws NoSuchEnvironmentException {
   configHelper.addEnvironments("foo-env");
   HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
   service.updateEnvironment(
       service.getEnvironmentConfig("foo-env"),
       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 update environment 'foo-env'."));
 }
Ejemplo n.º 4
0
 @Test
 public void
     shouldReturnTheCorrectLocalizedMessageForUpdateWhenDuplicateEnvironmentExists_ForNewUpdateEnvironmentMethod()
         throws NoSuchEnvironmentException {
   configHelper.addEnvironments("foo-env");
   configHelper.addEnvironments("bar-env");
   HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
   service.updateEnvironment(
       service.getEnvironmentConfig("bar-env"),
       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 update environment 'bar-env'. failed to save : Duplicate unique value [foo-env] declared for identity constraint \"uniqueEnvironmentName\" of element \"environments\"."));
 }
Ejemplo n.º 5
0
  @Test
  public void
      shouldReturnTheCorrectLocalizedMessageWhenUserDoesNotHavePermissionToUpdate_ForNewUpdateEnvironmentMethod()
          throws Exception {
    configHelper.addEnvironments("foo");
    configHelper.turnOnSecurity();
    configHelper.addAdmins("super_hero");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();

    service.updateEnvironment(
        service.getEnvironmentConfig("foo"),
        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 update environment 'foo'. User 'evil_hacker' does not have permission to update environments"));
  }