diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.java index 447de44759..57a69550f6 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.java @@ -51,7 +51,7 @@ public class urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu extends private final static Logger log = LoggerFactory.getLogger(urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.class); static final String ADNAME_ATTRIBUTE = AttributesManager.NS_GROUP_ATTR_DEF + ":adName:o365mu"; - static final String MEMBER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE = AttributesManager.NS_MEMBER_ATTR_DEF + ":o365EmailAddresses:mu"; + static final String USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE = AttributesManager.NS_USER_ATTR_DEF + ":o365UserEmailAddresses:mu"; @Override public void checkAttributeSyntax(PerunSessionImpl sess, Group group, Attribute attribute) throws WrongAttributeValueException { @@ -97,18 +97,18 @@ public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribut } //No need to check duplicities among other groups (attribute is unique) - //check for duplicities among members attributes and this one + //check for duplicities among users attributes and this one try { AttributesManagerBl attributesManagerBl = sess.getPerunBl().getAttributesManagerBl(); - Attribute memberO365EmailAddresses = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, MEMBER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE)); - memberO365EmailAddresses.setValue(emails); - Set> memberPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, memberO365EmailAddresses); - if (!memberPairs.isEmpty()) { - throw new WrongReferenceAttributeValueException(attribute, memberO365EmailAddresses, group, null, "member " + BeansUtils.getSingleId(memberPairs) + " "); + Attribute userO365EmailAddresses = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE)); + userO365EmailAddresses.setValue(emails); + Set> usersPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, userO365EmailAddresses); + if (!usersPairs.isEmpty()) { + throw new WrongReferenceAttributeValueException(attribute, userO365EmailAddresses, group, null, "member " + BeansUtils.getSingleId(usersPairs) + " "); } } catch(AttributeNotExistsException ex) { //If attribute not exists, we can log it and skip it, because there are no duplicates in not existing attributes - log.debug("Attribute {} not exists to check duplicities in it while checkAttributeSemantics for {}.", MEMBER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE, attribute); + log.debug("Attribute {} not exists to check duplicities in it while checkAttributeSemantics for {}.", USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE, attribute); } } /** @@ -131,7 +131,10 @@ public Attribute fillAttribute(PerunSessionImpl sess, Group group, AttributeDefi @Override public List getDependencies() { - return Collections.singletonList(ADNAME_ATTRIBUTE); + List dependencies = new ArrayList<>(); + dependencies.add(ADNAME_ATTRIBUTE); + dependencies.add(USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE); + return dependencies; } @Override diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu.java index d7a1b2f6fc..0389d7ace5 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu.java @@ -106,11 +106,11 @@ public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource if (!groupResourcePairs.isEmpty()) { throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "some of the email addresses are already assigned to the following group_resource pairs: " + groupResourcePairs); } - Attribute memberO365EmailAddresses = new Attribute(new urn_perun_member_attribute_def_def_o365EmailAddresses_mu().getAttributeDefinition()); - memberO365EmailAddresses.setValue(emails); - Set> memberPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, memberO365EmailAddresses); - if (!memberPairs.isEmpty()) { - throw new WrongReferenceAttributeValueException(attribute, memberO365EmailAddresses, group, resource, "member " + BeansUtils.getSingleId(memberPairs) + " "); + Attribute userO365EmailAddresses = new Attribute(new urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu().getAttributeDefinition()); + userO365EmailAddresses.setValue(emails); + Set> userPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, userO365EmailAddresses); + if (!userPairs.isEmpty()) { + throw new WrongReferenceAttributeValueException(attribute, userO365EmailAddresses, group, resource, "user " + BeansUtils.getSingleId(userPairs) + " "); } } @@ -134,7 +134,10 @@ public Attribute fillAttribute(PerunSessionImpl sess, Group group, Resource reso @Override public List getDependencies() { - return Collections.singletonList(ADNAME_ATTRIBUTE); + List dependencies = new ArrayList<>(); + dependencies.add(ADNAME_ATTRIBUTE); + dependencies.add(new urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu().getAttributeDefinition().getName()); + return dependencies; } @Override diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_mu.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_mu.java index 45148f5c2a..6cb6385f3b 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_mu.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_mu.java @@ -38,11 +38,10 @@ * Requirements: *
    *
  • type is list
  • - *
  • all values are email addresses
  • - *
  • must contain value uco@muni.cz
  • + *
  • value can be null
  • + *
  • if not null, than all values are email addresses
  • *
  • no duplicates among the list values
  • - *
  • no duplicates among all values of this attribute for all members and all values of - * attribute urn:perun:group_resource:attribute-def:def:o365EmailAddresses:mu
  • + *
  • no duplicates among all values of this attribute for all members
  • *
