Skip to content

Commit

Permalink
Ignore case for additional filters.
Browse files Browse the repository at this point in the history
This commits introduces support for starting and ending with
in combination with ignore case.
  • Loading branch information
meistermeier committed Mar 5, 2020
1 parent 4dc545e commit 3d28721
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/neo4j/ogm/cypher/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Filter ignoreCase() {
throw new IllegalStateException("ignoreCase is only supported for a filter based on property comparison");
} else {
PropertyComparison propertyComparision = (PropertyComparison) this.function;
if (!EnumSet.of(EQUALS, CONTAINING).contains(propertyComparision.getOperator())) {
if (!EnumSet.of(EQUALS, CONTAINING, STARTING_WITH, ENDING_WITH).contains(propertyComparision.getOperator())) {
throw new IllegalStateException(
String.format("ignoreCase is only supported for %s or %s comparison", EQUALS.name(),
CONTAINING.name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void clear() {
}

@Test
public void ignoreCaseShouldNotBeApplicableToComparisonOtherThanEquals() {
public void ignoreCaseShouldBeApplicableToEquals() {
final String emi = "EMI Studios, London";
session.save(new Studio(emi));
final Filter nameFilter = new Filter("name", ComparisonOperator.EQUALS, "eMi Studios, London").ignoreCase();
Expand All @@ -67,4 +67,37 @@ public void ignoreCaseShouldNotBeApplicableToComparisonOtherThanEquals() {
.extracting(Studio::getName)
.containsExactly(emi);
}

@Test
public void ignoreCaseShouldBeApplicableToContaining() {
final String emi = "EMI Studios, London";
session.save(new Studio(emi));
final Filter nameFilter = new Filter("name", ComparisonOperator.CONTAINING, "STUDIO").ignoreCase();
assertThat(session.loadAll(Studio.class, nameFilter, 0))
.hasSize(1)
.extracting(Studio::getName)
.containsExactly(emi);
}

@Test
public void ignoreCaseShouldBeApplicableToStartingWith() {
final String emi = "EMI Studios, London";
session.save(new Studio(emi));
final Filter nameFilter = new Filter("name", ComparisonOperator.STARTING_WITH, "em").ignoreCase();
assertThat(session.loadAll(Studio.class, nameFilter, 0))
.hasSize(1)
.extracting(Studio::getName)
.containsExactly(emi);
}

@Test
public void ignoreCaseShouldBeApplicableToEndingWith() {
final String emi = "EMI Studios, London";
session.save(new Studio(emi));
final Filter nameFilter = new Filter("name", ComparisonOperator.ENDING_WITH, "london").ignoreCase();
assertThat(session.loadAll(Studio.class, nameFilter, 0))
.hasSize(1)
.extracting(Studio::getName)
.containsExactly(emi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ public void equalComparisionShouldWork() {
assertThat(filter.toCypher("n", true)).isEqualTo("WHERE toLower(n.`thing`) = toLower($`thing_0`) ");
}

@Test
public void startingWithComparisionShouldWork() {
final String value = "someOtherThing";
Filter filter = new Filter("thing", ComparisonOperator.STARTING_WITH, value);
assertThat(filter.toCypher("n", true)).isEqualTo("WHERE n.`thing` STARTS WITH $`thing_0` ");

filter = new Filter("thing", ComparisonOperator.STARTING_WITH, value);
filter.ignoreCase();
assertThat(filter.toCypher("n", true)).isEqualTo("WHERE toLower(n.`thing`) STARTS WITH toLower($`thing_0`) ");
}

@Test
public void endingWithComparisionShouldWork() {
final String value = "someOtherThing";
Filter filter = new Filter("thing", ComparisonOperator.ENDING_WITH, value);
assertThat(filter.toCypher("n", true)).isEqualTo("WHERE n.`thing` ENDS WITH $`thing_0` ");

filter = new Filter("thing", ComparisonOperator.ENDING_WITH, value);
filter.ignoreCase();
assertThat(filter.toCypher("n", true)).isEqualTo("WHERE toLower(n.`thing`) ENDS WITH toLower($`thing_0`) ");
}

@Test
public void containingComparisionShouldWork() {
final String value = "someOtherThing";
Expand Down

0 comments on commit 3d28721

Please sign in to comment.