urn_perun_user_attribute_def_virt_institutionsCountries extends UserVirtualAttributeCollectedFromUserExtSource<DnsMapCtx> { @Override public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl sess, AuditEvent message) throws WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException { List<AuditEvent> messages = super.resolveVirtualAttributeValueChange(sess, message); if (message instanceof AttributeSetForKey && ((AttributeSetForKey) message).getAttribute().getFriendlyName().equals(DNS_STATE_MAPPING_ATTR.getFriendlyName())) { messages.addAll(resolveEvent(sess, ((AttributeSetForKey) message).getKey())); } else if (message instanceof AttributeRemovedForKey && ((AttributeRemovedForKey) message).getAttribute().getFriendlyName().equals(DNS_STATE_MAPPING_ATTR.getFriendlyName())) { messages.addAll(resolveEvent(sess, ((AttributeRemovedForKey) message).getKey())); } return messages; }  @Override String getSourceAttributeFriendlyName(); @Override String getDestinationAttributeFriendlyName(); @Override String getDestinationAttributeDescription(); @Override String modifyValue(PerunSession session, DnsMapCtx ctx, UserExtSource ues, String value); @Override List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl sess, AuditEvent message);  }
@Test public void resolveVirtualAttributeValueChange() throws Exception { setSchacHomeOrgs("muni.cz;cesnet.cz"); AttributeDefinition countries = classInstance.getAttributeDefinition(); when(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess,"urn:perun:user:attribute-def:virt:institutionsCountries")) .thenReturn(countries); when(sess.getPerunBl().getUsersManagerBl().getUserById(sess, userExtSource.getUserId())).thenReturn(user); AuditEvent uesSet = new AttributeSetForUes(schacHomeOrg, userExtSource); List<AuditEvent> msgs = classInstance.resolveVirtualAttributeValueChange(sess, uesSet); assertTrue("audit should contain change of institutionsCountries",msgs.get(0).getMessage().contains("friendlyName=<institutionsCountries>")); }
@Test public void resolveVirtualAttributeValueChange2() throws Exception { setSchacHomeOrgs("muni.cz;cesnet.cz"); String czech_republic = "Czech Republic"; dnsMap.put(".cz", czech_republic); AttributeDefinition countries = classInstance.getAttributeDefinition(); when(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:user:attribute-def:virt:institutionsCountries")) .thenReturn(countries); Attribute newval = new Attribute(new urn_perun_entityless_attribute_def_def_dnsStateMapping().getAttributeDefinition()); newval.setValue(czech_republic); when(sess.getPerunBl().getUsersManagerBl().findUsersWithExtSourceAttributeValueEnding(eq(sess), eq(SCHAC_HOME_ATTR_NAME), eq(".cz"), any())) .thenReturn(Collections.singletonList(user)); AuditEvent event = new AttributeSetForKey(newval, ".cz"); List<AuditEvent> msgs = classInstance.resolveVirtualAttributeValueChange(sess, event); assertTrue("audit should contain change of institutionsCountries",msgs.get(0).getMessage().contains("friendlyName=<institutionsCountries>")); }