urn_perun_user_attribute_def_def_preferredEduPersonPrincipalName extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { String value = attribute.valueAsString(); try { Attribute eppns = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, user, A_U_eduPersonPrincipalNames); if (eppns.getValue() != null) { List<String> values = eppns.valueAsList(); if (!values.contains(value)) { throw new WrongReferenceAttributeValueException(attribute, eppns, user, null, user, null, "Value '"+value+"' is not allowed. Please use one of allowed."); } } else { if (value != null) throw new WrongReferenceAttributeValueException(attribute, eppns, user, null, user, null, "Value '"+value+"' is not allowed. Please use one of allowed."); } } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException("Can't check attribute value because source attribute " + A_U_eduPersonPrincipalNames + " not exist!", ex); } }  @Override Attribute fillAttribute(PerunSessionImpl session, User user, AttributeDefinition attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckNullValue() throws Exception { System.out.println("testCheckNullValue()"); List<String> list = new ArrayList<>(); list.add("not name"); reqAttribute.setValue(list); attributeToCheck.setValue(null); classInstance.checkAttributeSemantics(session, user, attributeToCheck); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckNotAllowedValue() throws Exception { System.out.println("testCheckNotAllowedValue()"); List<String> list = new ArrayList<>(); list.add("not name"); reqAttribute.setValue(list); attributeToCheck.setValue("name"); classInstance.checkAttributeSemantics(session, user, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); List<String> list = new ArrayList<>(); list.add("name"); reqAttribute.setValue(list); attributeToCheck.setValue("name"); classInstance.checkAttributeSemantics(session, user, attributeToCheck); }