urn_perun_member_attribute_def_def_o365EmailAddresses_mu extends MemberAttributesModuleAbstract { public void checkAttributeSyntax(PerunSessionImpl perunSession, Member member, Attribute attribute) throws WrongAttributeValueException { Object value = attribute.getValue(); List<String> emails; if (value == null) return; else if (!(value instanceof ArrayList)) { throw new WrongAttributeValueException(attribute, member, "is of type " + value.getClass() + ", but should be ArrayList"); } else { emails = attribute.valueAsList(); } if (hasDuplicate(emails)) { throw new WrongAttributeValueException(attribute, member, "has duplicate values"); } for (String email : emails) { Matcher emailMatcher = emailPattern.matcher(email); if (!emailMatcher.matches()) throw new WrongAttributeValueException(attribute, member, "Email " + email + " is not in correct form."); } }  void checkAttributeSyntax(PerunSessionImpl perunSession, Member member, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Member member, Attribute attribute); @Override List<String> getDependencies(); @Override Attribute fillAttribute(PerunSessionImpl sess, Member member, AttributeDefinition attrDef); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckType() throws Exception { System.out.println("testCheckType()"); attributeToCheck.setValue("AAA"); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckEmailSyntax() throws Exception { System.out.println("testCheckEmailSyntax()"); attributeToCheck.setValue(Lists.newArrayList("my@example.com", "a/-+")); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckDuplicates() throws Exception { System.out.println("testCheckDuplicates()"); attributeToCheck.setValue(Lists.newArrayList("my@example.com", "aaa@bbb.com", "my@example.com")); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); attributeToCheck.setValue(Lists.newArrayList("my@example.com", "aaa@bbb.com", uco + "@muni.cz")); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }