urn_perun_resource_attribute_def_def_vomsRoles extends ResourceAttributesModuleAbstract implements ResourceAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws WrongAttributeValueException { if(attribute.getValue() == null) { return; } try { List<String> vomRoles = attribute.valueAsList(); for (String vomRole : vomRoles) { Matcher matcher = pattern.matcher(vomRole); if(!matcher.matches()) { throw new WrongAttributeValueException(attribute, resource, "Bad resource vomsRoles value. It should not contain '<>&' characters."); } } } catch (ClassCastException e) { throw new WrongAttributeValueException(attribute, "Value should be a list of Strings."); } }  @Override void checkAttributeSyntax(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testSyntaxWithWrongValue() throws Exception { System.out.println("testSyntaxWithWrongValue()"); List<String> value = new ArrayList<>(); value.add("bad&example"); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(sess, resource, attributeToCheck); }
@Test public void testSyntaxCorrect() throws Exception { System.out.println("testSyntaxCorrect()"); List<String> value = new ArrayList<>(); value.add("example"); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(sess, resource, attributeToCheck); }