Search in sources :

Example 16 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 17 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 18 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 19 with TestRequestScope

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();
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 20 with TestRequestScope

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());
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Aggregations

TestRequestScope (com.yahoo.elide.core.TestRequestScope)48 RequestScope (com.yahoo.elide.core.RequestScope)47 Test (org.junit.jupiter.api.Test)47 Book (example.Book)20 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)20 UpdateAndCreate (example.UpdateAndCreate)19 EntityProjection (com.yahoo.elide.core.request.EntityProjection)18 Publisher (example.Publisher)13 Author (example.Author)11 Editor (example.Editor)9 Collection (java.util.Collection)8 Parent (example.Parent)7 PersistentResource (com.yahoo.elide.core.PersistentResource)6 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)6 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)5 Resource (com.yahoo.elide.jsonapi.models.Resource)5 Child (example.Child)5 Price (example.Price)5 Path (com.yahoo.elide.core.Path)4 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)4