From 07541fa5b77a51759b23eac2308255651eb5cd93 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 06 Sep 2007 00:26:13 +0000
Subject: [PATCH] Add partial support for performing server-side referential integrity. This change adds a constraint which prevents configuration of dangling references. A subsequent change will add a constraint which will prevent removal of referenced components.

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/admin/server/AggregationTest.java |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/server/AggregationTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/server/AggregationTest.java
index 3641a92..78048c0 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/server/AggregationTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/server/AggregationTest.java
@@ -34,6 +34,7 @@
 
 import javax.naming.ldap.LdapName;
 
+import org.opends.messages.Message;
 import org.opends.server.TestCaseUtils;
 import org.opends.server.admin.AdminTestCase;
 import org.opends.server.admin.IllegalPropertyValueStringException;
@@ -150,6 +151,23 @@
     assertSetEquals(child.getAggregationProperty(), "LDAPS Connection Handler",
         "LDAP Connection Handler");
   }
+  
+  
+
+  // Test child 5 LDIF.
+  private static final String[] TEST_CHILD_5 = new String[] {
+      "dn: cn=test child 5,cn=test children,cn=test parent 1,cn=test parents,cn=config",
+      "objectclass: top",
+      "objectclass: ds-cfg-test-child-dummy",
+      "cn: test child 5",
+      "ds-cfg-virtual-attribute-enabled: true",
+      "ds-cfg-virtual-attribute-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
+      "ds-cfg-virtual-attribute-type: description",
+      "ds-cfg-virtual-attribute-conflict-behavior: virtual-overrides-real",
+      "ds-cfg-backend-base-dn: cn=BAD Connection Handler 1, cn=connection handlers, cn=config",
+      "ds-cfg-backend-base-dn: cn=BAD Connection Handler 2, cn=connection handlers, cn=config",
+      "ds-cfg-backend-base-dn: cn=LDAP Connection Handler, cn=connection handlers, cn=config"
+  };
 
   // Test LDIF.
   private static final String[] TEST_LDIF = new String[] {
@@ -332,6 +350,41 @@
 
 
 
+  /**
+   * Tests that aggregation is rejected by a constraint violation when
+   * the DN values are dangling.
+   *
+   * @throws Exception
+   *           If the test unexpectedly fails.
+   */
+  @Test
+  public void testAggregationDanglingReference() throws Exception {
+    // Add the entry.
+    TestCaseUtils.addEntry(TEST_CHILD_5);
+
+    try {
+      TestParentCfg parent = getParent("test parent 1");
+      parent.getTestChild("test child 5");
+      Assert
+          .fail("Unexpectedly added test child 5 when it had a dangling reference");
+    } catch (ConfigException e) {
+      // Check that we have a constraint violation as the cause.
+      Throwable cause = e.getCause();
+      if (cause instanceof ConstraintViolationException) {
+        ConstraintViolationException cve = (ConstraintViolationException) cause;
+        Collection<Message> causes = cve.getMessages();
+        Assert.assertEquals(causes.size(), 2);
+      } else {
+        // Got an unexpected cause.
+        throw e;
+      }
+    } finally {
+      deleteSubtree("cn=test child 5,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+    }
+  }
+
+
+
   // Asserts that the actual set of DNs contains the expected values.
   private void assertSetEquals(SortedSet<String> actual, String... expected) {
     SortedSet<String> values = new TreeSet<String>(TestChildCfgDefn

--
Gitblit v1.10.0