mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
04.52.2014 ba6ebe365fcf87dd109a4ef83402647b31575c31
Add support for SearchScope.SUBORDINATES to MemoryBackend
2 files modified
24 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/MemoryBackend.java 6 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java 18 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/MemoryBackend.java
@@ -398,7 +398,8 @@
                    sendEntry(attributeFilter, resultHandler, baseEntry);
                }
                resultHandler.handleResult(newResult(ResultCode.SUCCESS));
            } else if (scope.equals(SearchScope.SINGLE_LEVEL) || scope.equals(SearchScope.WHOLE_SUBTREE)) {
            } else if (scope.equals(SearchScope.SINGLE_LEVEL) || scope.equals(SearchScope.SUBORDINATES)
                || scope.equals(SearchScope.WHOLE_SUBTREE)) {
                searchWithSubordinates(requestContext, resultHandler, dn, matcher, attributeFilter,
                        request.getSizeLimit(), scope, request.getControl(
                                SimplePagedResultsControl.DECODER, new DecodeOptions()));
@@ -502,7 +503,8 @@
        int position = 0;
        for (final Entry entry : subtree.values()) {
            requestContext.checkIfCancelled(false);
            if (scope.equals(SearchScope.WHOLE_SUBTREE) || entry.getName().isChildOf(dn)) {
            if (scope.equals(SearchScope.WHOLE_SUBTREE) || entry.getName().isChildOf(dn)
                || (scope.equals(SearchScope.SUBORDINATES) && !entry.getName().equals(dn))) {
                if (matcher.matches(entry).toBoolean()) {
                    /*
                     * This entry is going to be returned to the client so it
opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java
@@ -456,6 +456,24 @@
    }
    @Test
    public void testSearchSubordinatesReturnsAllEntries() throws Exception {
        final Connection connection = getConnection();
        Collection<SearchResultEntry> entries = new ArrayList<SearchResultEntry>();
        connection.search(Requests.newSearchRequest("dc=com", SearchScope.SUBORDINATES, "(objectclass=*)"), entries);
        assertThat(entries).hasSize(numberOfEntriesInBackend - 1);
    }
    @Test
    public void testSearchSubordinatesEntries() throws Exception {
        int numberOfUsers = 5;
        final Connection connection = getConnection();
        Collection<SearchResultEntry> entries = new ArrayList<SearchResultEntry>();
        connection.search(Requests.newSearchRequest("ou=People,dc=example,dc=com", SearchScope.SUBORDINATES,
            "(objectclass=*)"), entries);
        assertThat(entries).hasSize(numberOfUsers);
    }
    @Test
    public void testSearchSubtreeWithSizeLimit() throws Exception {
        final Connection connection = getConnection();
        Collection<SearchResultEntry> entries = new ArrayList<SearchResultEntry>();