Skip to content

Commit

Permalink
fix search query mutiple sort option
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stanchev <aleksandar.stanchev@bosch.com>
  • Loading branch information
alstanchev committed Nov 8, 2023
1 parent 804b35a commit a5c98aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -206,7 +206,8 @@ public static List<String> calculateOptions(final List<String> optionsString) {
}
return optionsString
.stream()
.flatMap(s -> Arrays.stream(s.split(",")))
.flatMap(s -> Arrays.stream(s.split("\\),")))
.map(s -> s.endsWith(")") ? s : s + ")")
.toList();
}

Expand Down
Expand Up @@ -49,15 +49,28 @@ public void postSearchThingsShouldGetParametersFromBody() {
final var formData = FormData.create(
List.of(
new Pair<>("filter", "and(like(definition,\"*test*\"))"),
new Pair<>("option", "sort(+thingId)"),
new Pair<>("option", "sort(+thingId,-attributes/type)"),
new Pair<>("option","limit(0,5)"),
new Pair<>("namespaces","org.eclipse.ditto,foo.bar")
));
final var result = underTest.run(HttpRequest.POST("/search/things")
.withEntity(formData.toEntity()));

result.assertStatusCode(StatusCodes.OK);
result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"filter\":\"and(and(like(definition,\\\"*test*\\\")))\",\"options\":[\"limit(0\",\"5)\",\"sort(+thingId)\"],\"namespaces\":[\"foo.bar\",\"org.eclipse.ditto\"]}");
result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"filter\":\"and(and(like(definition,\\\"*test*\\\")))\",\"options\":[\"limit(0,5)\",\"sort(+thingId,-attributes/type)\"],\"namespaces\":[\"foo.bar\",\"org.eclipse.ditto\"]}");
}
@Test
public void searchThingsShouldGetParametersFromUrl() {

final var result = underTest.run(HttpRequest.GET(
"/search/things?" +
"namespaces=org.eclipse.ditto&" +
"fields=thingId&" +
"option=sort(%2Bfeature/property,-attributes/type,%2BthingId),size(2),cursor(nextCursor)")
);

result.assertStatusCode(StatusCodes.OK);
result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"options\":[\"sort(+feature/property,-attributes/type,+thingId)\",\"size(2)\",\"cursor(nextCursor)\"],\"fields\":\"/thingId\",\"namespaces\":[\"org.eclipse.ditto\"]}");
}

@Test
Expand Down

0 comments on commit a5c98aa

Please sign in to comment.