strangedb/src/test/java/org/warp/jcwdb/tests/DBNestedDBObjects.java

67 lines
2.2 KiB
Java

package org.warp.jcwdb.tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.warp.jcwdb.utils.NestedClass;
import org.warp.jcwdb.utils.TestUtils;
import static org.junit.Assert.*;
public class DBNestedDBObjects {
private TestUtils.WrappedDb db;
private NestedClass root;
@Before
public void setUp() throws Exception {
db = TestUtils.wrapDb().create((db) -> {
root = db.get().loadRoot(NestedClass.class);
});
root.child = new NestedClass(db.get());
root.child.child = new NestedClass(db.get());
root.child.child.child = new NestedClass(db.get());
root.child.child.child.child = new NestedClass(db.get());
root.child.child.child.child.isFinal = true;
NestedClass nestedClass0 = new NestedClass(db.get());
nestedClass0.isFinal = true;
NestedClass nestedClass1 = new NestedClass(db.get());
nestedClass1.setValue(nestedClass0);
NestedClass nestedClass2 = new NestedClass(db.get());
nestedClass2.setValue(nestedClass1);
NestedClass nestedClass3 = new NestedClass(db.get());
nestedClass3.setValue(nestedClass2);
NestedClass nestedClass4 = new NestedClass(db.get());
nestedClass4.setValue(nestedClass3);
root.setValue(nestedClass4);
db.closeAndReopen();
}
@Test
public void shouldMatchNestedObjects() {
assertNotNull(root);
assertNotNull(root.child);
assertNotNull(root.child.child);
assertNotNull(root.child.child.child);
assertNotNull(root.child.child.child.child);
assertTrue(root.child.child.child.child.isFinal);
assertNotNull(root.getValue());
assertFalse(root.isFinal);
assertNotNull(root.getValue().getValue());
assertFalse(root.getValue().isFinal);
assertNotNull(root.getValue().getValue().getValue());
assertFalse(root.getValue().getValue().isFinal);
assertNotNull(root.getValue().getValue().getValue().getValue());
assertFalse(root.getValue().getValue().getValue().isFinal);
assertNotNull(root.getValue().getValue().getValue().getValue().getValue());
assertFalse(root.getValue().getValue().getValue().getValue().isFinal);
assertTrue(root.getValue().getValue().getValue().getValue().getValue().isFinal);
}
@After
public void tearDown() throws Exception {
db.delete();
}
}