DATACOUCH-251 - Wrap base where criteria with parenthesis for OR expressions.

Base criteria for the query should be wrapped before adding the entity filter criteria so the priority of filtering is clear.
This commit is contained in:
Subhashni Balakrishnan
2016-11-23 07:51:23 -08:00
committed by Oliver Gierke
parent ce8dd97d66
commit b52dee3a3c
4 changed files with 48 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
package org.springframework.data.couchbase.repository.query.support;
import static com.couchbase.client.java.query.dsl.Expression.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
@@ -132,4 +133,19 @@ public class N1qlUtilsTest {
assertEquals(expectedDefault, real);
assertEquals(expectedTypeKey, realWithTypeKey);
}
@Test
public void testCreateWhereFilterForEntityWithBaseCriteria() throws Exception {
String expected = "(field1 >= 30 OR field2 = \"foo\") AND `_class` = \"java.lang.String\"";
CouchbaseConverter converter = mock(CouchbaseConverter.class);
when(converter.getTypeKey()).thenReturn("_class");
EntityMetadata metadata = mock(EntityMetadata.class);
when(metadata.getJavaType()).thenReturn(String.class);
String real = N1qlUtils.createWhereFilterForEntity(
x("field1").gte(30).or(x("field2").eq(s("foo"))),
converter, metadata).toString();
assertEquals(expected, real);
}
}