urn_perun_vo_attribute_def_def_fromEmail extends VoAttributesModuleAbstract implements VoAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, Vo vo, Attribute attribute) throws WrongAttributeValueException { if (attribute.getValue() == null) return; String fromEmail = attribute.valueAsString(); if (!(sess.getPerunBl().getModulesUtilsBl().isNameOfEmailValid(sess, fromEmail))){ Matcher match = pattern.matcher(fromEmail); if (!match.matches()) { throw new WrongAttributeValueException(attribute, "Vo : " + vo.getName() + " has fromEmail " + fromEmail + " which is not valid. It has to be in form \"header\" <correct email> or just correct email."); }else{ String[] emailParts = fromEmail.split("[<>]+"); if (!(sess.getPerunBl().getModulesUtilsBl().isNameOfEmailValid(sess, emailParts[1]))){ throw new WrongAttributeValueException(attribute, "Vo : " + vo.getName() +" has email in <> " + emailParts[1] +" which is not valid."); } } } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, Vo vo, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Vo vo, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckValueWithIncorrectEmail() throws Exception { System.out.println("testCheckValueWithIncorrectEmail()"); attributeToCheck.setValue(incorrectEmail); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckValueWithIncorrectHeader() throws Exception { System.out.println("testCheckValueWithIncorrectHeader()"); attributeToCheck.setValue(correctEmailWithIncorrectHeader); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); attributeToCheck.setValue(correctEmail); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); attributeToCheck.setValue(correctEmailWithHeader); classInstance.checkAttributeSyntax(session, vo, attributeToCheck); }