| | |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * BackendImpl Tester. |
| | | */ |
| | | /** BackendImpl Tester. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class TestBackendImpl extends JebTestCase { |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testAddNoParent() throws Exception { |
| | | |
| | | try |
| | | { |
| | | for (Entry entry : entries) { |
| | |
| | | } |
| | | failBecauseExceptionWasNotThrown(DirectoryException.class); |
| | | } |
| | | catch (DirectoryException e) |
| | | catch (DirectoryException expected) |
| | | { |
| | | // expected |
| | | } |
| | | |
| | | } |
| | | |
| | | @Test(dependsOnMethods = "testAddNoParent") |
| | |
| | | backend.getNumberOfEntriesInBaseDN(DN.valueOf("ou=People,dc=test,dc=com")); |
| | | } |
| | | |
| | | |
| | | @Test(dependsOnMethods = "testAdd") |
| | | public void testSearchIndex() throws Exception { |
| | | Set<String> attribs = new LinkedHashSet<String>(); |
| | | Set<String> attribs = new LinkedHashSet<>(); |
| | | String debugString; |
| | | List<SearchResultEntry> result; |
| | | |
| | |
| | | { |
| | | int finalStartPos = debugString.indexOf("final=") + 13; |
| | | int finalEndPos = debugString.indexOf("]", finalStartPos); |
| | | int finalCount = Integer.valueOf(debugString.substring(finalStartPos, finalEndPos)); |
| | | int finalCount = Integer.parseInt(debugString.substring(finalStartPos, finalEndPos)); |
| | | assertEquals(finalCount, expectedCount); |
| | | } |
| | | |
| | |
| | | @Test(dependsOnMethods = {"testAdd", "testSearchIndex", |
| | | "testSearchScope", "testMatchedDN"}) |
| | | public void testDeleteEntry() throws Exception { |
| | | List<Control> noControls = new ArrayList<Control>(0); |
| | | List<Control> noControls = new ArrayList<>(0); |
| | | EntryContainer ec = |
| | | backend.getRootContainer().getEntryContainer(DN.valueOf("ou=People,dc=test,dc=com")); |
| | | |
| | |
| | | DN.valueOf("uid=user.539,ou=People,dc=test,dc=com")); |
| | | backend.deleteEntry(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), delete); |
| | | |
| | | |
| | | assertFalse(ec.entryExists(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"))); |
| | | assertNull(ec.getDN2ID().get(null, |
| | | DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), LockMode.DEFAULT)); |
| | |
| | | |
| | | private static List<AttributeIndexer> newAttributeIndexers(AttributeType attrType, MatchingRule matchingRule) |
| | | { |
| | | List<AttributeIndexer> indexers = new ArrayList<AttributeIndexer>(); |
| | | List<AttributeIndexer> indexers = new ArrayList<>(); |
| | | for (org.forgerock.opendj.ldap.spi.Indexer indexer : matchingRule.createIndexers(getOptions())) |
| | | { |
| | | indexers.add(new AttributeIndexer(attrType, indexer)); |
| | |
| | | |
| | | private static void assertIndexContainsID(List<? extends Indexer> indexers, Entry entry, Index index, EntryID entryID) |
| | | { |
| | | for (Indexer indexer : indexers) |
| | | { |
| | | Set<ByteString> addKeys = new HashSet<ByteString>(); |
| | | indexer.indexEntry(entry, addKeys); |
| | | |
| | | DatabaseEntry key = new DatabaseEntry(); |
| | | for (ByteString keyBytes : addKeys) |
| | | { |
| | | key.setData(keyBytes.toByteArray()); |
| | | assertEquals(index.containsID(null, key, entryID), TRUE); |
| | | } |
| | | } |
| | | assertIndexContainsID(indexers, entry, index, entryID, TRUE); |
| | | } |
| | | |
| | | private static void assertIndexContainsID(List<? extends Indexer> indexers, Entry entry, Index index, |
| | |
| | | { |
| | | for (Indexer indexer : indexers) |
| | | { |
| | | Set<ByteString> addKeys = new HashSet<ByteString>(); |
| | | Set<ByteString> addKeys = new HashSet<>(); |
| | | indexer.indexEntry(entry, addKeys); |
| | | |
| | | assertIndexContainsID(addKeys, index, entryID, expected); |
| | |
| | | ec.sharedLock.lock(); |
| | | try |
| | | { |
| | | List<Modification> modifications = new ArrayList<Modification>(); |
| | | List<Modification> modifications = new ArrayList<>(); |
| | | modifications.add(new Modification(ADD, create("title", "debugger"))); |
| | | |
| | | AttributeBuilder builder = new AttributeBuilder("title"); |
| | |
| | | nameIndex = ec.getAttributeIndex(name); |
| | | |
| | | // This current entry in the DB shouldn't be in the presence titleIndex. |
| | | addKeys = new HashSet<ByteString>(); |
| | | addKeys = new HashSet<>(); |
| | | addKeys.add(PresenceIndexer.presenceKey); |
| | | assertIndexContainsID(addKeys, titleIndex.getIndex("presence"), entryID, FALSE); |
| | | |
| | | // This current entry should be in the presence nameIndex. |
| | | addKeys = new HashSet<ByteString>(); |
| | | addKeys = new HashSet<>(); |
| | | addKeys.add(PresenceIndexer.presenceKey); |
| | | assertIndexContainsID(addKeys, nameIndex.getIndex("presence"), entryID, TRUE); |
| | | |
| | | List<Control> noControls = new ArrayList<Control>(0); |
| | | List<Control> noControls = new ArrayList<>(0); |
| | | ModifyOperationBasis modifyOp = new ModifyOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(), |
| | | noControls, DN.valueOf("uid=user.1,ou=People,dc=test,dc=com"), modifications); |
| | | |
| | |
| | | DN.valueOf("ou=People,dc=test,dc=com"), LockMode.DEFAULT); |
| | | assertTrue(newSuperiorID.compareTo(oldID) > 0); |
| | | |
| | | List<Control> noControls = new ArrayList<Control>(0); |
| | | List<Control> noControls = new ArrayList<>(0); |
| | | ModifyDNOperationBasis modifyDN = new ModifyDNOperationBasis( |
| | | getRootConnection(), nextOperationID(), nextMessageID(), |
| | | noControls, |
| | |
| | | assertEquals(backend.getNumberOfChildren(dn), -1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Provides a set of DNs for the matched DN test case. |
| | | * |
| | |
| | | */ |
| | | @DataProvider(name = "MatchedDNs") |
| | | public Object[][] initMatchedDNs() throws Exception { |
| | | |
| | | ResultCode success = ResultCode.SUCCESS; |
| | | ResultCode noSuchObject = ResultCode.NO_SUCH_OBJECT; |
| | | |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Executes an internal search operation and check the result code and |
| | | * matched DN field. |
| | |
| | | private static String substringIndexId() { |
| | | return SMR_CASE_IGNORE_NAME + ":" + getOptions().substringKeySize(); |
| | | } |
| | | |
| | | } |