urn_perun_user_facility_attribute_def_def_accountExpirationTime extends UserFacilityAttributesModuleAbstract implements UserFacilityAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Facility facility, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { Integer accExpTime = attribute.valueAsInteger(); if (accExpTime == null) { throw new WrongReferenceAttributeValueException(attribute, null, user, facility, "account expiration time shouldn't be null"); } Integer facilityAccExpTime; Attribute facilityAccExpAttribute; try { facilityAccExpAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, facility, A_F_D_accountExpirationTime); facilityAccExpTime = facilityAccExpAttribute.valueAsInteger(); } catch (AttributeNotExistsException ex) { throw new InternalErrorException(ex); } if(accExpTime > facilityAccExpTime) { throw new WrongReferenceAttributeValueException(attribute, facilityAccExpAttribute, user, facility, facility, null, "this user_facility attribute cannot has higher value than same facility attribute"); } }  @Override void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Facility facility, Attribute attribute); @Override List<String> getDependencies(); @Override Attribute fillAttribute(PerunSessionImpl perunSession, User user, Facility facility, AttributeDefinition attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void testCheckAttributeSemantics() throws Exception { System.out.println("testCheckAttributeSemantics()"); attributeToCheck.setValue(1000); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Facility.class), anyString())).thenReturn(new Attribute() { { setValue(1500); } }); classInstance.checkAttributeSemantics(session, new User(), new Facility(), attributeToCheck); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckAttributeSemanticsHigherValueThanFacilityTime() throws Exception { System.out.println("testCheckAttributeSemanticsHigherValueThanFacilityTime()"); attributeToCheck.setValue(1000); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Facility.class), anyString())).thenReturn(new Attribute() { { setValue(999); } }); classInstance.checkAttributeSemantics(session, new User(), new Facility(), attributeToCheck); fail("Assigning lower accountExpirationTime than the time set at facility should throw exception."); }