WorkspaceValidator { public void validateAttributes(Map<String, String> attributes) throws ValidationException { for (String attributeName : attributes.keySet()) { check( attributeName != null && !attributeName.trim().isEmpty() && !attributeName.toLowerCase().startsWith("codenvy"), "Attribute name '%s' is not valid", attributeName); } for (WorkspaceAttributeValidator attributeValidator : attributeValidators) { attributeValidator.validate(attributes); } } @Inject  WorkspaceValidator(Set<WorkspaceAttributeValidator> attributeValidators); void validateConfig(WorkspaceConfig config); void validateAttributes(Map<String, String> attributes); void validateUpdateAttributes(Map<String, String> existing, Map<String, String> update);  }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Attribute name 'null' is not valid") public void shouldFailValidationIfAttributeNameIsNull() throws Exception { Map<String, String> attributes = new HashMap<>(); attributes.put(null, "value1"); wsValidator.validateAttributes(attributes); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Attribute name '' is not valid") public void shouldFailValidationIfAttributeNameIsEmpty() throws Exception { wsValidator.validateAttributes(ImmutableMap.of("", "value1")); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Attribute name 'codenvy_key' is not valid") public void shouldFailValidationIfAttributeNameStartsWithWordCodenvy() throws Exception { wsValidator.validateAttributes(ImmutableMap.of("codenvy_key", "value1")); }