use of com.yahoo.elide.example.beans.FirstChildBean in project elide by yahoo.
the class HashMapDataStoreTest method dataStoreTestInheritanceUpdate.
@Test
public void dataStoreTestInheritanceUpdate() 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);
// update Child
try (DataStoreTransaction t = inMemoryDataStore.beginTransaction()) {
child.setNickname("hello");
t.save(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());
FirstChildBean bean = (FirstChildBean) IterableUtils.first(beans);
assertEquals("1", bean.getId());
assertEquals("hello", bean.getNickname());
}
}
use of com.yahoo.elide.example.beans.FirstChildBean 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.example.beans.FirstChildBean 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());
}
Aggregations