LDAPClientTest.java revision d70586b00b9530ab99ab4b8f003e9a54793e419f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
*/
@SuppressWarnings("javadoc")
@Test(singleThreaded = true)
public final class LDAPClientTest extends AdminTestCase {
// @Checkstyle:off
// Base entries.
"dn: cn=config",
"objectclass: top",
"objectclass: ds-cfg-branch",
"cn: config",
"",
"dn: cn=test parents,cn=config",
"objectclass: top",
"objectclass: ds-cfg-branch",
"cn: test-parents",
"",
// 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-test-parent-dummy",
"cn: test parent 1",
"ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-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-test-parent-dummy",
"cn: test parent 2",
"ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-attribute-type: description",
"ds-cfg-base-dn: dc=default value p2v1,dc=com",
"ds-cfg-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-test-parent-dummy",
"cn: test parent 3",
"ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-attribute-type: description",
"ds-cfg-base-dn: dc=default value p3v1,dc=com",
"ds-cfg-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-test-child-dummy",
"cn: test child 1",
"ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-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-test-child-dummy",
"cn: test child 2",
"ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-attribute-type: description",
"ds-cfg-base-dn: dc=default value c2v1,dc=com",
"ds-cfg-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-test-child-dummy",
"cn: test child 3",
"ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-attribute-type: description",
"ds-cfg-base-dn: dc=default value c3v1,dc=com",
"ds-cfg-base-dn: dc=default value c3v2,dc=com",
"ds-cfg-group-dn: dc=default value c3v3,dc=com",
"ds-cfg-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-test-child-dummy", "cn: test child 1", "ds-cfg-enabled: true",
"ds-cfg-java-class: org.opends.server.extensions.UserDefinedVirtualAttributeProvider",
"ds-cfg-attribute-type: description", "", };
// @Checkstyle:on
/**
* Provide valid naming exception to client API exception mappings.
*
* @return Returns valid naming exception to client API exception mappings.
*/
public Object[][] createManagedObjectExceptions() {
return new Object[][] {
// result code corresponding to exception thrown, expected
// exception, expected code result
}
/**
* Provide valid naming exception to client API exception mappings.
*
* @return Returns valid naming exception to client API exception mappings.
*/
public Object[][] getManagedObjectExceptions() {
return new Object[][] {
// result code corresponding to exception thrown, expected
// exception, expected code result
}
}
public void tearDown() {
}
/**
* Tests creation of a child managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testCreateChildManagedObject() throws Exception {
"cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedAttribute("ds-cfg-java-class",
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null);
child.setMandatoryBooleanProperty(true);
c.assertEntryIsCreated();
}
/**
* Tests creation of a top-level managed object using fails when an
* underlying exception occurs.
*/
}
};
try {
} catch (Exception e) {
} else {
}
}
}
/**
* Tests creation of a top-level managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testCreateTopLevelManagedObject() throws Exception {
new CreateEntryMockLDAPConnection("cn=test parent new,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedAttribute("ds-cfg-java-class", "org.opends.server.extensions.SomeVirtualAttributeProvider");
c.assertEntryIsCreated();
}
/**
* Tests retrieval of a child managed object with non-default values.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testGetChildManagedObject() throws Exception {
MockLDAPConnection c = new MockLDAPConnection();
c.importLDIF(TEST_LDIF);
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
"dc=default value c3v2,dc=com");
"dc=default value c3v4,dc=com");
}
/**
* Tests retrieval of a child managed object with default values.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testGetChildManagedObjectDefault() throws Exception {
MockLDAPConnection c = new MockLDAPConnection();
c.importLDIF(TEST_LDIF);
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
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 fails when an underlying
* ErrorResultException occurs.
*
* @param cause
* The ErrorResultException cause of the failure.
* @param expected
* The expected client API exception class.
*/
MockLDAPConnection c = new MockLDAPConnection() {
}
};
c.importLDIF(TEST_LDIF);
try {
} catch (Exception e) {
} else {
}
}
}
/**
* Tests retrieval of a top-level managed object with non-default values.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testGetTopLevelManagedObject() throws Exception {
MockLDAPConnection c = new MockLDAPConnection();
c.importLDIF(TEST_LDIF);
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
"dc=default value p2v2,dc=com");
}
/**
* Tests retrieval of a top-level managed object with default values.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testGetTopLevelManagedObjectDefault() throws Exception {
MockLDAPConnection c = new MockLDAPConnection();
c.importLDIF(TEST_LDIF);
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
assertDNSetEquals(parent.getOptionalMultiValuedDNProperty(), "dc=domain1,dc=com", "dc=domain2,dc=com",
"dc=domain3,dc=com");
}
/**
* Tests retrieval of relative inherited default values.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testInheritedDefaultValues1() throws Exception {
"cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedAttribute("ds-cfg-java-class",
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null);
// Check pre-commit values.
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
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);
c.assertEntryIsCreated();
}
/**
* Tests retrieval of relative inherited default values.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testInheritedDefaultValues2() throws Exception {
"cn=test child new,cn=test children,cn=test parent 2,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedAttribute("ds-cfg-java-class",
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null);
// Check pre-commit values.
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
"dc=default value p2v2,dc=com");
"dc=default value p2v2,dc=com");
// Check that the default values are not committed.
child.setMandatoryBooleanProperty(true);
c.assertEntryIsCreated();
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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 {
MockLDAPConnection c = new MockLDAPConnection();
}
/**
* Tests modification of a child managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testModifyChildManagedObjectResetToDefault() throws Exception {
"cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedModification("ds-cfg-base-dn");
}
/**
* Tests modification of a top-level managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testModifyTopLevelManagedObjectNoChanges() throws Exception {
new ModifyEntryMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
}
/**
* Tests modification of a top-level managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testModifyTopLevelManagedObjectWithChanges() throws Exception {
new ModifyEntryMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
parent.setMandatoryBooleanProperty(false);
}
/**
* Tests removal of a child managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testRemoveChildManagedObject() throws Exception {
"cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
}
/**
* Tests removal of a top-level managed object.
*
* @throws Exception
* If an unexpected error occurred.
*/
@Test
public void testRemoveTopLevelManagedObject() throws Exception {
new DeleteSubtreeMockLDAPConnection("cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
}
/**
* 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 {
try {
"cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedAttribute("ds-cfg-java-class",
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null);
child.setMandatoryBooleanProperty(true);
c.assertEntryIsCreated();
} finally {
// Clean up.
}
}
/**
* Tests creation of a child managed object fails when registered add
* constraints fail.
*
* @throws Exception
* If an unexpected error occurred.
*/
public void testAddConstraintFail() throws Exception {
try {
"cn=test child new,cn=test children,cn=test parent 1,cn=test parents,cn=config");
"org.opends.server.extensions.UserDefinedVirtualAttributeProvider");
TestChildCfgClient child = parent.createTestChild(TestChildCfgDefn.getInstance(), "test child new", null);
child.setMandatoryBooleanProperty(true);
} finally {
// Clean up.
}
}
/**
* 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 {
try {
"cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
} finally {
// Clean up.
}
}
/**
* Tests removal of a child managed object fails when registered remove
* constraints fails.
*
* @throws Exception
* If an unexpected error occurred.
*/
public void testRemoveConstraintFail() throws Exception {
try {
"cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
} finally {
// Clean up.
}
}
/**
* 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 {
try {
"cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedModification("ds-cfg-base-dn");
} finally {
// Clean up.
}
}
/**
* Tests modification of a child managed object fails when registered remove
* constraints fails.
*
* @throws Exception
* If an unexpected error occurred.
*/
public void testModifyConstraintFail() throws Exception {
try {
"cn=test child 2,cn=test children,cn=test parent 1,cn=test parents,cn=config");
c.importLDIF(TEST_LDIF);
c.addExpectedModification("ds-cfg-base-dn");
} finally {
// Clean up.
}
}
// Asserts that the actual set of DNs contains the expected values.
int i = 0;
i++;
}
}
// Create the named test parent managed object.
private TestParentCfgClient createTestParent(ManagementContext context, String name) throws Exception {
return root.createChild(TestCfg.getTestOneToManyParentRelationDefinition(), TestParentCfgDefn.getInstance(),
}
// Retrieve the named test parent managed object.
private TestParentCfgClient getTestParent(ManagementContext context, String name) throws Exception {
}
// List test parent managed objects.
}
// Remove the named test parent managed object.
}
}