* * @author Martin Kuba <makub@ics.muni.cz> @@ -53,8 +52,6 @@ public class urn_perun_member_attribute_def_def_o365EmailAddresses_mu extends Me private final static Logger log = LoggerFactory.getLogger(urn_perun_member_attribute_def_def_o365EmailAddresses_mu.class); private static final String NAMESPACE = AttributesManager.NS_MEMBER_ATTR_DEF; - static final String UCO_ATTRIBUTE = AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:mu"; - static final String G_D_O365_EMAIL_ADDRESSES_O365MU_ATTR = AttributesManager.NS_GROUP_ATTR_DEF + ":o365EmailAddresses:o365mu"; public void checkAttributeSyntax(PerunSessionImpl perunSession, Member member, Attribute attribute) throws WrongAttributeValueException { Object value = attribute.getValue(); @@ -82,84 +79,13 @@ else if (!(value instanceof ArrayList)) { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Member member, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { log.trace("checkAttributeSemantics(member={},attribute={})", member, attribute); - List emails; //get values if (attribute.getValue() == null) { throw new WrongReferenceAttributeValueException(attribute, "can't be null."); - } else { - emails = attribute.valueAsList(); - } - - //check for presence of uco@muni.cz - Attribute attrUCO = getUserUco(sess, member); - String UCO = attrUCO.valueAsString(); - //Throw an exception if UCO is null (we need to have this value not-null to correctly check value of this attribute) - if(UCO == null) { - throw new WrongReferenceAttributeValueException(attribute, attrUCO, member, null, UCO_ATTRIBUTE + " has null value!"); - } - String ucoEmail = UCO + "@muni.cz"; - if (!emails.contains(ucoEmail)) { - throw new WrongReferenceAttributeValueException(attribute, attrUCO, member, null, member, null, "does not contain " + ucoEmail); - } - - //No need to check duplicities between other members, cause attribute is unique - //Check uniqueness between this attribute and groups - try { - Attribute groupO365EmailAddresses = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, G_D_O365_EMAIL_ADDRESSES_O365MU_ATTR)); - groupO365EmailAddresses.setValue(emails); - Set groupsWithSameAttributeValueSet = sess.getPerunBl().getAttributesManagerBl().getPerunBeanIdsForUniqueAttributeValue(sess, groupO365EmailAddresses).stream() - .map(Pair::getLeft) - .collect(Collectors.toSet()); - if (!groupsWithSameAttributeValueSet.isEmpty()) { - try { - Group groupWithDuplicateEmail = sess.getPerunBl().getGroupsManagerBl().getGroupById(sess, groupsWithSameAttributeValueSet.iterator().next()); - throw new WrongReferenceAttributeValueException(attribute, groupO365EmailAddresses, member, null, groupWithDuplicateEmail, null, "some of the email addresses are already assigned."); - } catch (GroupNotExistsException e) { - throw new ConsistencyErrorException(e); - } - } - } catch (AttributeNotExistsException ex) { - //If attribute not exists, we can log it and skip it, because there are no duplicates in not existing attributes - log.debug("Attribute {} not exists to check duplicities in it while checkAttributeSemantics for {}.", G_D_O365_EMAIL_ADDRESSES_O365MU_ATTR, attribute); - } - } - - @Override - public List getDependencies() { - return Arrays.asList(UCO_ATTRIBUTE, G_D_O365_EMAIL_ADDRESSES_O365MU_ATTR); - } - - /** - * Prefills values uco@mail.muni.cz and uco@muni.cz - */ - @Override - public Attribute fillAttribute(PerunSessionImpl sess, Member member, AttributeDefinition attrDef) throws WrongAttributeAssignmentException { - return new Attribute(attrDef, getUserUcoEmails(sess, member)); - } - - /** - * Gets user uco attribute urn:perun:user:attribute-def:def:login-namespace:mu. - * - * @return Attribute with STRING UCO value if exists, with null value if not exists - */ - private Attribute getUserUco(PerunSessionImpl sess, Member member) throws WrongAttributeAssignmentException { - try { - User user = sess.getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId()); - return sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, UCO_ATTRIBUTE); - } catch (UserNotExistsException | AttributeNotExistsException e) { - throw new InternalErrorException(e.getMessage(), e); } - } - /** - * @returns uco@muni.cz in list if UCO exists, null if not exists - */ - private ArrayList getUserUcoEmails(PerunSessionImpl sess, Member member) throws WrongAttributeAssignmentException { - Attribute attributeUCO = getUserUco(sess, member); - String uco = attributeUCO.valueAsString(); - if(uco == null) return null; - else return Lists.newArrayList(uco + "@muni.cz"); + //No need to check duplicities, attribute is unique } @Override diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365SystemEmailAddresses_mu.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365SystemEmailAddresses_mu.java new file mode 100644 index 0000000000..cdaf39d81b --- /dev/null +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365SystemEmailAddresses_mu.java @@ -0,0 +1,72 @@ +package cz.metacentrum.perun.core.impl.modules.attributes; + +import cz.metacentrum.perun.core.api.Attribute; +import cz.metacentrum.perun.core.api.AttributeDefinition; +import cz.metacentrum.perun.core.api.AttributesManager; +import cz.metacentrum.perun.core.api.Pair; +import cz.metacentrum.perun.core.api.User; +import cz.metacentrum.perun.core.api.exceptions.InternalErrorException; +import cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException; +import cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException; +import cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException; +import cz.metacentrum.perun.core.bl.AttributesManagerBl; +import cz.metacentrum.perun.core.impl.PerunSessionImpl; +import cz.metacentrum.perun.core.implApi.modules.attributes.UserAttributesModuleAbstract; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; + +import static cz.metacentrum.perun.core.impl.Utils.emailPattern; +import static cz.metacentrum.perun.core.impl.Utils.hasDuplicate; + +public class urn_perun_user_attribute_def_def_o365SystemEmailAddresses_mu extends UserAttributesModuleAbstract { + + private final static Logger log = LoggerFactory.getLogger(urn_perun_user_attribute_def_def_o365SystemEmailAddresses_mu.class); + + @Override + public void checkAttributeSyntax(PerunSessionImpl perunSession, User user, Attribute attribute) throws InternalErrorException, WrongAttributeValueException { + //empty value is valid + if(attribute.getValue() == null) return; + ArrayList emails = attribute.valueAsList(); + + //check syntax of all values + for (String email : emails) { + Matcher emailMatcher = emailPattern.matcher(email); + if (!emailMatcher.matches()) + throw new WrongAttributeValueException(attribute, user, "Email " + email + " is not in correct form."); + } + + //check for duplicities + if (hasDuplicate(emails)) { + throw new WrongAttributeValueException(attribute, user, "duplicate values"); + } + } + + @Override + public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException { + log.trace("checkAttributeSemantics(user={},attribute={})", user, attribute); + + //empty value is valid + if(attribute.getValue() == null) return; + ArrayList emails = attribute.valueAsList(); + + //No need to check duplicities, attribute is unique + } + + @Override + public AttributeDefinition getAttributeDefinition() { + AttributeDefinition attr = new AttributeDefinition(); + attr.setNamespace(AttributesManager.NS_USER_ATTR_DEF); + attr.setFriendlyName("o365SystemEmailAddresses:mu"); + attr.setDisplayName("System managed email addresses for MU o365"); + attr.setType(ArrayList.class.getName()); + attr.setUnique(true); + attr.setDescription("System managed email addresses for MU o365"); + return attr; + } +} diff --git a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu.java b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu.java index c9ad95f6a2..7f0b8de180 100644 --- a/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu.java +++ b/perun-core/src/main/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu.java @@ -10,7 +10,6 @@ import cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException; import cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException; import cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException; -import cz.metacentrum.perun.core.bl.AttributesManagerBl; import cz.metacentrum.perun.core.impl.PerunSessionImpl; import cz.metacentrum.perun.core.implApi.modules.attributes.UserAttributesModuleAbstract; import org.slf4j.Logger; @@ -18,17 +17,17 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Matcher; -import static cz.metacentrum.perun.core.impl.Utils.emailPattern; -import static cz.metacentrum.perun.core.impl.Utils.hasDuplicate; -import static cz.metacentrum.perun.core.impl.Utils.ucoEmailPattern; +import static cz.metacentrum.perun.core.impl.Utils.*; public class urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu extends UserAttributesModuleAbstract { + private final static Logger log = LoggerFactory.getLogger(urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu.class); + final static String G_D_O365_EMAIL_ADDRESSES_O365_MU_ATTR = AttributesManager.NS_GROUP_ATTR_DEF + ":o365EmailAddresses:o365mu"; + @Override public void checkAttributeSyntax(PerunSessionImpl perunSession, User user, Attribute attribute) throws InternalErrorException, WrongAttributeValueException { //empty value is valid @@ -51,6 +50,33 @@ public void checkAttributeSyntax(PerunSessionImpl perunSession, User user, Attri } } + @Override + public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException { + log.trace("checkAttributeSemantics(member={},attribute={})", user, attribute); + + //empty value is valid + if(attribute.getValue() == null) return; + ArrayList emails = attribute.valueAsList(); + + //check for duplicities among this attribute and all groups (urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu) + try { + Attribute groupO365EmailAddresses = new Attribute(perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, G_D_O365_EMAIL_ADDRESSES_O365_MU_ATTR)); + groupO365EmailAddresses.setValue(emails); + Set> groupResourcePairs = perunSession.getPerunBl().getAttributesManagerBl().getPerunBeanIdsForUniqueAttributeValue(perunSession, groupO365EmailAddresses); + if (!groupResourcePairs.isEmpty()) { + throw new WrongReferenceAttributeValueException(attribute, groupO365EmailAddresses, user, null, "some of the email addresses are already assigned to the following group_resource pairs: " + groupResourcePairs); + } + } catch (AttributeNotExistsException ex) { + //If attribute not exists, we can log it and skip it, because there are no duplicates in not existing attributes + log.debug("Attribute {} not exists to check duplicities in it while checkAttributeSemantics for {}.", G_D_O365_EMAIL_ADDRESSES_O365_MU_ATTR, attribute); + } + } + + @Override + public List getDependencies() { + return Collections.singletonList(G_D_O365_EMAIL_ADDRESSES_O365_MU_ATTR); + } + @Override public AttributeDefinition getAttributeDefinition() { AttributeDefinition attr = new AttributeDefinition(); diff --git a/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365muTest.java b/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365muTest.java index 15f7be1cea..e919b165c9 100644 --- a/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365muTest.java +++ b/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_group_attribute_def_def_o365EmailAddresses_o365muTest.java @@ -60,8 +60,8 @@ public void setUp() throws Exception { .thenReturn(adName); when(adNameAttr.getValue()) .thenReturn(adName); - when(am.getAttributeDefinition(session, urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.MEMBER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE)) - .thenReturn(new urn_perun_member_attribute_def_def_o365EmailAddresses_mu().getAttributeDefinition()); + when(am.getAttributeDefinition(session, urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu.USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE)) + .thenReturn(new urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu().getAttributeDefinition()); attributeToCheck = new Attribute(classInstance.getAttributeDefinition()); attributeToCheck.setId(100); @@ -79,7 +79,7 @@ public void fillAttribute() throws Exception { assertThat(attributeValue, equalTo(expectedValue)); //check that value generated by fillAttribute() is acceptable for checkAttributeSemantics() - when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("member")))) + when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("user")))) .thenReturn(Sets.newHashSet()); classInstance.checkAttributeSemantics(session, group, attribute); } @@ -146,7 +146,7 @@ public void testCorrect() throws Exception { public void testUniqItself() throws Exception { System.out.println("testUniqItself"); attributeToCheck.setValue(new ArrayList<>(Arrays.asList("my@example.com", "my2@google.com"))); - when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("member")))) + when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("user")))) .thenReturn(Sets.newHashSet()); classInstance.checkAttributeSemantics(session, group, attributeToCheck); } @@ -155,7 +155,7 @@ public void testUniqItself() throws Exception { public void testUniqClash() throws Exception { System.out.println("testUniqClash"); attributeToCheck.setValue(new ArrayList<>(Arrays.asList("my@example.com", "my2@google.com"))); - when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("member")))) + when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("user")))) .thenReturn(Sets.newHashSet(new Pair<>(10, 0))); classInstance.checkAttributeSemantics(session, group, attributeToCheck); } diff --git a/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_muTest.java b/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_muTest.java index 32b366afad..aab1d65f21 100644 --- a/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_muTest.java +++ b/perun-core/src/test/java/cz/metacentrum/perun/core/impl/modules/attributes/urn_perun_member_attribute_def_def_o365EmailAddresses_muTest.java @@ -18,13 +18,7 @@ import org.junit.Test; import org.mockito.ArgumentMatcher; -import java.util.List; - -import static cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_member_attribute_def_def_o365EmailAddresses_mu.UCO_ATTRIBUTE; import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.argThat; @@ -61,7 +55,6 @@ public void setUp() throws Exception { when(perunBl.getAttributesManagerBl()).thenReturn(am); when(perunBl.getUsersManagerBl()).thenReturn(um); when(um.getUserById(session, member.getUserId())).thenReturn(user); - when(am.getAttribute(session, user, UCO_ATTRIBUTE)).thenReturn(ucoAttr); when(ucoAttr.getValue()).thenReturn(uco); when(ucoAttr.valueAsString()).thenReturn(uco); when(um.getUserById(session, member.getUserId())).thenReturn(user); @@ -69,8 +62,6 @@ public void setUp() throws Exception { .thenReturn(Sets.newHashSet(new Pair<>(member.getId(), 0))); when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("group")))) .thenReturn(Sets.newHashSet()); - when(am.getAttributeDefinition(session, urn_perun_member_attribute_def_def_o365EmailAddresses_mu.G_D_O365_EMAIL_ADDRESSES_O365MU_ATTR)) - .thenReturn(new urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu().getAttributeDefinition()); attributeToCheck = new Attribute(classInstance.getAttributeDefinition()); attributeToCheck.setId(101); } @@ -97,20 +88,6 @@ public String toString() { } } - @Test - public void fillAttribute() throws Exception { - System.out.println("fillAttribute()"); - Attribute attribute = classInstance.fillAttribute(session, member, classInstance.getAttributeDefinition()); - Object attributeValue = attribute.getValue(); - assertThat(attributeValue, is(notNullValue())); - List expectedValue = Lists.newArrayList(uco + "@muni.cz"); - assertThat(attributeValue, equalTo(expectedValue)); - - //check that value generated by fillAttribute() is acceptable for checkAttributeSemantics() - classInstance.checkAttributeSemantics(session, member, attribute); - } - - @Test(expected = WrongReferenceAttributeValueException.class) public void testCheckNull() throws Exception { System.out.println("testCheckNull()"); attributeToCheck.setValue(null); @@ -138,22 +115,10 @@ public void testCheckDuplicates() throws Exception { classInstance.checkAttributeSyntax(session, member, attributeToCheck); } - @Test - public void testCheckMissingUco() throws Exception { - System.out.println("testCheckMissingUco()"); - attributeToCheck.setValue(Lists.newArrayList("my@example.com", "aaa@bbb.com")); - try { - classInstance.checkAttributeSemantics(session, member, attributeToCheck); - fail("should throw WrongReferenceAttributeValueException"); - } catch (WrongReferenceAttributeValueException ex) { - assertThat(ex.getMessage(), endsWith("does not contain 123456@muni.cz")); - } - } - @Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); - attributeToCheck.setValue(Lists.newArrayList("my@example.com", "aaa@bbb.com", uco + "@muni.cz")); + attributeToCheck.setValue(Lists.newArrayList("my@example.com", "aaa@bbb.com")); classInstance.checkAttributeSemantics(session, member, attributeToCheck); } @@ -163,22 +128,4 @@ public void testCorrectSyntax() throws Exception { attributeToCheck.setValue(Lists.newArrayList("my@example.com", "aaa@bbb.com", uco + "@muni.cz")); classInstance.checkAttributeSyntax(session, member, attributeToCheck); } - - @Test - public void testClashGroupResource() throws Exception { - System.out.println("testClashGroupResource()"); - when(am.getPerunBeanIdsForUniqueAttributeValue(eq(session), argThat(new BeanAttributeMatcher("group")))) - .thenReturn(Sets.newHashSet(new Pair<>(55, 0))); - Group groupWithDuplicateEmail = mock(Group.class); - GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class); - when(session.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl); - when(session.getPerunBl().getGroupsManagerBl().getGroupById(session, 55)).thenReturn(groupWithDuplicateEmail); - attributeToCheck.setValue(Lists.newArrayList("my@example.com", uco + "@muni.cz")); - try { - classInstance.checkAttributeSemantics(session, member, attributeToCheck); - fail("should throw WrongReferenceAttributeValueException"); - } catch (WrongReferenceAttributeValueException ex) { - assertThat(ex.getMessage(), endsWith("some of the email addresses are already assigned.")); - } - } }