urn_perun_user_facility_attribute_def_def_homeMountPoint extends UserFacilityAttributesModuleAbstract implements UserFacilityAttributesModuleImplApi { @Override public Attribute fillAttribute(PerunSessionImpl session, User user, Facility facility, AttributeDefinition attribute) throws WrongAttributeAssignmentException { Attribute returnAttribute = new Attribute(attribute); List<Resource> usersResources; usersResources = session.getPerunBl().getUsersManagerBl().getAllowedResources(session, facility, user); for (Resource res : usersResources) { Attribute resAttribute; try { resAttribute = session.getPerunBl().getAttributesManagerBl().getAttribute(session, res, AttributesManager.NS_RESOURCE_ATTR_DEF + ":defaultHomeMountPoint"); } catch (AttributeNotExistsException ex) { throw new InternalErrorException("no homemountpoints found on underlying user's resources", ex); } if (resAttribute.getValue() != null) { returnAttribute.setValue(resAttribute.getValue()); return returnAttribute; } } return returnAttribute; }  @Override void checkAttributeSemantics(PerunSessionImpl session, User user, Facility facility, Attribute attribute); @Override void checkAttributeSyntax(PerunSessionImpl session, User user, Facility facility, Attribute attribute); @Override Attribute fillAttribute(PerunSessionImpl session, User user, Facility facility, AttributeDefinition attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void testFillAttribute() throws Exception { System.out.println("testFillAttribute()"); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<Resource>() { { add(resource); } }); when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSession.class), any(Facility.class))).thenReturn(new ArrayList<Resource>() { { add(resource); } }); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(listOfMntPts); Attribute filledAttribute = classInstance.fillAttribute(session, user, facility, new AttributeDefinition()); assertTrue("A different homeMountPoint was filled than those available", ( listOfMntPts.getValue()).equals(filledAttribute.getValue())); }
@Test public void testFillAttributeOfUnknownUser() throws Exception { System.out.println("testFillAttributeOfUnknownUser()"); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<>()); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(listOfMntPts); Attribute atr = classInstance.fillAttribute(session, user, facility, new AttributeDefinition()); assertNull("User's homeMountPoint was filled even they don't have an account there.", atr.getValue()); }