urn_perun_user_attribute_def_def_vsupMail extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute) throws WrongAttributeValueException { if (attribute.getValue() != null) { Matcher emailMatcher = emailPattern.matcher(attribute.valueAsString()); if (!emailMatcher.find()) throw new WrongAttributeValueException(attribute, user, "School mail is not in a correct form: \"login@vsup.cz\"."); } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute); @Override List<String> getDependencies(); @Override void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute); @Override AttributeDefinition getAttributeDefinition(); static final Pattern emailPattern; static final String usedMailsUrn; static final String usedMailsKeyVsup; static final String vsupMailUrn; static final String vsupMailAliasUrn; static final String vsupMailAliasesUrn; static final String vsupPreferredMailUrn; }
@Test(expected = WrongAttributeValueException.class) public void testSyntaxWithIncorrectEmail() throws Exception { System.out.println("testSyntaxWithIncorrectEmail()"); attributeToCheck.setValue("bad@example"); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); attributeToCheck.setValue("example@vsup.cz"); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }