Search in sources :

Example 31 with DataStoreIterableBuilder

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

the class PersistentResourceTest method testDeleteResourceUpdateRelationshipSuccess.

@Test
void testDeleteResourceUpdateRelationshipSuccess() {
    Parent parent = new Parent();
    Child child = newChild(100);
    parent.setChildren(Sets.newHashSet(child));
    parent.setSpouses(Sets.newHashSet());
    Set<Parent> parents = Sets.newHashSet(parent);
    child.setParents(Sets.newHashSet(parent));
    assertFalse(parent.getChildren().isEmpty());
    when(tx.getToManyRelation(any(), eq(child), any(), any())).thenReturn(new DataStoreIterableBuilder(parents).build());
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Parent> parentResource = new PersistentResource<>(parent, "1", goodScope);
    PersistentResource<Child> childResource = new PersistentResource<>(child, parentResource, "children", "1", goodScope);
    childResource.deleteResource();
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).delete(child, goodScope);
    verify(tx, times(1)).save(parent, goodScope);
    verify(tx, never()).delete(parent, goodScope);
    assertTrue(parent.getChildren().isEmpty());
}
Also used : DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) Parent(example.Parent) Child(example.Child) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Test(org.junit.jupiter.api.Test)

Example 32 with DataStoreIterableBuilder

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

the class InMemoryStoreTransactionTest method testFilterPredicateInMemoryOnComplexAttribute.

@Test
public void testFilterPredicateInMemoryOnComplexAttribute() {
    FilterExpression expression = new InPredicate(new Path(Author.class, dictionary, "homeAddress.street1"), "Foo");
    EntityProjection projection = EntityProjection.builder().type(Author.class).filterExpression(expression).build();
    DataStoreIterable filterInMemory = new DataStoreIterableBuilder(Arrays.asList(author1, author2)).filterInMemory(true).build();
    when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(filterInMemory);
    Collection<Object> loaded = ImmutableList.copyOf(inMemoryStoreTransaction.loadObjects(projection, scope));
    assertEquals(1, loaded.size());
    assertTrue(loaded.contains(author1));
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) Author(example.Author) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Test(org.junit.jupiter.api.Test)

Example 33 with DataStoreIterableBuilder

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

the class InMemoryStoreTransactionTest method testSortOnComputedAttribute.

@Test
public void testSortOnComputedAttribute() {
    Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
    sortOrder.put("fullName", Sorting.SortOrder.desc);
    Editor editor1 = new Editor();
    editor1.setFirstName("A");
    editor1.setLastName("X");
    Editor editor2 = new Editor();
    editor2.setFirstName("B");
    editor2.setLastName("Y");
    Sorting sorting = new SortingImpl(sortOrder, Editor.class, dictionary);
    EntityProjection projection = EntityProjection.builder().type(Editor.class).sorting(sorting).build();
    DataStoreIterable iterable = new DataStoreIterableBuilder(Arrays.asList(editor1, editor2)).sortInMemory(false).build();
    ArgumentCaptor<EntityProjection> projectionArgument = ArgumentCaptor.forClass(EntityProjection.class);
    when(wrappedTransaction.loadObjects(projectionArgument.capture(), eq(scope))).thenReturn(iterable);
    Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
    assertNull(projectionArgument.getValue().getSorting());
    assertEquals(2, loaded.size());
    Object[] sorted = loaded.toArray();
    assertEquals(editor2, sorted[0]);
    assertEquals(editor1, sorted[1]);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) HashMap(java.util.HashMap) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Sorting(com.yahoo.elide.core.request.Sorting) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Editor(example.Editor) Test(org.junit.jupiter.api.Test)

Example 34 with DataStoreIterableBuilder

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

the class InMemoryStoreTransactionTest method testDataStoreRequiresTotalInMemoryFilter.

@Test
public void testDataStoreRequiresTotalInMemoryFilter() {
    FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
    EntityProjection projection = EntityProjection.builder().type(Book.class).filterExpression(expression).build();
    DataStoreIterable filterInMemory = new DataStoreIterableBuilder(books).filterInMemory(true).build();
    when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(filterInMemory);
    Collection<Object> loaded = ImmutableList.copyOf(inMemoryStoreTransaction.loadObjects(projection, scope));
    verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
    assertEquals(2, loaded.size());
    assertTrue(loaded.contains(book1));
    assertTrue(loaded.contains(book3));
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Test(org.junit.jupiter.api.Test)

Example 35 with DataStoreIterableBuilder

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

the class InMemoryStoreTransactionTest method testDataStoreRequiresInMemoryPagination.

@Test
public void testDataStoreRequiresInMemoryPagination() {
    PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 2, 10, 10, false, false);
    EntityProjection projection = EntityProjection.builder().type(Book.class).pagination(pagination).build();
    DataStoreIterable paginateInMemory = new DataStoreIterableBuilder(books).paginateInMemory(true).build();
    when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(paginateInMemory);
    Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
    verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
    assertEquals(2, loaded.size());
    assertTrue(loaded.contains(book1));
    assertTrue(loaded.contains(book2));
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) Book(example.Book) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Test(org.junit.jupiter.api.Test)

Aggregations

DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)46 Test (org.junit.jupiter.api.Test)41 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)20 Child (example.Child)16 Book (example.Book)15 EntityProjection (com.yahoo.elide.core.request.EntityProjection)13 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)12 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)11 Parent (example.Parent)11 Path (com.yahoo.elide.core.Path)8 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)7 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)7 Sorting (com.yahoo.elide.core.request.Sorting)7 GraphQLTest (com.yahoo.elide.graphql.GraphQLTest)7 Author (example.Author)7 ArrayList (java.util.ArrayList)7 RequestScope (com.yahoo.elide.core.RequestScope)6 PaginationImpl (com.yahoo.elide.core.pagination.PaginationImpl)6 Relationship (com.yahoo.elide.core.request.Relationship)6 HashMap (java.util.HashMap)6