From 79cb3d38939c48e71eb1d83592f61765d3983cf0 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 12 Jul 2007 22:46:42 +0000
Subject: [PATCH] Fix issues 1558 and 1919.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/admin/client/ldap/LDAPClientTest.java | 831 +++++++++++++++++++++++++++++++++++------------------------
1 files changed, 494 insertions(+), 337 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 2b0a7c8..69f031a 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
@@ -28,7 +28,10 @@
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.SortedSet;
import javax.naming.NamingException;
import javax.naming.OperationNotSupportedException;
@@ -38,6 +41,7 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.AdminTestCase;
import org.opends.server.admin.DefinitionDecodingException;
+import org.opends.server.admin.LDAPProfile;
import org.opends.server.admin.ManagedObjectAlreadyExistsException;
import org.opends.server.admin.ManagedObjectNotFoundException;
import org.opends.server.admin.MockLDAPProfile;
@@ -53,7 +57,10 @@
import org.opends.server.admin.client.ManagementContext;
import org.opends.server.admin.client.OperationRejectedException;
import org.opends.server.admin.std.client.RootCfgClient;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.types.DN;
import org.testng.Assert;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -67,25 +74,112 @@
// Test LDIF.
private static final String[] TEST_LDIF = new String[] {
- "dn: cn=test-parents", "objectclass: top", "objectclass: ds-cfg-branch",
- "cn: test-parents", "", "dn: cn=test parent 1, cn=test-parents",
- "objectclass: top", "objectclass: ds-cfg-test-parent",
- "cn: test parent 1", "", "dn: cn=test parent 2,cn=test-parents",
- "objectclass: top", "objectclass: ds-cfg-test-parent",
- "cn: test parent 2", "ds-cfg-minimum-length: 10000",
- "ds-cfg-maximum-length: 20000", "",
- "dn:cn=test-children,cn=test parent 1,cn=test-parents",
- "objectclass: top", "objectclass: ds-cfg-branch", "cn: test-children",
- "", "dn:cn=test-children,cn=test parent 2,cn=test-parents",
- "objectclass: top", "objectclass: ds-cfg-branch", "cn: test-children",
+ // Base entries.
+ "dn: cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-branch",
+ "cn: config",
"",
- "dn: cn=test child 1,cn=test-children,cn=test parent 1,cn=test-parents",
- "objectclass: top", "objectclass: ds-cfg-test-child", "cn: test child 1",
+ "dn: cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-branch",
+ "cn: test-parents",
"",
- "dn: cn=test child 2,cn=test-children,cn=test parent 1,cn=test-parents",
- "objectclass: top", "objectclass: ds-cfg-test-child", "cn: test child 2",
- "ds-cfg-heartbeat-interval: 12345s", "ds-cfg-minimum-length: 11111",
- "ds-cfg-maximum-length: 22222", "" };
+ // Parent 1 - uses default values for
+ // optional-multi-valued-dn-property.
+ "dn: cn=test parent 1,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test parent 1",
+ "ds-cfg-virtual-attribute-enabled: true",
+ "ds-cfg-virtual-attribute-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
+ "ds-cfg-virtual-attribute-type: description",
+ "",
+ // Parent 2 - overrides default values for
+ // optional-multi-valued-dn-property.
+ "dn: cn=test parent 2,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test parent 2",
+ "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-base-dn: dc=default value p2v1,dc=com",
+ "ds-cfg-virtual-attribute-base-dn: dc=default value p2v2,dc=com",
+ "",
+ // Parent 3 - overrides default values for
+ // optional-multi-valued-dn-property.
+ "dn: cn=test parent 3,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test parent 3",
+ "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-base-dn: dc=default value p3v1,dc=com",
+ "ds-cfg-virtual-attribute-base-dn: dc=default value p3v2,dc=com",
+ "",
+ // Child base entries.
+ "dn:cn=test children,cn=test parent 1,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-branch",
+ "cn: multiple children",
+ "",
+ "dn:cn=test children,cn=test parent 2,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-branch",
+ "cn: multiple children",
+ "",
+ // Child 1 inherits defaults for both
+ // optional-multi-valued-dn-property1 and
+ // optional-multi-valued-dn-property2.
+ "dn: cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test child 1",
+ "ds-cfg-virtual-attribute-enabled: true",
+ "ds-cfg-virtual-attribute-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
+ "ds-cfg-virtual-attribute-type: description",
+ "",
+ // Child 2 inherits defaults for
+ // optional-multi-valued-dn-property2.
+ "dn: cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test child 2",
+ "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-base-dn: dc=default value c2v1,dc=com",
+ "ds-cfg-virtual-attribute-base-dn: dc=default value c2v2,dc=com",
+ "",
+ // Child 3 overrides defaults for
+ // optional-multi-valued-dn-property1 and
+ // optional-multi-valued-dn-property2.
+ "dn: cn=test child 3,cn=test children,cn=test parent 1,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test child 3",
+ "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-base-dn: dc=default value c3v1,dc=com",
+ "ds-cfg-virtual-attribute-base-dn: dc=default value c3v2,dc=com",
+ "ds-cfg-virtual-attribute-group-dn: dc=default value c3v3,dc=com",
+ "ds-cfg-virtual-attribute-group-dn: dc=default value c3v4,dc=com",
+ "",
+ // Child 4 inherits overridden defaults for both
+ // optional-multi-valued-dn-property1 and
+ // optional-multi-valued-dn-property2.
+ "dn: cn=test child 1,cn=test children,cn=test parent 2,cn=test parents,cn=config",
+ "objectclass: top",
+ "objectclass: ds-cfg-virtual-attribute",
+ "cn: test child 1",
+ "ds-cfg-virtual-attribute-enabled: true",
+ "ds-cfg-virtual-attribute-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
+ "ds-cfg-virtual-attribute-type: description",
+ ""
+ };
@@ -98,18 +192,31 @@
@DataProvider(name = "createManagedObjectExceptions")
public Object[][] createManagedObjectExceptions() {
return new Object[][] {
- { new javax.naming.CommunicationException(),
- CommunicationException.class },
- { new javax.naming.ServiceUnavailableException(),
- CommunicationException.class },
- { new javax.naming.CannotProceedException(),
- CommunicationException.class },
- { new javax.naming.NameAlreadyBoundException(),
- ManagedObjectAlreadyExistsException.class },
- { new javax.naming.NoPermissionException(),
- AuthorizationException.class },
- { new OperationNotSupportedException(),
- OperationRejectedException.class } };
+ {
+ new javax.naming.CommunicationException(),
+ CommunicationException.class
+ },
+ {
+ new javax.naming.ServiceUnavailableException(),
+ CommunicationException.class
+ },
+ {
+ new javax.naming.CannotProceedException(),
+ CommunicationException.class
+ },
+ {
+ new javax.naming.NameAlreadyBoundException(),
+ ManagedObjectAlreadyExistsException.class
+ },
+ {
+ new javax.naming.NoPermissionException(),
+ AuthorizationException.class
+ },
+ {
+ new OperationNotSupportedException(),
+ OperationRejectedException.class
+ }
+ };
}
@@ -123,17 +230,30 @@
@DataProvider(name = "getManagedObjectExceptions")
public Object[][] getManagedObjectExceptions() {
return new Object[][] {
- { new javax.naming.CommunicationException(),
- CommunicationException.class },
- { new javax.naming.ServiceUnavailableException(),
- CommunicationException.class },
- { new javax.naming.CannotProceedException(),
- CommunicationException.class },
- { new javax.naming.NameNotFoundException(),
- ManagedObjectNotFoundException.class },
- { new javax.naming.NoPermissionException(),
- AuthorizationException.class },
- { new OperationNotSupportedException(), CommunicationException.class } };
+ {
+ new javax.naming.CommunicationException(),
+ CommunicationException.class
+ },
+ {
+ new javax.naming.ServiceUnavailableException(),
+ CommunicationException.class
+ },
+ {
+ new javax.naming.CannotProceedException(),
+ CommunicationException.class
+ },
+ {
+ new javax.naming.NameNotFoundException(),
+ ManagedObjectNotFoundException.class
+ },
+ {
+ new javax.naming.NoPermissionException(),
+ AuthorizationException.class
+ },
+ {
+ new OperationNotSupportedException(), CommunicationException.class
+ }
+ };
}
@@ -149,6 +269,17 @@
// This test suite depends on having the schema available, so
// we'll start the server.
TestCaseUtils.startServer();
+ LDAPProfile.getInstance().pushWrapper(new MockLDAPProfile());
+ }
+
+
+
+ /**
+ * Tears down test environment.
+ */
+ @AfterClass
+ public void tearDown() {
+ LDAPProfile.getInstance().popWrapper();
}
@@ -162,46 +293,22 @@
@Test
public void testCreateChildManagedObject() throws Exception {
CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
- "cn=test child 3,cn=test-children,cn=test parent 1,cn=test-parents");
+ "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 3");
- c.addExpectedAttribute("objectclass", "top", "ds-cfg-test-child");
+ 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");
- // LDAP encoding uses base unit.
- c.addExpectedAttribute("ds-cfg-heartbeat-interval", "10000ms");
-
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn
- .getInstance(), "test child 3", null);
- child.setHeartbeatInterval(10000L);
- child.commit();
-
- c.assertEntryIsCreated();
- }
-
-
-
- /**
- * Tests creation of a child managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testCreateChildManagedObjectDefault() throws Exception {
- CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
- "cn=test child 3,cn=test-children,cn=test parent 1,cn=test-parents");
- c.importLDIF(TEST_LDIF);
- c.addExpectedAttribute("cn", "test child 3");
- c.addExpectedAttribute("objectclass", "top", "ds-cfg-test-child");
-
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
- TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn
- .getInstance(), "test child 3", null);
+ .getInstance(), "test child new", null);
+ child.setMandatoryBooleanProperty(true);
+ child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
child.commit();
c.assertEntryIsCreated();
@@ -234,10 +341,12 @@
};
c.importLDIF(TEST_LDIF);
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
try {
- TestParentCfgClient parent = createTestParent(ctx, "test parent 3");
+ TestParentCfgClient parent = createTestParent(ctx, "test parent new");
+ parent.setMandatoryBooleanProperty(true);
+ parent.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
parent.commit();
} catch (Exception e) {
Assert.assertEquals(e.getClass(), expected);
@@ -255,41 +364,20 @@
@Test
public void testCreateTopLevelManagedObject() throws Exception {
CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
- "cn=test parent 3,cn=test-parents");
+ "cn=test parent new,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
- c.addExpectedAttribute("cn", "test parent 3");
- c.addExpectedAttribute("objectclass", "top", "ds-cfg-test-parent");
- c.addExpectedAttribute("ds-cfg-maximum-length", "54321");
- c.addExpectedAttribute("ds-cfg-minimum-length", "12345");
+ c.addExpectedAttribute("cn", "test parent 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,
- new MockLDAPProfile());
- TestParentCfgClient parent = createTestParent(ctx, "test parent 3");
- parent.setMaximumLength(54321);
- parent.setMinimumLength(12345);
- parent.commit();
- c.assertEntryIsCreated();
- }
-
-
-
- /**
- * Tests creation of a top-level managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testCreateTopLevelManagedObjectDefault() throws Exception {
- CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
- "cn=test parent 3,cn=test-parents");
- c.importLDIF(TEST_LDIF);
- c.addExpectedAttribute("cn", "test parent 3");
- c.addExpectedAttribute("objectclass", "top", "ds-cfg-test-parent");
-
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
- TestParentCfgClient parent = createTestParent(ctx, "test parent 3");
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = createTestParent(ctx, "test parent new");
+ parent.setMandatoryBooleanProperty(true);
+ parent.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
parent.commit();
c.assertEntryIsCreated();
}
@@ -305,12 +393,20 @@
*/
@Test
public void testGetChildManagedObject() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- TestChildCfgClient child = parent.getTestChild("test child 2");
- Assert.assertEquals(child.getHeartbeatInterval(), 12345000);
- Assert.assertEquals(child.getMinimumLength(), 11111);
- Assert.assertEquals(child.getMaximumLength(), 22222);
+ TestChildCfgClient child = parent.getTestChild("test child 3");
+ Assert.assertEquals(child.isMandatoryBooleanProperty(), Boolean.TRUE);
+ Assert.assertEquals(child.getMandatoryClassProperty(),
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ Assert.assertEquals(child.getMandatoryReadOnlyAttributeTypeProperty(),
+ DirectoryServer.getAttributeType("description"));
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty1(),
+ "dc=default value c3v1,dc=com", "dc=default value c3v2,dc=com");
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty2(),
+ "dc=default value c3v3,dc=com", "dc=default value c3v4,dc=com");
}
@@ -323,18 +419,26 @@
*/
@Test
public void testGetChildManagedObjectDefault() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
TestChildCfgClient child = parent.getTestChild("test child 1");
- Assert.assertEquals(child.getHeartbeatInterval(), 1000);
- Assert.assertEquals(child.getMinimumLength(), 10000);
- Assert.assertEquals(child.getMaximumLength(), 456);
+ Assert.assertEquals(child.isMandatoryBooleanProperty(), Boolean.TRUE);
+ Assert.assertEquals(child.getMandatoryClassProperty(),
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ Assert.assertEquals(child.getMandatoryReadOnlyAttributeTypeProperty(),
+ DirectoryServer.getAttributeType("description"));
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty1(),
+ "dc=domain1,dc=com", "dc=domain2,dc=com", "dc=domain3,dc=com");
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty2(),
+ "dc=domain1,dc=com", "dc=domain2,dc=com", "dc=domain3,dc=com");
}
/**
- * Tests retrieval of a top-level managed object using fails when an
+ * Tests retrieval of a top-level managed object fails when an
* underlying NamingException occurs.
*
* @param cause
@@ -358,8 +462,7 @@
};
c.importLDIF(TEST_LDIF);
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
try {
getTestParent(ctx, "test parent 2");
} catch (Exception e) {
@@ -378,10 +481,17 @@
*/
@Test
public void testGetTopLevelManagedObject() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 2");
- Assert.assertEquals(parent.getMinimumLength(), 10000);
- Assert.assertEquals(parent.getMaximumLength(), 20000);
+ Assert.assertEquals(parent.isMandatoryBooleanProperty(), Boolean.TRUE);
+ Assert.assertEquals(parent.getMandatoryClassProperty(),
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ Assert.assertEquals(parent.getMandatoryReadOnlyAttributeTypeProperty(),
+ DirectoryServer.getAttributeType("description"));
+ assertDNSetEquals(parent.getOptionalMultiValuedDNProperty(),
+ "dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com");
}
@@ -395,183 +505,17 @@
*/
@Test
public void testGetTopLevelManagedObjectDefault() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
- TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- Assert.assertEquals(parent.getMinimumLength(), 123);
- Assert.assertEquals(parent.getMaximumLength(), 456);
- }
-
-
-
- /**
- * Tests listing of child managed objects.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testListChildManagedObjects() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
- TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- String[] actual = parent.listTestChildren();
- String[] expected = new String[] { "test child 1", "test child 2" };
- Assert.assertEqualsNoOrder(actual, expected);
- }
-
-
-
- /**
- * Tests listing of child managed objects when their are not any.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testListChildManagedObjectsEmpty() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
- TestParentCfgClient parent = getTestParent(ctx, "test parent 2");
- String[] actual = parent.listTestChildren();
- String[] expected = new String[] {};
- Assert.assertEqualsNoOrder(actual, expected);
- }
-
-
-
- /**
- * Tests listing of top level managed objects.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testListTopLevelManagedObjects() throws Exception {
- ManagementContext ctx = getManagementContext(TEST_LDIF);
- String[] actual = listTestParents(ctx);
- String[] expected = new String[] { "test parent 1", "test parent 2" };
- Assert.assertEqualsNoOrder(actual, expected);
- }
-
-
-
- /**
- * Tests listing of top level managed objects when their are not
- * any.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testListTopLevelManagedObjectsEmpty() throws Exception {
- ManagementContext ctx = getManagementContext();
- String[] actual = listTestParents(ctx);
- String[] expected = new String[] {};
- Assert.assertEqualsNoOrder(actual, expected);
- }
-
-
-
- /**
- * Tests modification of a child managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testModifyChildManagedObjectResetToDefault() throws Exception {
- ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
- "cn=test child 2,cn=test-children,cn=test parent 1,cn=test-parents");
+ MockLDAPConnection c = new MockLDAPConnection();
c.importLDIF(TEST_LDIF);
- c.addExpectedModification("ds-cfg-heartbeat-interval");
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- TestChildCfgClient child = parent.getTestChild("test child 2");
- child.setHeartbeatInterval(null);
- child.commit();
- Assert.assertTrue(c.isEntryModified());
- }
-
-
-
- /**
- * Tests modification of a top-level managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testModifyTopLevelManagedObjectNoChanges() throws Exception {
- ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
- "cn=test parent 1,cn=test-parents");
- c.importLDIF(TEST_LDIF);
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
- TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- parent.commit();
- Assert.assertFalse(c.isEntryModified());
- }
-
-
-
- /**
- * Tests modification of a top-level managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testModifyTopLevelManagedObjectWithChanges() throws Exception {
- ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
- "cn=test parent 1,cn=test-parents");
- c.importLDIF(TEST_LDIF);
- c.addExpectedModification("ds-cfg-maximum-length", "54321");
- c.addExpectedModification("ds-cfg-minimum-length", "12345");
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
- TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- parent.setMaximumLength(54321);
- parent.setMinimumLength(12345);
- parent.commit();
- Assert.assertTrue(c.isEntryModified());
- }
-
-
-
- /**
- * Tests removal of a child managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testRemoveChildManagedObject() throws Exception {
- DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection(
- "cn=test child 1,cn=test-children,cn=test parent 1,cn=test-parents");
- c.importLDIF(TEST_LDIF);
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
- TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
- parent.removeTestChild("test child 1");
- c.assertSubtreeIsDeleted();
- }
-
-
-
- /**
- * Tests removal of a top-level managed object.
- *
- * @throws Exception
- * If an unexpected error occurred.
- */
- @Test
- public void testRemoveTopLevelManagedObject() throws Exception {
- DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection(
- "cn=test parent 1,cn=test-parents");
- c.importLDIF(TEST_LDIF);
- ManagementContext ctx = LDAPManagementContext.createFromContext(c,
- new MockLDAPProfile());
- removeTestParent(ctx, "test parent 1");
- c.assertSubtreeIsDeleted();
+ Assert.assertEquals(parent.isMandatoryBooleanProperty(), Boolean.TRUE);
+ Assert.assertEquals(parent.getMandatoryClassProperty(),
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ Assert.assertEquals(parent.getMandatoryReadOnlyAttributeTypeProperty(),
+ DirectoryServer.getAttributeType("description"));
+ assertDNSetEquals(parent.getOptionalMultiValuedDNProperty(),
+ "dc=domain1,dc=com", "dc=domain2,dc=com", "dc=domain3,dc=com");
}
@@ -585,24 +529,35 @@
@Test
public void testInheritedDefaultValues1() throws Exception {
CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
- "cn=test child 3,cn=test-children,cn=test parent 1,cn=test-parents");
+ "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 3");
- c.addExpectedAttribute("objectclass", "top", "ds-cfg-test-child");
+ 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,
- new MockLDAPProfile());
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn
- .getInstance(), "test child 3", null);
+ .getInstance(), "test child new", null);
- // Inherits from parent (test parent 1).
- Assert.assertEquals(child.getMinimumLength(), 10000);
-
- // Inherits from test parent 2.
- Assert.assertEquals(child.getMaximumLength(), 456);
+ // Check pre-commit values.
+ Assert.assertEquals(child.isMandatoryBooleanProperty(), null);
+ Assert.assertEquals(child.getMandatoryClassProperty(),
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ Assert
+ .assertEquals(child.getMandatoryReadOnlyAttributeTypeProperty(), null);
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty1(),
+ "dc=domain1,dc=com", "dc=domain2,dc=com", "dc=domain3,dc=com");
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty2(),
+ "dc=domain1,dc=com", "dc=domain2,dc=com", "dc=domain3,dc=com");
// Check that the default values are not committed.
+ child.setMandatoryBooleanProperty(true);
+ child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
child.commit();
c.assertEntryIsCreated();
@@ -619,24 +574,35 @@
@Test
public void testInheritedDefaultValues2() throws Exception {
CreateEntryMockLDAPConnection c = new CreateEntryMockLDAPConnection(
- "cn=test child 3,cn=test-children,cn=test parent 2,cn=test-parents");
+ "cn=test child new,cn=test children,cn=test parent 2,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
- c.addExpectedAttribute("cn", "test child 3");
- c.addExpectedAttribute("objectclass", "top", "ds-cfg-test-child");
+ 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,
- new MockLDAPProfile());
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
TestParentCfgClient parent = getTestParent(ctx, "test parent 2");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn
- .getInstance(), "test child 3", null);
+ .getInstance(), "test child new", null);
- // Inherits from parent (test parent 2).
- Assert.assertEquals(child.getMinimumLength(), 10000);
-
- // Inherits from test parent 2.
- Assert.assertEquals(child.getMaximumLength(), 20000);
+ // Check pre-commit values.
+ Assert.assertEquals(child.isMandatoryBooleanProperty(), null);
+ Assert.assertEquals(child.getMandatoryClassProperty(),
+ "org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
+ Assert
+ .assertEquals(child.getMandatoryReadOnlyAttributeTypeProperty(), null);
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty1(),
+ "dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com");
+ assertDNSetEquals(child.getOptionalMultiValuedDNProperty2(),
+ "dc=default value p2v1,dc=com", "dc=default value p2v2,dc=com");
// Check that the default values are not committed.
+ child.setMandatoryBooleanProperty(true);
+ child.setMandatoryReadOnlyAttributeTypeProperty(DirectoryServer
+ .getAttributeType("description"));
child.commit();
c.assertEntryIsCreated();
@@ -644,6 +610,202 @@
+ /**
+ * Tests listing of child managed objects.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testListChildManagedObjects() throws Exception {
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ String[] actual = parent.listTestChildren();
+ String[] expected = new String[] {
+ "test child 1", "test child 2", "test child 3"
+ };
+ Assert.assertEqualsNoOrder(actual, expected);
+ }
+
+
+
+ /**
+ * Tests listing of child managed objects when their are not any.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testListChildManagedObjectsEmpty() throws Exception {
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 3");
+ String[] actual = parent.listTestChildren();
+ String[] expected = new String[] {};
+ Assert.assertEqualsNoOrder(actual, expected);
+ }
+
+
+
+ /**
+ * Tests listing of top level managed objects.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testListTopLevelManagedObjects() throws Exception {
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ String[] actual = listTestParents(ctx);
+ String[] expected = new String[] {
+ "test parent 1", "test parent 2", "test parent 3"
+ };
+ Assert.assertEqualsNoOrder(actual, expected);
+ }
+
+
+
+ /**
+ * Tests listing of top level managed objects when their are not
+ * any.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testListTopLevelManagedObjectsEmpty() throws Exception {
+ String[] ldif = {};
+ MockLDAPConnection c = new MockLDAPConnection();
+ c.importLDIF(ldif);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ String[] actual = listTestParents(ctx);
+ String[] expected = new String[] {};
+ Assert.assertEqualsNoOrder(actual, expected);
+ }
+
+
+
+ /**
+ * Tests modification of a child managed object.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testModifyChildManagedObjectResetToDefault() throws Exception {
+ 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());
+ }
+
+
+
+ /**
+ * Tests modification of a top-level managed object.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testModifyTopLevelManagedObjectNoChanges() throws Exception {
+ ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
+ "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.commit();
+ Assert.assertFalse(c.isEntryModified());
+ }
+
+
+
+ /**
+ * Tests modification of a top-level managed object.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testModifyTopLevelManagedObjectWithChanges() throws Exception {
+ ModifyEntryMockLDAPConnection c = new ModifyEntryMockLDAPConnection(
+ "cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ c.addExpectedModification("ds-cfg-virtual-attribute-enabled", "false");
+ c.addExpectedModification("ds-cfg-virtual-attribute-base-dn",
+ "dc=mod1,dc=com", "dc=mod2,dc=com");
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ TestParentCfgClient parent = getTestParent(ctx, "test parent 1");
+ parent.setMandatoryBooleanProperty(false);
+ parent.setOptionalMultiValuedDNProperty(Arrays.asList(DN
+ .decode("dc=mod1,dc=com"), DN.decode("dc=mod2,dc=com")));
+ parent.commit();
+ Assert.assertTrue(c.isEntryModified());
+ }
+
+
+
+ /**
+ * Tests removal of a child managed object.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testRemoveChildManagedObject() throws Exception {
+ 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();
+ }
+
+
+
+ /**
+ * Tests removal of a top-level managed object.
+ *
+ * @throws Exception
+ * If an unexpected error occurred.
+ */
+ @Test
+ public void testRemoveTopLevelManagedObject() throws Exception {
+ DeleteSubtreeMockLDAPConnection c = new DeleteSubtreeMockLDAPConnection(
+ "cn=test parent 1,cn=test parents,cn=config");
+ c.importLDIF(TEST_LDIF);
+ ManagementContext ctx = LDAPManagementContext.createFromContext(c);
+ removeTestParent(ctx, "test parent 1");
+ c.assertSubtreeIsDeleted();
+ }
+
+
+
+ // 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()];
+ int i = 0;
+ for (DN dn : actual) {
+ actualStrings[i] = dn.toString();
+ i++;
+ }
+ Assert.assertEqualsNoOrder(actualStrings, expected);
+ }
+
+
+
// Create the named test parent managed object.
private TestParentCfgClient createTestParent(ManagementContext context,
String name) throws ManagedObjectDecodingException,
@@ -652,21 +814,13 @@
CommunicationException {
ManagedObject<RootCfgClient> root = context
.getRootConfigurationManagedObject();
- return root.createChild(TestParentCfgDefn.RD_TEST_PARENT,
+ return root.createChild(
+ org.opends.server.admin.TestCfg.RD_TEST_ONE_TO_MANY_PARENT,
TestParentCfgDefn.getInstance(), name, null).getConfiguration();
}
- // Creates a management context using the provided LDIF.
- private ManagementContext getManagementContext(String... ldif) {
- MockLDAPConnection c = new MockLDAPConnection();
- c.importLDIF(ldif);
- return LDAPManagementContext.createFromContext(c, new MockLDAPProfile());
- }
-
-
-
// Retrieve the named test parent managed object.
private TestParentCfgClient getTestParent(ManagementContext context,
String name) throws DefinitionDecodingException,
@@ -675,7 +829,8 @@
CommunicationException {
ManagedObject<RootCfgClient> root = context
.getRootConfigurationManagedObject();
- return root.getChild(TestParentCfgDefn.RD_TEST_PARENT, name)
+ return root.getChild(
+ org.opends.server.admin.TestCfg.RD_TEST_ONE_TO_MANY_PARENT, name)
.getConfiguration();
}
@@ -687,7 +842,8 @@
CommunicationException {
ManagedObject<RootCfgClient> root = context
.getRootConfigurationManagedObject();
- return root.listChildren(TestParentCfgDefn.RD_TEST_PARENT);
+ return root
+ .listChildren(org.opends.server.admin.TestCfg.RD_TEST_ONE_TO_MANY_PARENT);
}
@@ -699,6 +855,7 @@
CommunicationException {
ManagedObject<RootCfgClient> root = context
.getRootConfigurationManagedObject();
- root.removeChild(TestParentCfgDefn.RD_TEST_PARENT, name);
+ root.removeChild(
+ org.opends.server.admin.TestCfg.RD_TEST_ONE_TO_MANY_PARENT, name);
}
}
--
Gitblit v1.10.0