urn_perun_group_attribute_def_def_fromEmail extends GroupAttributesModuleAbstract implements GroupAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, Group group, Attribute attribute) throws WrongAttributeValueException { if (attribute.getValue() == null) return; if (!(attribute.getValue() instanceof String)) throw new WrongAttributeValueException(attribute, "Wrong type of the attribute. Expected: String"); String fromEmail = attribute.valueAsString(); if (!(sess.getPerunBl().getModulesUtilsBl().isNameOfEmailValid(sess, fromEmail))){ Matcher match = pattern.matcher(fromEmail); if (!match.matches()) { throw new WrongAttributeValueException(attribute, "Group : " + group.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, "Group : " + group.getName() +" has email in <> " + emailParts[1] +" which is not valid."); } } } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, Group group, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testWrongTypeOfValue() throws Exception { System.out.println("testWrongTypeOfValue()"); attributeToCheck.setValue(1); classInstance.checkAttributeSyntax(sess, group, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); String correctValue = "my@example.com"; when(modulesUtilsBl.isNameOfEmailValid(sess, correctValue)).thenReturn(true); String correctValue2 = "\"my example\" <my@example.com>"; when(modulesUtilsBl.isNameOfEmailValid(sess, correctValue2)).thenReturn(true); attributeToCheck.setValue(correctValue); classInstance.checkAttributeSyntax(sess, group, attributeToCheck); attributeToCheck.setValue(correctValue2); classInstance.checkAttributeSyntax(sess, group, attributeToCheck); }