-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to separate test OClass instead of OPerspective for #395
- Loading branch information
1 parent
53c6fab
commit c814d51
Showing
5 changed files
with
195 additions
and
142 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
orienteer-core/src/test/java/org/orienteer/core/dao/DAOTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Boolean>() { | ||
|
||
@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<Boolean>() { | ||
|
||
@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<ODocument> perspectives = tester.getDatabase().query(new OSQLSynchQuery<ODocument>("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<ODocument> menu = iOPerspective.listAllChild(); | ||
assertNotNull(menu); | ||
assertTrue("Size of childs", menu.size()>0); | ||
} | ||
|
||
@Test | ||
public void testDAO() { | ||
ITestDAO dao = tester.getApplication().getServiceInstance(ITestDAO.class); | ||
List<ODocument> 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<ODocument> listDocs = dao.findAllAsDocument(); | ||
List<IDAOTestClass> listObjs = dao.findAllAsDAO(); | ||
assertEquals(listDocs.size(), listObjs.size()); | ||
assertTrue(listDocs.get(0) instanceof ODocument); | ||
assertTrue(listObjs.get(0) instanceof IDAOTestClass); | ||
} | ||
} |
91 changes: 0 additions & 91 deletions
91
orienteer-core/src/test/java/org/orienteer/core/dao/GuiceTest.java
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
orienteer-core/src/test/java/org/orienteer/core/dao/IDAOTestClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IDAOTestClass> 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<ODocument> listAllChild(); | ||
|
||
} |
40 changes: 0 additions & 40 deletions
40
orienteer-core/src/test/java/org/orienteer/core/dao/IOPerspective.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters