2019-01-31 20:05:23 +01:00
|
|
|
package org.warp.jcwdb.tests;
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2019-03-07 11:32:45 +01:00
|
|
|
import org.warp.jcwdb.EnhancedObject;
|
|
|
|
import org.warp.jcwdb.database.IDatabaseTools;
|
|
|
|
import org.warp.jcwdb.annotations.DBDataType;
|
|
|
|
import org.warp.jcwdb.annotations.DBField;
|
|
|
|
import org.warp.jcwdb.annotations.DBPropertyGetter;
|
|
|
|
import org.warp.jcwdb.annotations.DBPropertySetter;
|
2019-01-31 20:05:23 +01:00
|
|
|
import org.warp.jcwdb.utils.NTestUtils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2019-02-09 14:23:18 +01:00
|
|
|
public class MultipleEnhancedObjects {
|
2019-01-31 20:05:23 +01:00
|
|
|
private NTestUtils.WrappedDb db;
|
|
|
|
private RootTwoClasses root;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
db = NTestUtils.wrapDb().create((db) -> {
|
2019-03-02 17:47:24 +01:00
|
|
|
root = db.get().loadRoot(RootTwoClasses.class, RootTwoClasses::new);
|
2019-01-31 20:05:23 +01:00
|
|
|
});
|
|
|
|
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 {
|
|
|
|
|
2019-02-05 17:56:28 +01:00
|
|
|
@DBField(id = 0, type = DBDataType.ENHANCED_OBJECT)
|
2019-01-31 20:05:23 +01:00
|
|
|
public NTestUtils.RootClass class1;
|
|
|
|
|
2019-02-05 17:56:28 +01:00
|
|
|
@DBField(id = 1, type = DBDataType.ENHANCED_OBJECT)
|
2019-01-31 20:05:23 +01:00
|
|
|
public NTestUtils.RootClass class2;
|
|
|
|
|
|
|
|
public RootTwoClasses() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2019-03-02 17:47:24 +01:00
|
|
|
public RootTwoClasses(IDatabaseTools databaseTools) throws IOException {
|
|
|
|
super(databaseTools);
|
2019-01-31 20:05:23 +01:00
|
|
|
}
|
|
|
|
|
2019-02-05 17:56:28 +01:00
|
|
|
@DBPropertyGetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
|
2019-01-31 20:05:23 +01:00
|
|
|
public NTestUtils.RootClass getClass3() {
|
|
|
|
return getProperty();
|
|
|
|
}
|
|
|
|
|
2019-02-05 17:56:28 +01:00
|
|
|
@DBPropertySetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
|
2019-01-31 20:05:23 +01:00
|
|
|
public void setClass3(NTestUtils.RootClass value) {
|
|
|
|
setProperty(value);
|
|
|
|
}
|
|
|
|
|
2019-02-05 17:56:28 +01:00
|
|
|
@DBPropertyGetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
|
2019-01-31 20:05:23 +01:00
|
|
|
public NTestUtils.RootClass getClass4() {
|
|
|
|
return getProperty();
|
|
|
|
}
|
|
|
|
|
2019-02-05 17:56:28 +01:00
|
|
|
@DBPropertySetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
|
2019-01-31 20:05:23 +01:00
|
|
|
public void setClass4(NTestUtils.RootClass value) {
|
|
|
|
setProperty(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|