Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 64dc4a24

Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt

  • ID 64dc4a2478ace93b52dbb0fd56cd140152fd8dd8
  • Vorgänger 3bc1dde3
  • Nachfolger 79e33d0c

testcases

Unterschiede anzeigen:

src/src.pro
attribute.cpp \
attributeresolver.cpp
!system-sqlite:!contains(LIBS, .*sqlite3.*) {
!unix:!system-sqlite:!contains(LIBS, .*sqlite3.*) {
include($$[QT_INSTALL_PREFIX]/../Src/qtbase/src/3rdparty/sqlite.pri)
} else {
LIBS += -lsqlite3
tests/em/tst_querybuilder.cpp
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
QVERIFY(p);
QCOMPARE(p->getNickName(), QString("Lotta"));
}
void QuerybuilderTest::testFindByAttributesManyToManyResolve() {
QHash<QString, QVariant> attributes;
attributes["persNumber"] = 42;
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
QVERIFY(p);
QCOMPARE(p->getNickName(), QString("Lotta"));
QCOMPARE(p->getGroups().size(), 2);
attributes.clear();
attributes["name"] = "Group ABC";
}
void QuerybuilderTest::testFindByAttributesOneToManyResolve() {
QHash<QString, QVariant> attributes;
attributes["persNumber"] = 42;
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
QVERIFY(p);
QCOMPARE(p->getMaintainedGroups().size(), 2);
QSharedPointer<Group> g = e->findEntityByAttributes<Group>(attributes, true);
}
void QuerybuilderTest::testFindByAttributesOneToOneResolve() {
}
void QuerybuilderTest::testFindByAttributesManyToOneResolve() {
QHash<QString, QVariant> attributes;
attributes["name"] = QString("Group Health");
QSharedPointer<Group> g = this->e->findEntityByAttributes<Group>(attributes, true);
QVERIFY(g->getLeader());
QCOMPARE(g->getLeader()->getFirstName(), QString("Fenja"));
QCOMPARE(g->getLeader()->getFamilyName(), QString("Sey."));
}
void QuerybuilderTest::testFindByAttributesManyToOneRelation() {
QHash<QString, QVariant> attributes;
attributes["firstName"] = QString("Lucien");
attributes["familyName"] = QString("We");
QSharedPointer<Person> p = e->findEntityByAttributes<Person>(attributes, true);
QSharedPointer<Person> p = this->e->findEntityByAttributes<Person>(attributes, true);
QVERIFY(p);
attributes.clear();
attributes["leader"] = QVariant(p);
......
void QuerybuilderTest::testFindByAttributesManyToOneRelationAttribute() {
QHash<QString, QVariant> attributes;
attributes["leader.firstName"] = QString("Fenja");
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
QSharedPointer<Group> group = this->e->findEntityByAttributes<Group>
(attributes, true);
QVERIFY(group);
}
......
void QuerybuilderTest::testFindByAttributesManyToManyRelation() {
QHash<QString, QVariant> attributes;
attributes["firstName"] = "Kristina";
QSharedPointer<Person> p = e->findEntityByAttributes<Person>(attributes, true);
QSharedPointer<Person> p = this->e->findEntityByAttributes<Person>(attributes, true);
QVERIFY(p);
QCOMPARE(p->getFamilyName(), QString("Zero"));
attributes.clear();
......
QHash<QString, QVariant> attributes;
QList<QSharedPointer<Person>> persons = QList<QSharedPointer<Person>>();
attributes["firstName"] = QString("Lucien");
QSharedPointer<Person> p1 = e->findEntityByAttributes<Person>(attributes, true);
QSharedPointer<Person> p1 = this->e->findEntityByAttributes<Person>(attributes, true);
QVERIFY(p1);
QCOMPARE(p1->getFamilyName(), QString("We"));
persons.append(p1);
attributes["firstName"] = QString("Janine");
QSharedPointer<Person> p2 = e->findEntityByAttributes<Person>(attributes, true);
QSharedPointer<Person> p2 = this->e->findEntityByAttributes<Person>(attributes, true);
QVERIFY(p2);
QCOMPARE(p2->getFamilyName(), QString("Musterfrau"));
persons.append(p2);
......
QVariant var;
var.setValue<QList<QSharedPointer<Person>>>(persons);
attributes["persons"] = var;
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
QSharedPointer<Group> group = this->e->findEntityByAttributes<Group>
(attributes, true);
QVERIFY(group);
QCOMPARE(group->getName(), QString("Group Psy"));
......
void QuerybuilderTest::testFindByAttributesManyToManyRelationAttribute() {
QHash<QString, QVariant> attributes;
attributes["persons.firstName"] = QString("Janine");
QSharedPointer<Group> group = e->findEntityByAttributes<Group>
QSharedPointer<Group> group = this->e->findEntityByAttributes<Group>
(attributes, true);
QVERIFY(group);
QCOMPARE(group->getName(), QString("Group Psy"));
}
void QuerybuilderTest::testQueryBuilder() {
auto qb = e->getQueryBuilder();
auto qb = this->e->getQueryBuilder();
Query q = Query();
q.appendWhere(q.like(qb, QString("firstName"), QString("Fenj"),
JokerPosition::BEHIND));
q.setLimit(10);
QList<QSharedPointer<Person>> list = e->find<Person>(q);
QList<QSharedPointer<Person>> list = this->e->find<Person>(q);
QCOMPARE(list.size(), 2);
}
......
Query q = Query();
q.appendJoins(q.joinBaseClasses(qb, emp));
try {
QList<QSharedPointer<Employee>> list = e->find<Employee>(q);
QList<QSharedPointer<Employee>> list = this->e->find<Employee>(q);
QCOMPARE(list.size(), 3);
} catch(QString e) {
qWarning() << e;
......
void QuerybuilderTest::testQueryBuilderEntityInheritanceWithoutJoin() {
Query q = Query();
try {
QList<QSharedPointer<Employee>> list = e->find<Employee>(q, true);
QList<QSharedPointer<Employee>> list = this->e->find<Employee>(q, true);
QCOMPARE(list.size(), 3);
} catch(QString e) {
qWarning() << e;
......
q.setDistinct(true);
q.appendOrderBy(OrderBy(QString("birthday"), Direction::SORT_DESC));
q.setLimit(10);
QList<QSharedPointer<Person>> list = e->find<Person>(q, true);
QList<QSharedPointer<Person>> list = this->e->find<Person>(q, true);
QCOMPARE(list.size(), 2);
QCOMPARE(list.at(0)->getFirstName(), QString("Fenja"));
QCOMPARE(list.at(0)->getFamilyName(), QString("Sey."));
......
Query q = Query();
q.appendWhere(q.equal(qb, "firstName", "Milan"));
q.appendJoin(Join("person", "person.id = employee.id"));
QList<QSharedPointer<Employee>> list = e->find<Employee>(q, false);
QList<QSharedPointer<Employee>> list = this->e->find<Employee>(q, false);
QCOMPARE(list.size(), 1);
QCOMPARE(list.at(0)->getFirstName(), QString("Milan"));
QCOMPARE(list.at(0)->getFamilyName(), QString("Mes."));
tests/em/tst_querybuilder.h
void testFindByAttributesManyToManyRelation();
void testFindByAttributesManyToManyRelationWithList();
void testFindByAttributesManyToManyRelationAttribute();
void testFindByAttributesManyToManyResolve();
void testFindByAttributesOneToManyResolve();
void testFindByAttributesOneToOneResolve();
void testFindByAttributesManyToOneResolve();
void testQueryBuilder();
void testQueryBuilderEntityInheritance();
void testQueryBuilderEntityInheritanceWithoutJoin();

Auch abrufbar als: Unified diff