use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method createPermissionCheckClassAnnotationForCreatingAnEntitySuccessCase.
// ----------------------------------------- ** Entity Creation ** -------------------------------------------------
// Create allowed based on class level expression
@Test
public void createPermissionCheckClassAnnotationForCreatingAnEntitySuccessCase() {
com.yahoo.elide.core.RequestScope userOneScope = new TestRequestScope(tx, userOne, dictionary);
UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userOneScope)).thenReturn(updateAndCreateNewObject);
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userOneScope, Optional.of("1"));
created.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method updatePermissionOverwrittenForAttributeSuccessCase.
// Class level expression overwritten by field level expression
@Test
public void updatePermissionOverwrittenForAttributeSuccessCase() {
com.yahoo.elide.core.RequestScope userFourScope = new TestRequestScope(tx, userFour, dictionary);
UpdateAndCreate updateAndCreateExistingObject = new UpdateAndCreate();
when(tx.loadObject(any(), eq(1L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(updateAndCreateExistingObject);
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> loaded = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(UpdateAndCreate.class).build(), "1", userFourScope);
loaded.updateAttribute("alias", "");
loaded.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method createPermissionInheritedForRelationSuccessCase.
// ----------------------------------------- ** Update Relation On Create ** --------------------------------------
// Expression for relation inherited from class level expression
@Test
public void createPermissionInheritedForRelationSuccessCase() {
com.yahoo.elide.core.RequestScope userOneScope = new TestRequestScope(tx, userOne, dictionary);
UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userOneScope)).thenReturn(updateAndCreateNewObject);
when(tx.loadObject(any(), eq(2L), any(com.yahoo.elide.core.RequestScope.class))).thenReturn(new Book());
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userOneScope, Optional.of("8"));
com.yahoo.elide.core.PersistentResource<Book> loadedBook = com.yahoo.elide.core.PersistentResource.loadRecord(EntityProjection.builder().type(Book.class).build(), "2", userOneScope);
created.addRelation("books", loadedBook);
created.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class UpdateOnCreateTest method createPermissionOverwrittenForAttributeSuccessCase.
// Class level expression overwritten by field level expression
@Test
public void createPermissionOverwrittenForAttributeSuccessCase() {
com.yahoo.elide.core.RequestScope userThreeScope = new TestRequestScope(tx, userThree, dictionary);
UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userThreeScope)).thenReturn(updateAndCreateNewObject);
com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userThreeScope, Optional.of("6"));
created.updateAttribute("alias", "");
created.getRequestScope().getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.TestRequestScope in project elide by yahoo.
the class FilteredIteratorTest method testFilteredResult.
@Test
public void testFilteredResult() throws Exception {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
Book book1 = new Book();
book1.setTitle("foo");
Book book2 = new Book();
book2.setTitle("bar");
Book book3 = new Book();
book3.setTitle("foobar");
List<Book> books = List.of(book1, book2, book3);
RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
FilterExpression expression = filterDialect.parse(ClassType.of(Book.class), new HashSet<>(), "title==*bar", NO_VERSION);
RequestScope scope = new TestRequestScope(null, null, dictionary);
Iterator<Book> bookIterator = new FilteredIterator<>(expression, scope, books.iterator());
assertTrue(bookIterator.hasNext());
assertEquals("bar", bookIterator.next().getTitle());
assertTrue(bookIterator.hasNext());
assertEquals("foobar", bookIterator.next().getTitle());
assertFalse(bookIterator.hasNext());
}
Aggregations