Revision 4af3f83d
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
tests/em/tst_em.cpp | ||
---|---|---|
QVERIFY(!tables.contains("group_persons"));
|
||
}
|
||
|
||
|
||
void Em::containsColumn(QHash<QString, QSharedPointer<QSqlField>> &columns, QString name,
|
||
QVariant::Type type, QString tableName, bool pk) {
|
||
bool containsColumn = columns.contains(name);
|
tests/em/tst_querybuildertest.cpp | ||
---|---|---|
#include <QString>
|
||
#include <QtTest>
|
||
#include "entitymanager.h"
|
||
#include "databasemigration.h"
|
||
#include "../models.h"
|
||
|
||
class QuerybuilderTest : public QObject
|
||
{
|
||
class QuerybuilderTest : public QObject {
|
||
Q_OBJECT
|
||
|
||
public:
|
||
public:
|
||
QuerybuilderTest();
|
||
|
||
private Q_SLOTS:
|
||
private Q_SLOTS:
|
||
void initTestCase();
|
||
void cleanupTestCase();
|
||
void testCase1_data();
|
||
void testCase1();
|
||
void testFindByAttributes();
|
||
void testFindByAttributesManyToOneRelation();
|
||
void testFindByAttributesManyToOneRelationAttribute();
|
||
void testFindByAttributesManyToManyRelation();
|
||
void testFindByAttributesManyToManyRelationAttribute();
|
||
void testFindByAttributesInheritance();
|
||
void testQueryBuilder();
|
||
void testQueryBuilderInheritance();
|
||
private:
|
||
CuteEntityManager::EntityManager *e;
|
||
};
|
||
|
||
QuerybuilderTest::QuerybuilderTest()
|
||
{
|
||
QuerybuilderTest::QuerybuilderTest() {
|
||
}
|
||
|
||
void QuerybuilderTest::initTestCase()
|
||
{
|
||
void QuerybuilderTest::initTestCase() {
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Group>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Person>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Article>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<Employee>();
|
||
CuteEntityManager::EntityInstanceFactory::registerClass<WorkerGroup>();
|
||
this->e = new CuteEntityManager::EntityManager("QSQLITE",
|
||
":memory:", "", "", "", "", true, "foreign_keys = ON");
|
||
QStringList inits = QStringList() << "Person" << "Group" << "Employee" << "WorkerGroup";
|
||
QVERIFY2(this->e->startup("queryBuilderTest", inits), "Failure");
|
||
QSharedPointer<Person> p1 = QSharedPointer<Person>(new Person("Lucien", "We",
|
||
Person::Gender::MALE, "lucien.jpeg", "", "Luc", QDate(1995, 2, 4)));
|
||
QSharedPointer<Employee> p2 = QSharedPointer<Employee>(new Employee(11, "Janine",
|
||
"Musterfrau",
|
||
Person::Gender::FEMALE, "janine.jpeg", "", "", QDate(1992, 8, 5), "B"));
|
||
QSharedPointer<Employee> p3 = QSharedPointer<Employee>(new Employee(42, "Fenja", "Sey.",
|
||
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 11, 11), "A"));
|
||
QSharedPointer<Person> p4 = QSharedPointer<Person>(new Person("Fenja", "Neu",
|
||
Person::Gender::FEMALE, "fenja2.jpeg", "", "Fenni", QDate(1980, 5, 30)));
|
||
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("Group Psy"));
|
||
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("Group Health"));
|
||
g->setLeader(p1);
|
||
g->setPersons({p1, p2, p4});
|
||
g->setLeader(p3);
|
||
g->setPersons({p3});
|
||
QSharedPointer<WorkerGroup> wg = QSharedPointer<WorkerGroup>(new
|
||
WorkerGroup("Taskforce P&H", 50));
|
||
wg->addWorker(p2);
|
||
wg->addWorker(p3);
|
||
auto gEnt = g.objectCast<Entity>();
|
||
auto g2Ent = g2.objectCast<Entity>();
|
||
auto wgEnt = wg.objectCast<Entity>();
|
||
QVERIFY(this->e->save(gEnt));
|
||
QVERIFY(this->e->save(wgEnt));
|
||
QVERIFY(this->e->save(g2Ent));
|
||
}
|
||
|
||
void QuerybuilderTest::cleanupTestCase()
|
||
{
|
||
void QuerybuilderTest::cleanupTestCase() {
|
||
auto qb = this->e->getQueryBuilder();
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup_workers")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("employee")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("workergroup")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person_groups")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("group")));
|
||
QVERIFY(this->e->executeQuery(qb->dropTable("person")));
|
||
QVERIFY(this->e->removeAll("cuteentitymanager::databasemigration"));
|
||
if (this->e) {
|
||
delete this->e;
|
||
this->e = nullptr;
|
||
}
|
||
}
|
||
|
||
void QuerybuilderTest::testCase1_data()
|
||
{
|
||
QTest::addColumn<QString>("data");
|
||
QTest::newRow("0") << QString();
|
||
void QuerybuilderTest::testFindByAttributes() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persNumber"] = 42;
|
||
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
|
||
QVERIFY(p);
|
||
QCOMPARE(p->getNickName(), QString("Lotta"));
|
||
}
|
||
|
||
void QuerybuilderTest::testCase1()
|
||
{
|
||
QFETCH(QString, data);
|
||
QVERIFY2(true, "Failure");
|
||
void QuerybuilderTest::testFindByAttributesManyToOneRelation() {
|
||
QHash<QString, QVariant> attributes;
|
||
QSharedPointer<Person> person = QSharedPointer<Person>();
|
||
//@todo fetch person
|
||
attributes["leader"] = QVariant(person);
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToOneRelationAttribute() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["leader.firstName"] = QString("Fenja");
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelation() {
|
||
QHash<QString, QVariant> attributes;
|
||
QList<QSharedPointer<Person>> persons = QList<QSharedPointer<Person>>();
|
||
// attributes["persons"] = QVariant(persons);
|
||
// QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
// (attributes, true);
|
||
// QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesManyToManyRelationAttribute() {
|
||
QHash<QString, QVariant> attributes;
|
||
attributes["persons.firstName"] = QString("Fenja");
|
||
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
|
||
(attributes, true);
|
||
QVERIFY(group);
|
||
}
|
||
|
||
void QuerybuilderTest::testFindByAttributesInheritance() {
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilder() {
|
||
// Query q = Query();
|
||
// q.appendWhere(e->getQueryBuilder()->like(QString("firstname"), QString("Tim"),
|
||
// JokerPosition::BEHIND));
|
||
// q.appendWhere(e->getQueryBuilder()->andOperator());
|
||
// q.appendWhere(e->getQueryBuilder()->arbitraryOperator("<", "birthday",
|
||
// QDate(2000, 10, 10)));
|
||
// //q.appendJoin(Join("person", "pupil.id = person.id"));
|
||
// q.setDistinct(true);
|
||
// q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
|
||
// q.setLimit(10);
|
||
// QList<QSharedPointer<Pupil>> list = e->find<Pupil>(q, true);
|
||
}
|
||
|
||
void QuerybuilderTest::testQueryBuilderInheritance() {
|
||
}
|
||
|
||
|
||
QTESTCASE_H
|
||
//QTEST_APPLESS_MAIN(QuerybuilderTest)
|
||
|
||
#include "tst_querybuildertest.moc"
|
Auch abrufbar als: Unified diff
tests for query builder