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());
}
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));
}
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]);
}
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));
}
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));
}
Aggregations