Search in sources :

Example 31 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection 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 32 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection 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 33 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection 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 34 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection 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)

Example 35 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testInfixOperator.

@Test
public void testInfixOperator() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("name==*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 : 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

EntityProjection (com.yahoo.elide.core.request.EntityProjection)108 Test (org.junit.jupiter.api.Test)90 Book (example.Book)41 RequestScope (com.yahoo.elide.core.RequestScope)27 Author (example.Author)27 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)22 Publisher (example.Publisher)22 Relationship (com.yahoo.elide.core.request.Relationship)19 Path (com.yahoo.elide.core.Path)18 TestRequestScope (com.yahoo.elide.core.TestRequestScope)18 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)18 HashMap (java.util.HashMap)18 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)18 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)16 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)15 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)15 Collection (java.util.Collection)15 LinkedHashSet (java.util.LinkedHashSet)14 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)13 Editor (example.Editor)13