urn_perun_member_resource_attribute_def_virt_isBanned extends MemberResourceVirtualAttributesModuleAbstract implements MemberResourceVirtualAttributesModuleImplApi { @Override public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message) throws AttributeNotExistsException, WrongAttributeAssignmentException { List<AuditEvent> resolvingMessages = new ArrayList<>(); if (message == null) return resolvingMessages; if (message instanceof BanSetForResource) { return resolveBanChangedForResource(perunSession, ((BanSetForResource) message).getMemberId(), ((BanSetForResource) message).getResourceId()); } else if (message instanceof BanRemovedForResource) { return resolveBanChangedForResource(perunSession, ((BanRemovedForResource) message).getMemberId(), ((BanRemovedForResource) message).getResourceId()); } else if (message instanceof BanUpdatedForResource) { return resolveBanChangedForResource(perunSession, ((BanUpdatedForResource) message).getMemberId(), ((BanUpdatedForResource) message).getResourceId()); } else if (message instanceof BanSetForFacility) { return resolveBanChangedForFacility(perunSession, ((BanSetForFacility) message).getUserId(), ((BanSetForFacility) message).getFacilityId()); } else if (message instanceof BanRemovedForFacility) { return resolveBanChangedForFacility(perunSession, ((BanRemovedForFacility) message).getUserId(), ((BanRemovedForFacility) message).getFacilityId()); } else if (message instanceof BanUpdatedForFacility) { return resolveBanChangedForFacility(perunSession, ((BanUpdatedForFacility) message).getUserId(), ((BanUpdatedForFacility) message).getFacilityId()); } return resolvingMessages; }  @Override Attribute getAttributeValue(PerunSessionImpl sess, Member member, Resource resource, AttributeDefinition attributeDefinition); @Override List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, AuditEvent message); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void resolveVirtualAttributeValueChangeTest() throws Exception{ System.out.println("urn_perun_user_facility_attribute_def_virt_defaultUnixGID.resolveVirtualAttributeValueChangeTest()"); List<AuditEvent> resolvedEvents; when(session.getPerunBl().getMembersManagerBl().getMemberById(any(PerunSessionImpl.class), anyInt())).thenReturn(member); when(session.getPerunBl().getResourcesManagerBl().getResourceById(any(PerunSessionImpl.class), anyInt())).thenReturn(resource); when(session.getPerunBl().getAttributesManagerBl().getAttributeDefinition(any(PerunSessionImpl.class), anyString())).thenReturn(classInstance.getAttributeDefinition()); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, event1); assertEquals(resolvedEvents.size(), 1); assertEquals(resolvedEvents.get(0).getMessage(), isBanned.serializeToString() + " changed for " + resource.serializeToString() + " and " + member.serializeToString() + "."); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, event2); assertEquals(resolvedEvents.get(0).getMessage(), isBanned.serializeToString() + " changed for " + resource.serializeToString() + " and " + member.serializeToString() + "."); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, event3); assertEquals(resolvedEvents.get(0).getMessage(), isBanned.serializeToString() + " changed for " + resource.serializeToString() + " and " + member.serializeToString() + "."); when(session.getPerunBl().getUsersManagerBl().getUserById(any(PerunSessionImpl.class), anyInt())).thenReturn(user); when(session.getPerunBl().getFacilitiesManagerBl().getFacilityById(any(PerunSessionImpl.class), anyInt())).thenReturn(facility); when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSessionImpl.class), any(Facility.class))).thenReturn(Collections.singletonList(resource)); when(session.getPerunBl().getResourcesManagerBl().getAssignedMembers(any(PerunSessionImpl.class), any(Resource.class))).thenReturn(Collections.singletonList(member)); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, event4); assertEquals(resolvedEvents.get(0).getMessage(), isBanned.serializeToString() + " changed for " + resource.serializeToString() + " and " + member.serializeToString() + "."); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, event5); assertEquals(resolvedEvents.get(0).getMessage(), isBanned.serializeToString() + " changed for " + resource.serializeToString() + " and " + member.serializeToString() + "."); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, event6); assertEquals(resolvedEvents.get(0).getMessage(), isBanned.serializeToString() + " changed for " + resource.serializeToString() + " and " + member.serializeToString() + "."); }
@Test public void resolveVirtualAttributeValueChangeTestWithWrongMatch() throws Exception { System.out.println("urn_perun_user_facility_attribute_def_virt_defaultUnixGID.resolveVirtualAttributeValueChangeTestWithWrongMatch()"); List<AuditEvent> resolvedEvents; when(session.getPerunBl().getMembersManagerBl().getMemberById(any(PerunSessionImpl.class), anyInt())).thenReturn(member); when(session.getPerunBl().getResourcesManagerBl().getResourceById(any(PerunSessionImpl.class), anyInt())).thenReturn(resource); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Member.class), any(Resource.class), anyString())).thenReturn(isBanned); resolvedEvents = classInstance.resolveVirtualAttributeValueChange(session, wrongEvent); assertTrue(resolvedEvents.isEmpty()); }