-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#559] Add unit tests for new field name visitor and little refactoring
* Add JavaDocs * Add static factory * return unmodifiable set * better namings * and other minor simplifications. Signed-off-by: Joel Bartelheimer <joel.bartelheimer@bosch.io>
- Loading branch information
Showing
3 changed files
with
86 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...uery/src/test/java/org/eclipse/ditto/rql/query/things/FieldNamesPredicateVisitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2021 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.rql.query.things; | ||
|
||
import java.util.Set; | ||
|
||
import org.assertj.core.api.JUnitSoftAssertions; | ||
import org.eclipse.ditto.rql.parser.internal.RqlPredicateParser; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test for {@link FieldNamesPredicateVisitor} | ||
*/ | ||
public final class FieldNamesPredicateVisitorTest { | ||
|
||
@Rule | ||
public final JUnitSoftAssertions softly = new JUnitSoftAssertions(); | ||
|
||
@Test | ||
public void verifyCorrectFiltering() { | ||
softly.assertThat(extractFieldsFromRql("and(eq(attributes/foo,1),exists(_created))")) | ||
.containsExactlyInAnyOrder("attributes/foo", "_created"); | ||
softly.assertThat(extractFieldsFromRql("or(exists(attributes/foo),exists(attributes/foo2))")) | ||
.containsExactlyInAnyOrder("attributes/foo", "attributes/foo2"); | ||
softly.assertThat(extractFieldsFromRql("eq(features/*/definition,\"t:t:1\")")) | ||
.containsExactlyInAnyOrder("features/*/definition"); | ||
softly.assertThat(extractFieldsFromRql("eq(/attributes/complex,\"!#$%&'(features)*+,/:;=?@[\\\\]{|}\\\" äaZ0\")")) | ||
.containsExactlyInAnyOrder("/attributes/complex"); | ||
} | ||
|
||
private static Set<String> extractFieldsFromRql(final String filter) { | ||
final FieldNamesPredicateVisitor fieldNameVisitor = FieldNamesPredicateVisitor.getNewInstance(); | ||
fieldNameVisitor.visit(RqlPredicateParser.parse(filter)); | ||
return fieldNameVisitor.getFieldNames(); | ||
} | ||
} |