Search in sources :

Example 1 with UpdateAndCreate

use of example.UpdateAndCreate in project elide by yahoo.

the class UpdateOnCreateTest method createPermissionOverwrittenForAttributeFailureCase.

@Test
public void createPermissionOverwrittenForAttributeFailureCase() {
    com.yahoo.elide.core.RequestScope userFourScope = new TestRequestScope(tx, userFour, dictionary);
    UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
    when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userFourScope)).thenReturn(updateAndCreateNewObject);
    assertThrows(ForbiddenAccessException.class, () -> {
        com.yahoo.elide.core.PersistentResource<UpdateAndCreate> created = com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userFourScope, Optional.of("7"));
        created.updateAttribute("alias", "");
    });
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 2 with UpdateAndCreate

use of example.UpdateAndCreate in project elide by yahoo.

the class UpdateOnCreateTest method createPermissionCheckFieldAnnotationForCreatingAnEntitySuccessCase.

// Create allowed based on field level expression
@Test
public void createPermissionCheckFieldAnnotationForCreatingAnEntitySuccessCase() {
    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("2"));
    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 3 with UpdateAndCreate

use of example.UpdateAndCreate in project elide by yahoo.

the class UpdateOnCreateTest method createPermissionCheckFieldAnnotationForCreatingAnEntityFailureCase.

// Create denied based on field level expression
@Test
public void createPermissionCheckFieldAnnotationForCreatingAnEntityFailureCase() {
    com.yahoo.elide.core.RequestScope userFourScope = new TestRequestScope(tx, userFour, dictionary);
    UpdateAndCreate updateAndCreateNewObject = new UpdateAndCreate();
    when(tx.createNewObject(ClassType.of(UpdateAndCreate.class), userFourScope)).thenReturn(updateAndCreateNewObject);
    assertThrows(ForbiddenAccessException.class, () -> com.yahoo.elide.core.PersistentResource.createObject(ClassType.of(UpdateAndCreate.class), userFourScope, Optional.of("3")));
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) UpdateAndCreate(example.UpdateAndCreate) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateAndCreate

use of example.UpdateAndCreate 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 5 with UpdateAndCreate

use of example.UpdateAndCreate 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)

Aggregations

RequestScope (com.yahoo.elide.core.RequestScope)19 TestRequestScope (com.yahoo.elide.core.TestRequestScope)19 UpdateAndCreate (example.UpdateAndCreate)19 Test (org.junit.jupiter.api.Test)19 Author (example.Author)4 Book (example.Book)4