urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongAttributeValueException { log.trace("checkAttributeSyntax(resource={},group={},attribute={})", resource, group, attribute); List<String> emails = attribute.valueAsList(); if (emails == null) return; for (String email : emails) { Matcher emailMatcher = emailPattern.matcher(email); if (!emailMatcher.matches()) throw new WrongAttributeValueException(attribute, resource, group, "Email " + email + " is not in correct form."); Matcher ucoEmailMatcher = ucoEmailPattern.matcher(email); if (ucoEmailMatcher.matches()) throw new WrongAttributeValueException(attribute, resource, group, "Email " + email + " is based on UCO which is not supported."); } if (hasDuplicate(emails)) { throw new WrongAttributeValueException(attribute, resource, group, "duplicate values"); } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute); @Override Attribute fillAttribute(PerunSessionImpl sess, Group group, Resource resource, AttributeDefinition attrDef); @Override List<String> getDependencies(); @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, group, resource, 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, group, resource, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testUcoEmail() throws Exception { System.out.println("testUcoEmail"); when(adNameAttr.getValue()).thenReturn(null); when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session),any(Attribute.class))).thenReturn(Sets.newHashSet()); attributeToCheck.setValue(Lists.newArrayList("451570@muni.cz")); classInstance.checkAttributeSyntax(session, group, resource, attributeToCheck); }