package org.warp.jcwdb.tests; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.warp.cowdb.EnhancedObject; import org.warp.cowdb.IDatabase; import org.warp.jcwdb.ann.DBDataType; import org.warp.jcwdb.ann.DBField; import org.warp.jcwdb.ann.DBPropertyGetter; import org.warp.jcwdb.ann.DBPropertySetter; import org.warp.jcwdb.utils.NTestUtils; import java.io.IOException; public class NDBMultipleEnhancedObjects { private NTestUtils.WrappedDb db; private RootTwoClasses root; @Before public void setUp() throws Exception { db = NTestUtils.wrapDb().create((db) -> { root = db.get().loadRoot(RootTwoClasses.class); }); root.class1 = new NTestUtils.RootClass(db.get()); db.setRootClassValues(root.class1); root.class2 = new NTestUtils.RootClass(db.get()); db.setRootClassValues(root.class2); root.setClass3(new NTestUtils.RootClass(db.get())); db.setRootClassValues(root.getClass3()); root.setClass4(new NTestUtils.RootClass(db.get())); db.setRootClassValues(root.getClass4()); db.closeAndReopen(); } @Test public void shouldMatchMultipleEnhancedObjects() { db.testRootClassValues(root.class1); db.testRootClassValues(root.class2); db.testRootClassValues(root.getClass3()); db.testRootClassValues(root.getClass4()); } @After public void tearDown() throws Exception { db.delete(); } public static class RootTwoClasses extends EnhancedObject { @DBField(id = 0, type = DBDataType.DATABASE_OBJECT) public NTestUtils.RootClass class1; @DBField(id = 1, type = DBDataType.DATABASE_OBJECT) public NTestUtils.RootClass class2; public RootTwoClasses() { super(); } public RootTwoClasses(IDatabase database) throws IOException { super(database); } @DBPropertyGetter(id = 0, type = DBDataType.DATABASE_OBJECT) public NTestUtils.RootClass getClass3() { return getProperty(); } @DBPropertySetter(id = 0, type = DBDataType.DATABASE_OBJECT) public void setClass3(NTestUtils.RootClass value) { setProperty(value); } @DBPropertyGetter(id = 1, type = DBDataType.DATABASE_OBJECT) public NTestUtils.RootClass getClass4() { return getProperty(); } @DBPropertySetter(id = 1, type = DBDataType.DATABASE_OBJECT) public void setClass4(NTestUtils.RootClass value) { setProperty(value); } @Override public void initialize() throws IOException { } } }