Skip to content

Commit

Permalink
fix NullPointerException in cursor generation
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yufei (INST/ECS1) <yufei.cai@bosch-si.com>
  • Loading branch information
yufei-cai committed Apr 29, 2019
1 parent bcc9a19 commit acfbf31
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Expand Up @@ -145,7 +145,9 @@ private static Function<String, Object> seekToPath(final Document document) {
}

private static Object seekToPathImpl(final Document document, final String[] segments, final int i) {
if (i + 1 == segments.length) {
if (document == null) {
return null;
} else if (i + 1 == segments.length) {
return document.get(segments[i]);
} else {
return seekToPathImpl(document.get(segments[i], Document.class), segments, i + 1);
Expand Down
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors;

import java.util.Collections;

import org.bson.Document;
import org.eclipse.ditto.model.query.SortDirection;
import org.eclipse.ditto.model.query.SortOption;
import org.eclipse.ditto.model.query.expression.AttributeExpressionImpl;
import org.eclipse.ditto.model.query.expression.SortFieldExpression;
import org.junit.Test;

/**
* Tests {@link org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors.GetSortBsonVisitor}.
*/
public final class GetSortBsonVisitorTest {

@Test
public void handlesNullValues() {
final SortFieldExpression expression = new AttributeExpressionImpl("a/b/c/d/e/f/g");
final SortOption sortOption = new SortOption(expression, SortDirection.ASC);

GetSortBsonVisitor.sortValuesAsArray(new Document(), Collections.singletonList(sortOption));
}
}
Expand Up @@ -201,7 +201,7 @@ public void testCursorSearch() {

private QueryThings queryThings(final int size, final @Nullable String cursor) {
final List<String> options = new ArrayList<>();
options.add("sort(-attributes/c,+attributes/b,-attributes/a)");
options.add("sort(-attributes/c,+attributes/b,-attributes/a,+attributes/null/1,-attributes/null/2)");
options.add("size(" + size + ")");
if (cursor != null) {
options.add("cursor(" + cursor + ")");
Expand Down

0 comments on commit acfbf31

Please sign in to comment.