From 8532a5133e996e61765be126f8b4d25984745fd1 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 03 Sep 2007 13:33:50 +0000
Subject: [PATCH] Partial fix for issue 1451: admin framework constraint and dependency support.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/ldap/LDAPClientTest.java | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 201 insertions(+), 0 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/ldap/LDAPClientTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/ldap/LDAPClientTest.java
index 46bdbae..9c7e8b1 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/ldap/LDAPClientTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/ldap/LDAPClientTest.java
@@ -40,6 +40,7 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.AdminTestCase;
+import org.opends.server.admin.Constraint;
import org.opends.server.admin.DefinitionDecodingException;
import org.opends.server.admin.LDAPProfile;
import org.opends.server.admin.ManagedObjectAlreadyExistsException;
@@ -797,6 +798,206 @@
+ /**
+ * Tests creation of a child managed object succeeds when registered
+ * add constraints succeed.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testAddConstraintSuccess() throws Exception {
+ Constraint constraint = new MockConstraint(true, false, false);
+ TestChildCfgDefn.getInstance().addConstraint(constraint);
+
+ try {
+ CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
+ "cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ c.addExpectedAttribute("cn", "test child new");
+ c.addExpectedAttribute("objectclass", "top", "ds-cfg-virtual-attribute");
+ c.addExpectedAttribute("ds-cfg-virtual-attribute-enabled", "true");
+ c.addExpectedAttribute("ds-cfg-virtual-attribute-class",
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ c.addExpectedAttribute("ds-cfg-virtual-attribute-type", "description");
+
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn
+ .getInstance(), "test child new", null);
+ child.setMandatoryBooleanProperty(true);
+ child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
+ child.commit();
+
+ c.assertEntryIsCreated();
+ } finally {
+ // Clean up.
+ TestChildCfgDefn.getInstance().removeConstraint(constraint);
+ }
+ }
+
+
+
+ /**
+ * Tests creation of a child managed object fails when registered
+ * add constraints fail.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test(expectedExceptions=OperationRejectedException.class)
+ public void testAddConstraintFail() throws Exception {
+ Constraint constraint = new MockConstraint(false, true, true);
+ TestChildCfgDefn.getInstance().addConstraint(constraint);
+
+ try {
+ CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
+ "cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ c.addExpectedAttribute("cn", "test child new");
+ c.addExpectedAttribute("objectclass", "top", "ds-cfg-virtual-attribute");
+ c.addExpectedAttribute("ds-cfg-virtual-attribute-enabled", "true");
+ c.addExpectedAttribute("ds-cfg-virtual-attribute-class",
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ c.addExpectedAttribute("ds-cfg-virtual-attribute-type", "description");
+
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn
+ .getInstance(), "test child new", null);
+ child.setMandatoryBooleanProperty(true);
+ child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
+ child.commit();
+ Assert.fail("The add constraint failed to prevent creation of the managed object");
+ } finally {
+ // Clean up.
+ TestChildCfgDefn.getInstance().removeConstraint(constraint);
+ }
+ }
+
+
+
+ /**
+ * Tests removal of a child managed object succeeds when registered
+ * remove constraints succeed.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testRemoveConstraintSuccess() throws Exception {
+ Constraint constraint = new MockConstraint(false, false, true);
+ TestChildCfgDefn.getInstance().addConstraint(constraint);
+
+ try {
+ DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection(
+ "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ parent.removeTestChild("test child 1");
+ c.assertSubtreeIsDeleted();
+ } finally {
+ // Clean up.
+ TestChildCfgDefn.getInstance().removeConstraint(constraint);
+ }
+ }
+
+
+
+ /**
+ * Tests removal of a child managed object fails when registered
+ * remove constraints fails.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test(expectedExceptions=OperationRejectedException.class)
+ public void testRemoveConstraintFail() throws Exception {
+ Constraint constraint = new MockConstraint(true, true, false);
+ TestChildCfgDefn.getInstance().addConstraint(constraint);
+
+ try {
+ DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection(
+ "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ parent.removeTestChild("test child 1");
+ Assert.fail("The remove constraint failed to prevent removal of the managed object");
+ } finally {
+ // Clean up.
+ TestChildCfgDefn.getInstance().removeConstraint(constraint);
+ }
+ }
+
+
+
+ /**
+ * Tests modification of a child managed object succeeds when
+ * registered remove constraints succeed.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testModifyConstraintSuccess() throws Exception {
+ Constraint constraint = new MockConstraint(false, true, false);
+ TestChildCfgDefn.getInstance().addConstraint(constraint);
+
+ try {
+ ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
+ "cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ c.addExpectedModification("ds-cfg-virtual-attribute-base-dn");
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ TestChildCfgClient child = parent.getTestChild("test child 2");
+ child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet());
+ child.commit();
+ Assert.assertTrue(c.isEntryModified());
+ } finally {
+ // Clean up.
+ TestChildCfgDefn.getInstance().removeConstraint(constraint);
+ }
+ }
+
+
+
+ /**
+ * Tests modification of a child managed object fails when
+ * registered remove constraints fails.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test(expectedExceptions = OperationRejectedException.class)
+ public void testModifyConstraintFail() throws Exception {
+ Constraint constraint = new MockConstraint(true, false, true);
+ TestChildCfgDefn.getInstance().addConstraint(constraint);
+
+ try {
+ ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
+ "cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ c.addExpectedModification("ds-cfg-virtual-attribute-base-dn");
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ TestChildCfgClient child = parent.getTestChild("test child 2");
+ child.setOptionalMultiValuedDNProperty1(Collections.<DN> emptySet());
+ child.commit();
+ Assert
+ .fail("The modify constraint failed to prevent modification of the managed object");
+ } finally {
+ // Clean up.
+ TestChildCfgDefn.getInstance().removeConstraint(constraint);
+ }
+ }
+
+
+
// Asserts that the actual set of DNs contains the expected values.
private void assertDNSetEquals(SortedSet<DN> actual, String... expected) {
String[] actualStrings = new String[actual.size()];
--
Gitblit v1.10.0