Skip to content

Commit

Permalink
Switch to separate test OClass instead of OPerspective for #395
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomYdn committed Mar 29, 2020
1 parent 53c6fab commit c814d51
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 142 deletions.
146 changes: 146 additions & 0 deletions orienteer-core/src/test/java/org/orienteer/core/dao/DAOTest.java
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 orienteer-core/src/test/java/org/orienteer/core/dao/GuiceTest.java

This file was deleted.

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();

}

This file was deleted.

22 changes: 11 additions & 11 deletions orienteer-core/src/test/java/org/orienteer/core/dao/ITestDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
@ProvidedBy(DAOProvider.class)
public interface ITestDAO {

@Query("select from OPerspective")
public List<ODocument> listOPerspective();
@Query("select from DAOTestClass")
public List<ODocument> 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<ODocument> findAllAsDocument();

@Query("select from OPerspective")
public List<IOPerspective> findAllAsDAO();
@Query("select from DAOTestClass")
public List<IDAOTestClass> findAllAsDAO();

default public int countPerspectives() {
return listOPerspective().size();
default public int countAll() {
return listDAOTestClass().size();
}
}

0 comments on commit c814d51

Please sign in to comment.