urn_perun_group_attribute_def_def_groupStructureSynchronizationEnabled extends GroupAttributesModuleAbstract implements GroupAttributesModuleImplApi { @Override public void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException { if(attribute.getValue() == null) return; if (attribute.valueAsBoolean()) { if (perunSession.getPerunBl().getGroupsManagerBl().isGroupSynchronizedFromExternallSource(perunSession, group)) { throw new InternalErrorException("Synchronization is already enabled for one of the parent groups."); } try { Attribute attrSynchronizeEnabled = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPSYNCHROENABLED_ATTRNAME); if (Objects.equals("true", attrSynchronizeEnabled.getValue())) { throw new WrongReferenceAttributeValueException(attribute, attrSynchronizeEnabled); } Attribute requiredAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPSQUERY_ATTRNAME); if (requiredAttribute.getValue() == null) { throw new WrongReferenceAttributeValueException(attribute, requiredAttribute, requiredAttribute.toString() + " must be set in order to enable synchronization."); } requiredAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPMEMBERSQUERY_ATTRNAME); if (requiredAttribute.getValue() == null) { throw new WrongReferenceAttributeValueException(attribute, requiredAttribute, requiredAttribute.toString() + " must be set in order to enable synchronization."); } requiredAttribute = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME); if (requiredAttribute.getValue() == null) { throw new WrongReferenceAttributeValueException(attribute, requiredAttribute, requiredAttribute.toString() + " must be set in order to enable synchronization."); } } catch (AttributeNotExistsException e) { throw new ConsistencyErrorException(e); } } }  @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Attribute attribute); @Override List<String> getDependencies(); @Override void changedAttributeHook(PerunSessionImpl session, Group group, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongReferenceAttributeValueException.class) public void testGroupSyncEnabled() throws Exception { System.out.println("testGroupSyncEnabled()"); attributeToCheck.setValue(true); reqAttribute.setValue("true"); classInstance.checkAttributeSemantics(sess, group, attributeToCheck); }
@Test(expected = WrongReferenceAttributeValueException.class) public void testMissingReqAttribute() throws Exception { System.out.println("testMissingReqAttribute()"); attributeToCheck.setValue(true); reqAttribute.setValue("false"); Attribute attribute = new Attribute(); when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPSQUERY_ATTRNAME)).thenReturn(attribute); classInstance.checkAttributeSemantics(sess, group, attributeToCheck); }
@Test public void testCorrectSemantics() throws Exception { System.out.println("testCorrectSemantics()"); attributeToCheck.setValue(true); reqAttribute.setValue("false"); classInstance.checkAttributeSemantics(sess, group, attributeToCheck); }