86 lines
2.4 KiB
Java
86 lines
2.4 KiB
Java
package it.cavallium.strangedb.tests;
|
|
|
|
import it.cavallium.strangedb.EnhancedObject;
|
|
import it.cavallium.strangedb.annotations.DbDataType;
|
|
import it.cavallium.strangedb.annotations.DbField;
|
|
import it.cavallium.strangedb.annotations.DbPropertyGetter;
|
|
import it.cavallium.strangedb.annotations.DbPropertySetter;
|
|
import it.cavallium.strangedb.database.IDatabaseTools;
|
|
import it.cavallium.strangedb.utils.NTestUtils;
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class MultipleEnhancedObjects {
|
|
private NTestUtils.WrappedDb db;
|
|
private RootTwoClasses root;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
db = NTestUtils.wrapDb().create((db) -> {
|
|
root = db.get().loadRoot(RootTwoClasses.class, RootTwoClasses::new);
|
|
});
|
|
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.ENHANCED_OBJECT)
|
|
public NTestUtils.RootClass class1;
|
|
|
|
@DbField(id = 1, type = DbDataType.ENHANCED_OBJECT)
|
|
public NTestUtils.RootClass class2;
|
|
|
|
public RootTwoClasses() {
|
|
super();
|
|
}
|
|
|
|
public RootTwoClasses(IDatabaseTools databaseTools) throws IOException {
|
|
super(databaseTools);
|
|
}
|
|
|
|
@DbPropertyGetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
|
|
public NTestUtils.RootClass getClass3() {
|
|
return getProperty();
|
|
}
|
|
|
|
@DbPropertySetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
|
|
public void setClass3(NTestUtils.RootClass value) {
|
|
setProperty(value);
|
|
}
|
|
|
|
@DbPropertyGetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
|
|
public NTestUtils.RootClass getClass4() {
|
|
return getProperty();
|
|
}
|
|
|
|
@DbPropertySetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
|
|
public void setClass4(NTestUtils.RootClass value) {
|
|
setProperty(value);
|
|
}
|
|
}
|
|
}
|