Search in sources :

Example 51 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testNgramJustRight.

@Test
public void testNgramJustRight() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("description==*ruabc*", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
    assertFalse(loaded.needsInMemoryFilter());
    assertFalse(loaded.needsInMemoryPagination());
    assertFalse(loaded.needsInMemorySort());
    verify(wrappedTransaction, times(0)).loadObjects(any(), any());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 52 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testUnindexedField.

@Test
public void testUnindexedField() throws Exception {
    /* The field is not indexed */
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterExpression filter = filterParser.parseFilterExpression("price==123", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
    // The query was passed to the wrapped transaction which is a mock.
    assertNull(loaded);
    verify(wrappedTransaction, times(1)).loadObjects(any(), any());
}
Also used : Item(com.yahoo.elide.datastores.search.models.Item) EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 53 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testIndexedField.

@Test
public void testIndexedField() throws Exception {
    /* The field is indexed using the @Field annotation */
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterExpression filter = filterParser.parseFilterExpression("description==*rum*", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
    assertFalse(loaded.needsInMemoryFilter());
    assertFalse(loaded.needsInMemoryPagination());
    assertFalse(loaded.needsInMemorySort());
    verify(wrappedTransaction, times(0)).loadObjects(any(), any());
}
Also used : Item(com.yahoo.elide.datastores.search.models.Item) EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 54 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testLargeNgramForEqualityOperator.

@Test
public void testLargeNgramForEqualityOperator() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("description==abcdefghijk", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
    // The query was passed to the wrapped transaction which is a mock.
    assertNull(loaded);
    verify(wrappedTransaction, times(1)).loadObjects(any(), any());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 55 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testNgramTooLarge.

@Test
public void testNgramTooLarge() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("description==*abcdefghijk*", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    assertThrows(InvalidValueException.class, () -> testTransaction.loadObjects(projection, mockScope));
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)139 Test (org.junit.jupiter.api.Test)101 RequestScope (com.yahoo.elide.core.RequestScope)40 DataStore (com.yahoo.elide.core.datastore.DataStore)30 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)28 Elide (com.yahoo.elide.Elide)27 ElideResponse (com.yahoo.elide.ElideResponse)22 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 PersistentResource (com.yahoo.elide.core.PersistentResource)17 Item (com.yahoo.elide.datastores.search.models.Item)17 Book (example.Book)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Author (example.Author)8 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)7 FirstBean (com.yahoo.elide.example.beans.FirstBean)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)6