From c814d51f45fd3e27cc3420812e0914902eb4c41a Mon Sep 17 00:00:00 2001 From: Ilia Naryzhny Date: Sat, 28 Mar 2020 18:22:55 -0700 Subject: [PATCH] Switch to separate test OClass instead of OPerspective for #395 --- .../java/org/orienteer/core/dao/DAOTest.java | 146 ++++++++++++++++++ .../org/orienteer/core/dao/GuiceTest.java | 91 ----------- .../org/orienteer/core/dao/IDAOTestClass.java | 38 +++++ .../org/orienteer/core/dao/IOPerspective.java | 40 ----- .../java/org/orienteer/core/dao/ITestDAO.java | 22 +-- 5 files changed, 195 insertions(+), 142 deletions(-) create mode 100644 orienteer-core/src/test/java/org/orienteer/core/dao/DAOTest.java delete mode 100644 orienteer-core/src/test/java/org/orienteer/core/dao/GuiceTest.java create mode 100644 orienteer-core/src/test/java/org/orienteer/core/dao/IDAOTestClass.java delete mode 100644 orienteer-core/src/test/java/org/orienteer/core/dao/IOPerspective.java diff --git a/orienteer-core/src/test/java/org/orienteer/core/dao/DAOTest.java b/orienteer-core/src/test/java/org/orienteer/core/dao/DAOTest.java new file mode 100644 index 000000000..7e3580ef1 --- /dev/null +++ b/orienteer-core/src/test/java/org/orienteer/core/dao/DAOTest.java @@ -0,0 +1,146 @@ +package org.orienteer.core.dao; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.orienteer.core.OrienteerWebApplication; +import org.orienteer.core.util.OSchemaHelper; +import org.orienteer.junit.OrienteerTestRunner; +import org.orienteer.junit.OrienteerTester; + +import com.google.inject.Singleton; +import com.orientechnologies.orient.core.db.document.ODatabaseDocument; +import com.orientechnologies.orient.core.metadata.schema.OType; +import com.orientechnologies.orient.core.record.impl.ODocument; +import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; + +import ru.ydn.wicket.wicketorientdb.utils.DBClosure; + +@RunWith(OrienteerTestRunner.class) +@Singleton +public class DAOTest { + + static final String TEST_CLASS = "DAOTestClass"; + + private static OrienteerTester tester; + + static { + tester = OrienteerWebApplication.lookupApplication().getServiceInstance(OrienteerTester.class); + } + + @BeforeClass + public static void beforeDAOTest() { + new DBClosure() { + + @Override + protected Boolean execute(ODatabaseDocument db) { + OSchemaHelper helper = OSchemaHelper.bind(db) + .oClass(TEST_CLASS) + .oProperty("name", OType.STRING) + .oProperty("parent", OType.LINK) + .oProperty("child", OType.LINKLIST) + .setupRelationship(TEST_CLASS, "parent", TEST_CLASS, "child"); + ODocument root = helper.oDocument() + .field("name", "root") + .saveDocument().getODocument(); + for(int i=0; i<5; i++) { + helper.oDocument() + .field("name", "Child#"+i) + .field("parent", root) + .saveDocument(); + } + return true; + } + }.execute(); + } + + @AfterClass + public static void afterDAOTest() { + new DBClosure() { + + @Override + protected Boolean execute(ODatabaseDocument db) { + db.getMetadata().getSchema().dropClass(TEST_CLASS); + return true; + } + }.execute(); + } + + @Test + public void testInjection() { + IDAOTestClass doc = tester.getApplication().getServiceInstance(IDAOTestClass.class); + List perspectives = tester.getDatabase().query(new OSQLSynchQuery("select from DAOTestClass")); + for (ODocument oDocument : perspectives) { + doc.fromStream(oDocument); + assertEquals(oDocument.field("name"), doc.getName()); + assertEquals(oDocument.field("name"), doc.getNameSynonymMethod()); + assertEquals("test"+oDocument.field("name"), doc.getTestName()); + assertEquals("test2"+oDocument.field("name"), doc.getTest2Name()); + assertEquals("test3test"+oDocument.field("name"), doc.getTest3Name()); + assertEquals((Object)oDocument.field("name"), doc.getDocument().field("name")); + } + } + + @Test + public void testLookups() { + IDAOTestClass iOPerspective = tester.getApplication().getServiceInstance(IDAOTestClass.class); + assertTrue(iOPerspective.lookupToBoolean("root")); + assertEquals("root", iOPerspective.getName()); + assertEquals("testroot", iOPerspective.getTestName()); + assertEquals("test2root", iOPerspective.getTest2Name()); + assertEquals("test3testroot", iOPerspective.getTest3Name()); + IDAOTestClass other = iOPerspective.lookupAsChain("root"); + assertSame(iOPerspective, other); + assertNull(iOPerspective.lookupAsChain("notExistingPerspective")); + } + + @Test + public void testQuery() { + IDAOTestClass iOPerspective = tester.getApplication().getServiceInstance(IDAOTestClass.class); + iOPerspective.lookupToBoolean("root"); + List menu = iOPerspective.listAllChild(); + assertNotNull(menu); + assertTrue("Size of childs", menu.size()>0); + } + + @Test + public void testDAO() { + ITestDAO dao = tester.getApplication().getServiceInstance(ITestDAO.class); + List testDocs = dao.listDAOTestClass(); + assertNotNull(testDocs); + assertTrue("Size of test docs", testDocs.size()>0); + assertTrue("Size of test docs", dao.countAll()>0); + assertEquals(testDocs.size(), dao.countAll()); + } + + @Test + public void testMirroring() { + IDAOTestClass doc = tester.getApplication().getServiceInstance(IDAOTestClass.class); + doc.lookupToBoolean("root"); + assertNotNull(doc.getDocument()); + Object reloadRet = doc.reload(); + assertTrue(reloadRet == doc); + } + + @Test + public void testConvertions() { + ITestDAO dao = tester.getApplication().getServiceInstance(ITestDAO.class); + ODocument doc = dao.findSingleAsDocument("root"); + IDAOTestClass pers = dao.findSingleAsDAO("root"); + assertEquals(doc.field("name"), pers.getName()); + List listDocs = dao.findAllAsDocument(); + List listObjs = dao.findAllAsDAO(); + assertEquals(listDocs.size(), listObjs.size()); + assertTrue(listDocs.get(0) instanceof ODocument); + assertTrue(listObjs.get(0) instanceof IDAOTestClass); + } +} diff --git a/orienteer-core/src/test/java/org/orienteer/core/dao/GuiceTest.java b/orienteer-core/src/test/java/org/orienteer/core/dao/GuiceTest.java deleted file mode 100644 index 944cef907..000000000 --- a/orienteer-core/src/test/java/org/orienteer/core/dao/GuiceTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.orienteer.core.dao; - -import java.util.List; - -import org.junit.Test; -import static org.junit.Assert.*; -import org.junit.runner.RunWith; -import org.orienteer.junit.OrienteerTestRunner; -import org.orienteer.junit.OrienteerTester; - -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.orientechnologies.orient.core.record.impl.ODocument; -import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; - -@RunWith(OrienteerTestRunner.class) -@Singleton -public class GuiceTest { - - @Inject - private OrienteerTester tester; - - @Test - public void testInjection() { - IOPerspective iOPerspective = tester.getApplication().getServiceInstance(IOPerspective.class); - List perspectives = tester.getDatabase().query(new OSQLSynchQuery("select from OPerspective")); - for (ODocument oDocument : perspectives) { - iOPerspective.fromStream(oDocument); - assertEquals(oDocument.field("alias"), iOPerspective.getAlias()); - assertEquals(oDocument.field("alias"), iOPerspective.getAliasSynonymMethod()); - assertEquals("test"+oDocument.field("alias"), iOPerspective.getTestAlias()); - assertEquals("test2"+oDocument.field("alias"), iOPerspective.getTest2Alias()); - assertEquals("test3test"+oDocument.field("alias"), iOPerspective.getTest3Alias()); - assertEquals((Object)oDocument.field("alias"), iOPerspective.getDocument().field("alias")); - } - } - - @Test - public void testLookups() { - IOPerspective iOPerspective = tester.getApplication().getServiceInstance(IOPerspective.class); - assertTrue(iOPerspective.lookupToBoolean("default")); - assertEquals("default", iOPerspective.getAlias()); - assertEquals("testdefault", iOPerspective.getTestAlias()); - assertEquals("test2default", iOPerspective.getTest2Alias()); - assertEquals("test3testdefault", iOPerspective.getTest3Alias()); - IOPerspective other = iOPerspective.lookupAsChain("default"); - assertSame(iOPerspective, other); - assertNull(iOPerspective.lookupAsChain("notExistingPerspective")); - } - - @Test - public void testQuery() { - IOPerspective iOPerspective = tester.getApplication().getServiceInstance(IOPerspective.class); - iOPerspective.lookupToBoolean("default"); - List menu = iOPerspective.listAllMenu(); - assertNotNull(menu); - assertTrue("Size of menu", menu.size()>0); - } - - @Test - public void testDAO() { - ITestDAO dao = tester.getApplication().getServiceInstance(ITestDAO.class); - List perspectives = dao.listOPerspective(); - assertNotNull(perspectives); - assertTrue("Size of perspectives", perspectives.size()>0); - assertTrue("Size of perspectives", dao.countPerspectives()>0); - assertEquals(perspectives.size(), dao.countPerspectives()); - } - - @Test - public void testMirroring() { - IOPerspective iOPerspective = tester.getApplication().getServiceInstance(IOPerspective.class); - iOPerspective.lookupToBoolean("default"); - assertNotNull(iOPerspective.getDocument()); - Object reloadRet = iOPerspective.reload(); - assertTrue(reloadRet == iOPerspective); - } - - @Test - public void testConvertions() { - ITestDAO dao = tester.getApplication().getServiceInstance(ITestDAO.class); - ODocument doc = dao.findSingleAsDocument("default"); - IOPerspective pers = dao.findSingleAsDAO("default"); - assertEquals(doc.field("alias"), pers.getAlias()); - List listDocs = dao.findAllAsDocument(); - List listObjs = dao.findAllAsDAO(); - assertEquals(listDocs.size(), listObjs.size()); - assertTrue(listDocs.get(0) instanceof ODocument); - assertTrue(listObjs.get(0) instanceof IOPerspective); - } -} diff --git a/orienteer-core/src/test/java/org/orienteer/core/dao/IDAOTestClass.java b/orienteer-core/src/test/java/org/orienteer/core/dao/IDAOTestClass.java new file mode 100644 index 000000000..eef70fbbc --- /dev/null +++ b/orienteer-core/src/test/java/org/orienteer/core/dao/IDAOTestClass.java @@ -0,0 +1,38 @@ +package org.orienteer.core.dao; + +import java.util.List; +import java.util.Map; + +import com.google.inject.ProvidedBy; +import com.orientechnologies.orient.core.record.impl.ODocument; + +@ProvidedBy(ODocumentWrapperProvider.class) +public interface IDAOTestClass extends IODocumentWrapper { + public String getName(); + public List getChild(); + + @DAOField("name") + public String getNameSynonymMethod(); + + default public String getTestName() { + return "test"+getName(); + } + + default public String getTest2Name() { + return "test2"+getDocument().field("name"); + } + + default public String getTest3Name() { + return "test3"+getTestName(); + } + + @Lookup("select from DAOTestClass where name = :name") + public boolean lookupToBoolean(String name); + + @Lookup("select from DAOTestClass where name = :name") + public IDAOTestClass lookupAsChain(String name); + + @Query("select expand(child) from DAOTestClass where @rid = :target") + public List listAllChild(); + +} diff --git a/orienteer-core/src/test/java/org/orienteer/core/dao/IOPerspective.java b/orienteer-core/src/test/java/org/orienteer/core/dao/IOPerspective.java deleted file mode 100644 index 816e94864..000000000 --- a/orienteer-core/src/test/java/org/orienteer/core/dao/IOPerspective.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.orienteer.core.dao; - -import java.util.List; -import java.util.Map; - -import com.google.inject.ProvidedBy; -import com.orientechnologies.orient.core.record.impl.ODocument; - -@ProvidedBy(ODocumentWrapperProvider.class) -public interface IOPerspective extends IODocumentWrapper { - public String getAlias(); - public Map getName(); - - @DAOField("alias") - public String getAliasSynonymMethod(); - - default public String getTestAlias() { - return "test"+getAlias(); - } - - default public String getTest2Alias() { - return "test2"+getDocument().field("alias"); - } - - default public String getTest3Alias() { - return "test3"+getTestAlias(); - } - - @Lookup("select from OPerspective where alias = :alias") - public boolean lookupToBoolean(String alias); - - @Lookup("select from OPerspective where alias = :alias") - public IOPerspective lookupAsChain(String alias); - - @Query("select expand(menu) from OPerspective where @rid = :target") - public List listAllMenu(); - - public List getMenu(); - -} diff --git a/orienteer-core/src/test/java/org/orienteer/core/dao/ITestDAO.java b/orienteer-core/src/test/java/org/orienteer/core/dao/ITestDAO.java index 32b5b0487..833bbf555 100644 --- a/orienteer-core/src/test/java/org/orienteer/core/dao/ITestDAO.java +++ b/orienteer-core/src/test/java/org/orienteer/core/dao/ITestDAO.java @@ -8,23 +8,23 @@ @ProvidedBy(DAOProvider.class) public interface ITestDAO { - @Query("select from OPerspective") - public List listOPerspective(); + @Query("select from DAOTestClass") + public List listDAOTestClass(); - @Query("select from OPerspective where alias = :alias") - public ODocument findSingleAsDocument(String alias); + @Query("select from DAOTestClass where name = :name") + public ODocument findSingleAsDocument(String name); - @Query("select from OPerspective where alias = :alias") - public IOPerspective findSingleAsDAO(String alias); + @Query("select from DAOTestClass where name = :name") + public IDAOTestClass findSingleAsDAO(String name); - @Query("select from OPerspective") + @Query("select from DAOTestClass") public List findAllAsDocument(); - @Query("select from OPerspective") - public List findAllAsDAO(); + @Query("select from DAOTestClass") + public List findAllAsDAO(); - default public int countPerspectives() { - return listOPerspective().size(); + default public int countAll() { + return listDAOTestClass().size(); } }