urn_perun_resource_attribute_def_def_fairshareGroupName extends ResourceAttributesModuleAbstract implements ResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { if (attribute.getValue() == null) { return; } String gName = attribute.valueAsString(); Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource); List<Resource> facilityResources = perunSession.getPerunBl().getFacilitiesManagerBl().getAssignedResources(perunSession, facility); facilityResources.remove(resource); for(Resource res: facilityResources) { try { Attribute resFairshareName = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, res, attribute.getName()); if (resFairshareName.getValue() != null && gName.equals(resFairshareName.valueAsString())) { throw new WrongReferenceAttributeValueException(attribute, resFairshareName, resource, null, res, null, "This name is already taken (not unique). Choose another one."); } } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException(ex); } } }  @Override void checkAttributeSyntax(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testSemanticsWithNameAlreadyTaken() throws Exception { System.out.println("testSemanticsWithNameAlreadyTaken()"); attributeToCheck.setValue("example"); reqAttribute.setValue("example"); classInstance.checkAttributeSemantics(sess, resource, attributeToCheck); }
@Test public void testSemanticsCorrect() throws Exception { System.out.println("testSemanticsCorrect()"); attributeToCheck.setValue("example"); reqAttribute.setValue("anotherValue"); classInstance.checkAttributeSemantics(sess, resource, attributeToCheck); }