use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class HashMapDataStoreTest method dataStoreTestInheritanceDelete.
@Test
public void dataStoreTestInheritanceDelete() throws IOException, InstantiationException, IllegalAccessException {
Map<String, Object> entry = inMemoryDataStore.get(ClassType.of(FirstBean.class));
assertEquals(0, entry.size());
FirstChildBean child = createNewInheritanceObject(FirstChildBean.class);
createNewInheritanceObject(FirstBean.class);
// Delete Child
try (DataStoreTransaction t = inMemoryDataStore.beginTransaction()) {
t.delete(child, null);
t.commit(null);
}
// Only 1 parent entry should remain.
try (DataStoreTransaction t = inMemoryDataStore.beginTransaction()) {
Iterable<Object> beans = t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null);
assertNotNull(beans);
assertTrue(beans.iterator().hasNext());
FirstBean bean = (FirstBean) IterableUtils.first(beans);
assertEquals("2", bean.getId());
}
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class HashMapDataStoreTest method dataStoreTestInheritance.
@Test
public void dataStoreTestInheritance() throws IOException, InstantiationException, IllegalAccessException {
Map<String, Object> entry = inMemoryDataStore.get(ClassType.of(FirstBean.class));
assertEquals(0, entry.size());
FirstChildBean child = createNewInheritanceObject(FirstChildBean.class);
// Adding Child object, adds a parent entry.
try (DataStoreTransaction t = inMemoryDataStore.beginTransaction()) {
Iterable<Object> beans = t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null);
assertNotNull(beans);
assertTrue(beans.iterator().hasNext());
FirstBean bean = (FirstBean) IterableUtils.first(beans);
assertEquals("1", bean.getId());
}
assertEquals("1", child.getId());
assertNotNull(entry);
assertEquals(1, entry.size());
// New Parent avoids id collision.
FirstBean parent = createNewInheritanceObject(FirstBean.class);
assertEquals("2", parent.getId());
// New Child avoids id collision
FirstChildBean child1 = createNewInheritanceObject(FirstChildBean.class);
assertEquals("3", child1.getId());
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class VerifyFieldAccessFilterExpressionVisitorTest method setupMocks.
@BeforeEach
public void setupMocks() {
// this will test with the default interface implementation
scope = mock(RequestScope.class);
PermissionExecutor permissionExecutor = mock(PermissionExecutor.class);
DataStoreTransaction transaction = mock(DataStoreTransaction.class);
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
dictionary.bindEntity(Author.class);
when(scope.getDictionary()).thenReturn(dictionary);
when(scope.getPermissionExecutor()).thenReturn(permissionExecutor);
when(scope.getTransaction()).thenReturn(transaction);
when(permissionExecutor.evaluateFilterJoinUserChecks(any(), any())).thenCallRealMethod();
when(permissionExecutor.handleFilterJoinReject(any(), any(), any())).thenCallRealMethod();
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class VerifyFieldAccessFilterExpressionVisitorTest method testBypassReadonlyFilterRestriction.
@Test
public void testBypassReadonlyFilterRestriction() throws Exception {
RSQLFilterDialect dialect = RSQLFilterDialect.builder().dictionary(scope.getDictionary()).build();
FilterExpression expression = dialect.parseFilterExpression("authors.name==foo", ClassType.of(Book.class), true);
Book book = new Book();
PersistentResource<Book> resource = new PersistentResource<>(book, "", scope);
PermissionExecutor permissionExecutor = scope.getPermissionExecutor();
DataStoreTransaction tx = scope.getTransaction();
when(permissionExecutor.evaluateFilterJoinUserChecks(any(), any())).thenReturn(ExpressionResult.PASS);
VerifyFieldAccessFilterExpressionVisitor visitor = new VerifyFieldAccessFilterExpressionVisitor(resource);
// restricted HOME field
assertTrue(expression.accept(visitor));
verify(permissionExecutor, times(1)).evaluateFilterJoinUserChecks(any(), any());
verify(permissionExecutor, never()).checkSpecificFieldPermissions(any(), any(), any(), any());
verify(permissionExecutor, never()).checkUserPermissions(any(), any(), isA(String.class));
verify(permissionExecutor, never()).handleFilterJoinReject(any(), any(), any());
verify(tx, never()).getToManyRelation(any(), any(), any(), any());
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class LifeCycleTest method testLegacyElideDelete.
@Test
public void testLegacyElideDelete() throws Exception {
DataStore store = mock(DataStore.class);
DataStoreTransaction tx = mock(DataStoreTransaction.class);
LegacyTestModel mockModel = mock(LegacyTestModel.class);
Elide elide = getElide(store, dictionary, MOCK_AUDIT_LOGGER);
dictionary.setValue(mockModel, "id", "1");
when(store.beginTransaction()).thenReturn(tx);
when(tx.loadObject(isA(EntityProjection.class), any(), isA(RequestScope.class))).thenReturn(mockModel);
ElideResponse response = elide.delete(baseUrl, "/legacyTestModel/1", "", null, NO_VERSION);
assertEquals(HttpStatus.SC_NO_CONTENT, response.getResponseCode());
verify(mockModel, never()).classUpdatePostCommit();
verify(mockModel, never()).classUpdatePreSecurity();
verify(mockModel, never()).classUpdatePreCommit();
verify(mockModel, never()).classCreatePreCommitAllUpdates();
verify(mockModel, never()).classCreatePostCommit();
verify(mockModel, never()).classCreatePreSecurity();
verify(mockModel, never()).classCreatePreCommit();
verify(mockModel, times(1)).classDeletePreSecurity();
verify(mockModel, times(1)).classDeletePreCommit();
verify(mockModel, times(1)).classDeletePostCommit();
verify(mockModel, times(3)).classMultiple();
verify(mockModel, never()).fieldUpdatePostCommit();
verify(mockModel, never()).fieldUpdatePreSecurity();
verify(mockModel, never()).fieldUpdatePreCommit();
verify(mockModel, never()).fieldCreatePostCommit();
verify(mockModel, never()).fieldCreatePreSecurity();
verify(mockModel, never()).fieldCreatePreCommit();
verify(mockModel, never()).fieldMultiple();
verify(tx).preCommit(any());
verify(tx).delete(eq(mockModel), isA(RequestScope.class));
verify(tx).flush(isA(RequestScope.class));
verify(tx).commit(isA(RequestScope.class));
verify(tx).close();
}
Aggregations