/** * Sets the filter to ignore the case in case the underlying {@link Part} requires ignoring case and the property * actually supports it. Note: The method is modelled after {@link #setNestedAttributes(Part, Filter)} to have some * consistency. Preferable it should return a new filter. * * @param part * @param filter */ private void applyCaseInsensitivityIfShouldIgnoreCase(Part part, Filter filter) { switch (part.shouldIgnoreCase()) { case ALWAYS: Assert.state(canIgnoreCase(part), "Unable to ignore case of " + part.getProperty().getLeafType().getName() + " types, the property '" + part.getProperty().getSegment() + "' must reference a String"); filter.ignoreCase(); break; case WHEN_POSSIBLE: if (canIgnoreCase(part)) { filter.ignoreCase(); } break; case NEVER: default: break; } }
/** * Sets the filter to ignore the case in case the underlying {@link Part} requires ignoring case and the property * actually supports it. Note: The method is modelled after {@link #setNestedAttributes(Part, Filter)} to have some * consistency. Preferable it should return a new filter. * * @param part * @param filter */ private void applyCaseInsensitivityIfShouldIgnoreCase(Part part, Filter filter) { switch (part.shouldIgnoreCase()) { case ALWAYS: Assert.state(canIgnoreCase(part), "Unable to ignore case of " + part.getProperty().getLeafType().getName() + " types, the property '" + part.getProperty().getSegment() + "' must reference a String"); filter.ignoreCase(); break; case WHEN_POSSIBLE: if (canIgnoreCase(part)) { filter.ignoreCase(); } break; case NEVER: default: break; } }
@Test public void ignoreCaseShouldNotBeApplicableToComparisonOtherThanEquals() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("ignoreCase is only supported for EQUALS comparison"); Filter filter = new Filter("thing", ComparisonOperator.IS_NULL); filter.setBooleanOperator(BooleanOperator.AND); assertThat(filter.toCypher("n", true)).isEqualTo("WHERE n.`thing` IS NULL "); filter.ignoreCase(); assertThat(filter.toCypher("n", true)).isEqualTo("WHERE n.`thing` IS NULL "); } }
@Test public void equalComparisionShouldWork() { final String value = "someOtherThing"; Filter filter = new Filter("thing", ComparisonOperator.EQUALS, value); filter.setFunction(new PropertyComparison(value)); assertThat(filter.toCypher("n", true)).isEqualTo("WHERE n.`thing` = { `thing_0` } "); filter = new Filter("thing", ComparisonOperator.EQUALS, value); filter.ignoreCase(); assertThat(filter.toCypher("n", true)).isEqualTo("WHERE toLower(n.`thing`) = toLower({ `thing_0` }) "); }
@Test public void ignoreCaseShouldNotBeApplicableToComparisonOtherThanEquals() { final String emi = "EMI Studios, London"; session.save(new Studio(emi)); final Filter nameFilter = new Filter("name", ComparisonOperator.EQUALS, "eMi Studios, London").ignoreCase(); assertThat(session.loadAll(Studio.class, nameFilter, 0)) .hasSize(1) .extracting(Studio::getName) .containsExactly(emi); } }