ParameterOptionVisitor implements OptionVisitor { public ParameterOptionVisitor visitAll(final Iterable<Option> options) { options.forEach(o -> o.accept(this)); return this; } ParameterOptionVisitor(final FieldExpressionFactory fieldExpressionFactory,
            final QueryBuilder queryBuilder); ParameterOptionVisitor visitAll(final Iterable<Option> options); @Override void visit(final LimitOption limitOption); @Override void visit(final org.eclipse.ditto.model.thingsearch.SortOption sortOption); @Override void visit(final CursorOption cursorOption); @Override void visit(final SizeOption sizeOption);  }
@Test public void visitLimitOption() { visitor.visitAll(Collections.singletonList(SearchModelFactory.newLimitOption(KNOWN_SKIP, KNOWN_LIMIT))); verify(qbMock).skip(KNOWN_SKIP); verify(qbMock).limit(KNOWN_LIMIT); }
@Test public void visitSortOptionWithSingleSortOption() { final SortOption sortOption = SearchModelFactory.newSortOption(POINTER_1, SortOptionEntry.SortOrder.ASC); visitor.visitAll(Collections.singletonList(sortOption)); verify(exprFactoryMock).sortBy(POINTER_1.toString()); verify(qbMock).sort( Collections.singletonList(new org.eclipse.ditto.model.query.SortOption(exprMock, SortDirection.ASC))); }
@Test(expected = IllegalArgumentException.class) public void visitUnsupportedSortExpression() { final JsonPointer unsupportedProperty = JsonPointer.of("unsupportedExpr"); final SortOption sortOption = SearchModelFactory.newSortOption(unsupportedProperty, SortOptionEntry.SortOrder.ASC); when(exprFactoryMock.sortBy(unsupportedProperty.toString())) .thenThrow(new IllegalArgumentException("Unsupported expr")); visitor.visitAll(Collections.singletonList(sortOption)); }
@Test public void visitSortOptionMultiple() { SortOption sortOption = SearchModelFactory.newSortOption(Collections.emptyList()); sortOption = sortOption.add(POINTER_2, SortOptionEntry.SortOrder.DESC); sortOption = sortOption.add(POINTER_1, SortOptionEntry.SortOrder.ASC); visitor.visitAll(Collections.singletonList(sortOption)); verify(exprFactoryMock).sortBy(POINTER_2.toString()); verify(exprFactoryMock).sortBy(POINTER_1.toString()); verify(qbMock).sort( Arrays.asList(new org.eclipse.ditto.model.query.SortOption(exprMock, SortDirection.DESC), new org.eclipse.ditto.model.query.SortOption(exprMock, SortDirection.ASC))); }
@Test public void visitLimitOptionAndSortOption() { final LimitOption limitOption = SearchModelFactory.newLimitOption(KNOWN_SKIP, KNOWN_LIMIT); SortOption sortOption = SearchModelFactory.newSortOption(Collections.emptyList()); sortOption = sortOption.add(POINTER_1, SortOptionEntry.SortOrder.ASC); visitor.visitAll(Arrays.asList(limitOption, sortOption)); verify(qbMock).skip(KNOWN_SKIP); verify(qbMock).limit(KNOWN_LIMIT); verify(exprFactoryMock).sortBy(POINTER_1.toString()); verify(qbMock).sort( Collections.singletonList(new org.eclipse.ditto.model.query.SortOption(exprMock, SortDirection.ASC))); }
@Test public void visitCursorAndSizeOptions() { final Option cursorOption = SearchModelFactory.newCursorOption("cursor"); final Option sizeOption = SearchModelFactory.newSizeOption(123); visitor.visitAll(Arrays.asList(cursorOption, sizeOption)); verify(qbMock).skip(0); verify(qbMock).size(123); verifyNoMoreInteractions(qbMock); }