use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class PersistentResourceTest method testLoadRecordSuccess.
@Test()
public void testLoadRecordSuccess() {
Child child1 = newChild(1);
EntityProjection collection = EntityProjection.builder().type(Child.class).build();
when(tx.loadObject(eq(collection), eq(1L), any())).thenReturn(child1);
RequestScope goodScope = buildRequestScope(tx, goodUser);
goodScope.setEntityProjection(collection);
PersistentResource<Child> loaded = PersistentResource.loadRecord(EntityProjection.builder().type(Child.class).build(), "1", goodScope);
assertEquals(child1, loaded.getObject(), "The load function should return the requested child object");
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class PersistentResourceTest method testLoadRecords.
@Test()
public void testLoadRecords() {
Child child1 = newChild(1);
Child child2 = newChild(-2);
Child child3 = newChild(-3);
Child child4 = newChild(4);
Child child5 = newChild(5);
EntityProjection collection = EntityProjection.builder().type(Child.class).build();
when(tx.loadObjects(eq(collection), any(RequestScope.class))).thenReturn(new DataStoreIterableBuilder(Lists.newArrayList(child1, child2, child3, child4, child5)).build());
RequestScope goodScope = buildRequestScope(tx, goodUser);
goodScope.setEntityProjection(collection);
Set<PersistentResource> loaded = PersistentResource.loadRecords(EntityProjection.builder().type(Child.class).build(), new ArrayList<>(), goodScope).toList(LinkedHashSet::new).blockingGet();
Set<Child> expected = Sets.newHashSet(child1, child4, child5);
Set<Object> actual = loaded.stream().map(PersistentResource::getObject).collect(Collectors.toSet());
assertEquals(3, actual.size(), "The returned list should be filtered to only include elements that have read permission");
assertEquals(expected, actual, "The returned list should only include elements with a positive ID");
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class PersistentResourceTest method testLoadRecordInvalidId.
@Test
public void testLoadRecordInvalidId() {
EntityProjection collection = EntityProjection.builder().type(Child.class).build();
when(tx.loadObject(eq(collection), eq("1"), any())).thenReturn(null);
RequestScope goodScope = buildRequestScope(tx, goodUser);
goodScope.setEntityProjection(collection);
assertThrows(InvalidObjectIdentifierException.class, () -> PersistentResource.loadRecord(EntityProjection.builder().type(Child.class).build(), "1", goodScope));
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class PersistentResourceTest method testTransferPermissionErrorOnUpdateSingularRelationship.
@Test
public void testTransferPermissionErrorOnUpdateSingularRelationship() {
example.User userModel = new example.User();
userModel.setId(1);
NoShareEntity noShare = new NoShareEntity();
noShare.setId(1);
List<Resource> idList = new ArrayList<>();
idList.add(new ResourceIdentifier("noshare", "1").castToResource());
Relationship ids = new Relationship(null, new Data<>(idList));
EntityProjection collection = EntityProjection.builder().type(NoShareEntity.class).build();
when(tx.loadObject(eq(collection), eq(1L), any())).thenReturn(noShare);
RequestScope goodScope = buildRequestScope(tx, goodUser);
PersistentResource<example.User> userResource = new PersistentResource<>(userModel, goodScope.getUUIDFor(userModel), goodScope);
assertThrows(ForbiddenAccessException.class, () -> userResource.updateRelation("noShare", ids.toPersistentResources(goodScope)));
}
use of com.yahoo.elide.core.request.EntityProjection 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));
}
Aggregations