LDIFBackendTestCase.java revision 763a75aeed1a7731ddb95b99496aa7c1bf206ed0
/*
* 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.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* A set of test cases for the LDIF backend.
*/
public class LDIFBackendTestCase
extends BackendTestCase
{
/**
* Ensures that the Directory Server is running and that the LDIF backend
* is populated with sample data.
*
* @throws Exception If an unexpected problem occurs.
*/
{
"define suffix=o=ldif",
"define numusers=25",
"",
"branch: [suffix]",
"",
"branch: ou=People,[suffix]",
"subordinateTemplate: person:[numusers]",
"",
"template: person",
"rdnAttr: uid",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"givenName: <random:alpha:6>",
"sn: <random:alpha:6>",
"cn: {givenName} {sn}",
"uid: user.<sequential:1>",
"userPassword: password");
// Create a temporary test LDIF file.
",cn=Scheduled Tasks,cn=Tasks";
"dn: " + taskDN,
"objectclass: top",
"objectclass: ds-task",
"objectclass: ds-task-import",
"ds-task-class-name: org.opends.server.tasks.ImportTask",
"ds-task-import-backend-id: ldifRoot",
assertNotNull(t);
}
/**
* Tests to ensure that add and delete operations (including subtree delete)
* work as expected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testAddAndDelete()
throws Exception
{
// Add a number of entries to the server.
"dn: ou=dummy,o=ldif",
"changetype: add",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: dummy",
"",
"dn: ou=sub1,ou=dummy,o=ldif",
"changetype: add",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: sub1",
"",
"dn: ou=sub2,ou=dummy,o=ldif",
"changetype: add",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: sub2",
"",
"dn: ou=sub3,ou=dummy,o=ldif",
"changetype: add",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: sub3",
"",
"dn: ou=sub4,ou=dummy,o=ldif",
"changetype: add",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: sub4",
"",
"dn: ou=sub5,ou=dummy,o=ldif",
"changetype: add",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: sub5");
// Verify that we can delete a single leaf entry.
"dn: ou=sub5,ou=dummy,o=ldif",
"changetype: delete");
// Verify that a default attempt to delete a non-leaf entry will fail.
"dn: ou=dummy,o=ldif",
"changetype: delete");
{
"-h", "127.0.0.1",
"-D", "cn=Directory Manager",
"-w", "password",
"-f", subtreeDeletePath
};
// Verify that the subtree delete will succeed if we include the subtree
// delete control in the request.
{
"-h", "127.0.0.1",
"-D", "cn=Directory Manager",
"-w", "password",
"-J", "subtreeDelete",
"-f", subtreeDeletePath
};
}
/**
* Tests an attempt to add an entry to the LDIF backend when an entry with
* the same DN already exists.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testAddAlreadyExists()
throws Exception
{
"dn: ou=People,o=ldif",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People");
}
/**
* Tests an attempt to add an entry to the LDIF backend when the parent for
* the new entry doesn't exist.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testAddNoParent()
throws Exception
{
"dn: ou=test,ou=doesntexist,o=ldif",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: test");
}
/**
* Tests the ability to add the base entry to the backend. This will first
* perform a subtree delete to get rid of everything, then add the base entry,
* and then restore the original content.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testAddBaseEntry() throws Exception
{
"dn: o=ldif",
"changetype: delete");
{
"-h", "127.0.0.1",
"-D", "cn=Directory Manager",
"-w", "password",
"-J", "subtreeDelete",
"-f", path
};
"dn: o=ldif",
"objectClass: top",
"objectClass: organization",
"o: ldif");
setUp();
}
/**
* Tests to ensure that we can bind as a user contained in an LDIF backend.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testBind()
throws Exception
{
{
"-h", "127.0.0.1",
"-D", "uid=user.1,ou=People,o=ldif",
"-w", "password",
"-b", "o=ldif",
"-s", "base",
"(objectClass=*)"
};
}
/**
* Tests to ensure that we can perform a compare against entries in an LDIF
* backend.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompare() throws Exception
{
}
/**
* Tests to ensure that we can modify entries in the LDIF backend.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testModify() throws Exception
{
"dn: o=ldif",
"changetype: modify",
"replace: description",
"description: foo");
{
"-h", "127.0.0.1",
"-D", "cn=Directory Manager",
"-w", "password",
"-f", path
};
}
/**
* Tests a simple modify DN operation that targets a single leaf entry.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSimpleModifyDN()
throws Exception
{
"dn: ou=leaf before,o=ldif",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: leaf before");
}
/**
* Tests a modify DN operation in which the target entry already exists.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testModifyDNTargetAlreadyExists()
throws Exception
{
"dn: ou=new entry,o=ldif",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: new entry");
}
/**
* Tests a modify DN operation that targets a single leaf entry and provides a
* new superior DN.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testModifyDNWithNewSuperior()
throws Exception
{
"dn: ou=leaf before,o=ldif",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: leaf before");
"ou=People,o=ldif");
}
/**
* Tests a modify DN operation that involves a subtree rename operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testModifyDNSubtreeRename()
throws Exception
{
}
/**
* Tests to ensure that a base-level search works as expected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testBaseSearch() throws Exception
{
}
/**
* Tests to ensure that a base-level search works as expected when the filter
* doesn't match the target entry.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testBaseSearchNonMatchingFilter() throws Exception
{
getRootConnection().processSearch(newSearchRequest("o=ldif", SearchScope.BASE_OBJECT, "(o=not ldif)"));
}
/**
* Tests to ensure that a base-level search works as expected when the target
* entry does not exist.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testBaseSearchNoSuchEntry() throws Exception
{
}
/**
* Tests to ensure that a single-level search works as expected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSingleLevelSearch() throws Exception
{
}
/**
* Tests to ensure that subtree search operations work as expected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSubtreeSearch() throws Exception
{
}
/**
* Tests to ensure that subordinate subtree search operations work as
* expected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSubordinateSubtreeSearch() throws Exception
{
}
/**
* Tests the {@code hasSubordinates} method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testHasSubordinates() throws Exception
{
Backend<?> b = getLDIFBackend();
try
{
fail("Expected an exception when calling hasSubordinates on a " +
"non-existent entry");
}
catch (DirectoryException de)
{
}
}
/**
* Tests the {@code numSubordinates} method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testNumSubordinates()
throws Exception
{
Backend<?> b = getLDIFBackend();
try
{
fail("Expected an exception when calling numSubordinates on a " +
"non-existent entry");
}
catch (DirectoryException de)
{
}
}
/**
* Tests LDIF export functionality.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testLDIFExport() throws Exception
{
Backend<?> b = getLDIFBackend();
",cn=Scheduled Tasks,cn=Tasks";
"dn: " + taskDN,
"objectclass: top",
"objectclass: ds-task",
"objectclass: ds-task-export",
"ds-task-class-name: org.opends.server.tasks.ExportTask",
"ds-task-export-backend-id: ldifRoot",
"ds-task-export-ldif-file: " + tempFilePath);
assertNotNull(t);
}
/**
* Tests a number of miscellaneous backend methods.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testMiscellaneousBackendMethods()
throws Exception
{
LDIFBackend b = getLDIFBackend();
try
{
b.createBackup(null);
fail("Expected an exception when calling createBackup");
} catch (DirectoryException de) {}
try
{
fail("Expected an exception when calling removeBackup");
} catch (DirectoryException de) {}
try
{
b.restoreBackup(null);
fail("Expected an exception when calling restoreBackup");
} catch (DirectoryException de) {}
assertNotNull(b.getClassName());
assertNotNull(b.getAlerts());
}
private LDIFBackend getLDIFBackend()
{
assertNotNull(b);
assertTrue(b instanceof LDIFBackend);
return (LDIFBackend) b;
}
}