urn_perun_group_resource_attribute_def_def_adName extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { if(attribute.getValue() == null) { return; } Attribute resourceAdOuName; try { resourceAdOuName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_D_AD_OU_NAME); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException(ex); } if(resourceAdOuName.getValue() == null) { return; } List<Group> groupsWithSameADNameInSameOu = sess.getPerunBl().getSearcherBl().getGroupsByGroupResourceSetting(sess, attribute, resourceAdOuName); groupsWithSameADNameInSameOu.remove(group); if(!groupsWithSameADNameInSameOu.isEmpty()) { throw new WrongReferenceAttributeValueException(attribute, resourceAdOuName, group, resource, resource, null, "Attribute AD Name can't be set for group and resource in this OU, because this value is already " + "set for different group and resource in the same OU!"); } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testSemanticsWithSameADNameAlreadySetElsewhere() throws Exception { System.out.println("testSemanticsWithSameADNameAlreadySetElsewhere()"); attributeToCheck.setValue("correctValue"); reqAttribute.setValue("correctValue2"); Group group2 = new Group(); List<Group> groups = new ArrayList<>(); groups.add(group2); groups.add(group); when(sess.getPerunBl().getSearcherBl().getGroupsByGroupResourceSetting(sess, attributeToCheck, reqAttribute)).thenReturn(groups); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue("correctValue"); reqAttribute.setValue("correctValue2"); classInstance.checkAttributeSemantics(sess, group, resource, attributeToCheck); }