Search in sources :

Example 1 with FirstChildBean

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());
    }
}
Also used : FirstChildBean(com.yahoo.elide.example.beans.FirstChildBean) FirstBean(com.yahoo.elide.example.beans.FirstBean) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 2 with FirstChildBean

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());
    }
}
Also used : FirstChildBean(com.yahoo.elide.example.beans.FirstChildBean) FirstBean(com.yahoo.elide.example.beans.FirstBean) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 3 with FirstChildBean

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());
}
Also used : FirstChildBean(com.yahoo.elide.example.beans.FirstChildBean) FirstBean(com.yahoo.elide.example.beans.FirstBean) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 FirstBean (com.yahoo.elide.example.beans.FirstBean)3 FirstChildBean (com.yahoo.elide.example.beans.FirstChildBean)3 Test (org.junit.jupiter.api.Test)3