urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu extends UserAttributesModuleAbstract { @Override public void checkAttributeSyntax(PerunSessionImpl perunSession, User user, Attribute attribute) throws InternalErrorException, WrongAttributeValueException { if(attribute.getValue() == null) return; ArrayList<String> emails = attribute.valueAsList(); for (String email : emails) { Matcher emailMatcher = emailPattern.matcher(email); if (!emailMatcher.matches()) throw new WrongAttributeValueException(attribute, user, "Email " + email + " is not in correct form."); Matcher ucoEmailMatcher = ucoEmailPattern.matcher(email); if (ucoEmailMatcher.matches()) throw new WrongAttributeValueException(attribute, user, "Email " + email + " is based on UCO which is not supported."); } if (hasDuplicate(emails)) { throw new WrongAttributeValueException(attribute, user, "duplicate values"); } }  @Override void checkAttributeSyntax(PerunSessionImpl perunSession, User user, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckEmailSyntax() throws Exception { System.out.println("testCheckEmailSyntax()"); attributeToCheck.setValue(Lists.newArrayList("my@example.com", "a/-+")); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckUcoEmailSyntax() throws Exception { System.out.println("testCheckUcoEmailSyntax()"); attributeToCheck.setValue(Lists.newArrayList("my@example.com", "451570@muni.cz")); classInstance.checkAttributeSyntax(session, user, 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, user, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); attributeToCheck.setValue(Lists.newArrayList("my@example.com")); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }