urn_perun_user_facility_attribute_def_def_homeMountPoint extends UserFacilityAttributesModuleAbstract implements UserFacilityAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl session, User user, Facility facility, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { List<Resource> usersResources = session.getPerunBl().getUsersManagerBl().getAllowedResources(session, facility, user); List<String> homeMntPointsOnAllResources = new ArrayList<>(); for (Resource res : usersResources) { Attribute resAttribute; try { resAttribute = session.getPerunBl().getAttributesManagerBl().getAttribute(session, res, AttributesManager.NS_RESOURCE_ATTR_DEF + ":homeMountPoints"); } catch (AttributeNotExistsException ex) { throw new InternalErrorException("no homemountpoints found on underlying resources", ex); } List<String> homeMntPoint = resAttribute.valueAsList(); if (homeMntPoint != null) { homeMntPointsOnAllResources.addAll(homeMntPoint); } } if (homeMntPointsOnAllResources.isEmpty()) { throw new WrongReferenceAttributeValueException("No homeMountPoints set on associated resources."); } if (!homeMntPointsOnAllResources.contains(attribute.valueAsString())) { throw new WrongReferenceAttributeValueException(attribute, null, user, facility, "User's home mount point is invalid. Valid mount points: " + homeMntPointsOnAllResources); } }  @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 testCheckAttributeSemantics() throws Exception { System.out.println("testCheckAttributeSemantics()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("/mnt/mnt1"); 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); classInstance.checkAttributeSemantics(session, user, facility, attributeToCheck); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckAttributeSemanticsOfUnknownUser() throws Exception { System.out.println("testCheckAttributeSemanticsOfUnknownUser()"); 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 = new Attribute(); atr.setValue(("/mnt/mnt1")); classInstance.checkAttributeSemantics(session, user, facility, atr); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckAttributeSemanticsWithEmptyAttribute() throws Exception { System.out.println("testCheckAttributeSemanticsWithEmptyAttribute()"); 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); classInstance.checkAttributeSemantics(session, user, facility, new Attribute()); fail("Empty attribute should have thrown an exception"); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testCheckAttributeSemanticsWrongHomeMountPointFormatHomeMountPointIsDirectory() throws Exception { System.out.println("testCheckAttributeSemanticsWrongHomeMountPointFormatHomeMountPointIsDirectory()"); 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 attributeToCheck = new Attribute(); attributeToCheck.setValue("/mnt/mnt1/"); classInstance.checkAttributeSemantics(session, user, facility, attributeToCheck); fail("Wrong homeMountPoint format should have thrown an exception"); }