00001 #include "domaintest.h"
00002
00003 #include <domain/duration.h>
00004 #include <domain/schedule.h>
00005 #include <domain/project.h>
00006 #include <domain/task.h>
00007 #include <domain/user.h>
00008 #include <domain/usertype.h>
00009 #include <domain/schedule.h>
00010 #include <domain/taskstates.h>
00011 #include <domain/resource.h>
00012 #include <domain/resourcetype.h>
00013 #include <domain/reservation.h>
00014 #include <domain/taskmanagerdata.h>
00015 #include <domain/tasktype.h>
00016 #include <domain/invitation.h>
00017 #include <domain/clock.h>
00018 #include <tools/stringexception.h>
00019 #include <QDateTime>
00020 #include <QDebug>
00021
00022 QString DomainTest::name() const
00023 {
00024 return "domaintest";
00025 }
00026
00027 void DomainTest::initTestCase()
00028 {
00029
00030 }
00031
00032 void DomainTest::cleanupTestCase()
00033 {
00034
00035 }
00036
00037 void DomainTest::init()
00038 {
00039 taskManagerData = domain::TaskManagerData::instance();
00040
00041 QDateTime startTime(QDate(2010,1,1), QTime(0,0,0));
00042
00043 taskManagerData->clock()->setTime(startTime);
00044 }
00045
00046 void DomainTest::cleanup()
00047 {
00048 taskManagerData->clearTheme();
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058 #define FETCH_DURATION \
00059 QFETCH(int, weeks); \
00060 QFETCH(int, days); \
00061 QFETCH(int, hours); \
00062 QFETCH(int, minutes); \
00063 QFETCH(int, seconds)
00064
00065 void DomainTest::testDurationValid()
00066 {
00067 FETCH_DURATION;
00068
00069 domain::Duration duration(weeks, days, hours, minutes, seconds);
00070
00071 QCOMPARE(duration.weeks(), weeks);
00072 QCOMPARE(duration.days(), days);
00073 QCOMPARE(duration.hours(), hours);
00074 QCOMPARE(duration.minutes(), minutes);
00075 QCOMPARE(duration.seconds(), seconds);
00076 }
00077
00078 void DomainTest::testDurationInvalid()
00079 {
00080 FETCH_DURATION;
00081
00082 EXPECT_EXCEPTION(domain::Duration duration(weeks, days, hours,
00083 minutes, seconds));
00084 }
00085
00086 void DomainTest::testDurationTotalSecs()
00087 {
00088 FETCH_DURATION;
00089
00090 domain::Duration duration(weeks, days, hours, minutes, seconds);
00091 int total = seconds + 60 * (minutes + 60 * (hours + 24 * (days + 7 * weeks)));
00092
00093 QCOMPARE(duration.totalSeconds(), total);
00094 }
00095
00096 #undef FETCH_DURATION
00097
00098 #define FETCH_DURATION \
00099 QFETCH(int, weeks1); \
00100 QFETCH(int, days1); \
00101 QFETCH(int, hours1); \
00102 QFETCH(int, minutes1); \
00103 QFETCH(int, seconds1); \
00104 QFETCH(int, weeks2); \
00105 QFETCH(int, days2); \
00106 QFETCH(int, hours2); \
00107 QFETCH(int, minutes2); \
00108 QFETCH(int, seconds2)
00109
00110 void DomainTest::testDurationEquals()
00111 {
00112 FETCH_DURATION;
00113
00114 domain::Duration duration1(weeks1, days1, hours1, minutes1, seconds1);
00115 domain::Duration duration2(weeks2, days2, hours2, minutes2, seconds2);
00116
00117 QVERIFY(duration1 == duration2);
00118 }
00119
00120 void DomainTest::testDurationNotEquals()
00121 {
00122 FETCH_DURATION;
00123
00124 domain::Duration duration1(weeks1, days1, hours1, minutes1, seconds1);
00125 domain::Duration duration2(weeks2, days2, hours2, minutes2, seconds2);
00126
00127 QVERIFY(!(duration1 == duration2));
00128 }
00129
00130 void DomainTest::testDurationGreaterThan()
00131 {
00132 FETCH_DURATION;
00133
00134 domain::Duration duration1(weeks1, days1, hours1, minutes1, seconds1);
00135 domain::Duration duration2(weeks2, days2, hours2, minutes2, seconds2);
00136
00137 QVERIFY(duration1 > duration2);
00138 QVERIFY(!(duration1 < duration2));
00139 }
00140
00141 void DomainTest::testDurationSmallerThan()
00142 {
00143 FETCH_DURATION;
00144
00145 domain::Duration duration1(weeks1, days1, hours1, minutes1, seconds1);
00146 domain::Duration duration2(weeks2, days2, hours2, minutes2, seconds2);
00147
00148 QVERIFY(duration1 < duration2);
00149 QVERIFY(!(duration1 > duration2));
00150 }
00151
00152 #undef FETCH_DURATION
00153
00154 #define DURATION_COLUMNS \
00155 QTest::addColumn<int>("weeks"); \
00156 QTest::addColumn<int>("days"); \
00157 QTest::addColumn<int>("hours"); \
00158 QTest::addColumn<int>("minutes"); \
00159 QTest::addColumn<int>("seconds")
00160
00161 void DomainTest::testDurationValid_data()
00162 {
00163 DURATION_COLUMNS;
00164
00165 QTest::newRow("valid1") << 5 << 6 << 23 << 59 << 59;
00166 QTest::newRow("valid2") << INT_MAX / (60 * 60 * 24 * 7) - 1
00167 << 6 << 23 << 59 << 59;
00168 QTest::newRow("valid3") << 0 << 0 << 0 << 0 << 1;
00169 }
00170
00171 void DomainTest::testDurationInvalid_data()
00172 {
00173 DURATION_COLUMNS;
00174
00175 QTest::newRow("invalid_zero") << 0 << 0 << 0 << 0 << 0;
00176 QTest::newRow("invalid_seconds1") << 5 << 6 << 23 << 59 << 60;
00177 QTest::newRow("invalid_seconds2") << 5 << 6 << 23 << 59 << -1;
00178 QTest::newRow("invalid_minutes1") << 5 << 6 << 23 << 60 << 59;
00179 QTest::newRow("invalid_minutes2") << 5 << 6 << 23 << -1 << 59;
00180 QTest::newRow("invalid_hours1") << 5 << 6 << 24 << 59 << 59;
00181 QTest::newRow("invalid_hours2") << 5 << 6 << -1 << 59 << 59;
00182 QTest::newRow("invalid_days1") << 5 << 7 << 23 << 59 << 59;
00183 QTest::newRow("invalid_days2") << 5 << -1 << 23 << 59 << 59;
00184 QTest::newRow("invalid_weeks") << INT_MAX / (60 * 60 * 24 * 7)
00185 << 6 << 23 << 59 << 59;
00186 }
00187
00188 void DomainTest::testDurationTotalSecs_data()
00189 {
00190 DURATION_COLUMNS;
00191
00192 QTest::newRow("total1") << 0 << 2 << 1 << 25 << 0;
00193 QTest::newRow("total2") << 0 << 3 << 0 << 5 << 58;
00194 QTest::newRow("total3") << 1 << 4 << 9 << 6 << 0;
00195 QTest::newRow("total4") << 5 << 6 << 0 << 52 << 40;
00196 }
00197
00198 #undef DURATION_COLUMNS
00199
00200 #define DURATION_COLUMNS \
00201 QTest::addColumn<int>("weeks1"); \
00202 QTest::addColumn<int>("days1"); \
00203 QTest::addColumn<int>("hours1"); \
00204 QTest::addColumn<int>("minutes1"); \
00205 QTest::addColumn<int>("seconds1"); \
00206 QTest::addColumn<int>("weeks2"); \
00207 QTest::addColumn<int>("days2"); \
00208 QTest::addColumn<int>("hours2"); \
00209 QTest::addColumn<int>("minutes2"); \
00210 QTest::addColumn<int>("seconds2")
00211
00212 void DomainTest::testDurationEquals_data()
00213 {
00214 DURATION_COLUMNS;
00215
00216 QTest::newRow("equals1") << 1 << 1 << 1 << 1 << 1
00217 << 1 << 1 << 1 << 1 << 1;
00218 QTest::newRow("equals2") << 1 << 5 << 1 << 20 << 1
00219 << 1 << 5 << 1 << 20 << 1;
00220 }
00221
00222 void DomainTest::testDurationNotEquals_data()
00223 {
00224 DURATION_COLUMNS;
00225
00226 QTest::newRow("not_equals1") << 1 << 1 << 1 << 1 << 1
00227 << 1 << 1 << 3 << 1 << 1;
00228 QTest::newRow("not_equals2") << 1 << 5 << 1 << 20 << 1
00229 << 1 << 5 << 2 << 20 << 1;
00230 }
00231
00232 void DomainTest::testDurationGreaterThan_data()
00233 {
00234 DURATION_COLUMNS;
00235
00236 QTest::newRow("greater1") << 2 << 1 << 1 << 1 << 1
00237 << 1 << 1 << 3 << 1 << 1;
00238 QTest::newRow("greater2") << 1 << 1 << 2 << 1 << 1
00239 << 1 << 1 << 1 << 1 << 1;
00240 }
00241
00242 void DomainTest::testDurationSmallerThan_data()
00243 {
00244 DURATION_COLUMNS;
00245
00246 QTest::newRow("smaller1") << 1 << 1 << 1 << 1 << 1
00247 << 1 << 1 << 3 << 1 << 1;
00248 QTest::newRow("smaller2") << 1 << 5 << 1 << 20 << 1
00249 << 1 << 5 << 2 << 22 << 10;
00250 }
00251
00252 #undef DURATION_COLUMNS
00253
00254
00255
00256
00257
00258
00259 #define FETCH_SCHEDULE \
00260 QFETCH(QDateTime, startDate); \
00261 QFETCH(QDateTime, dueDate); \
00262 QFETCH(int, durationSecs);
00263
00264 void DomainTest::testScheduleValid()
00265 {
00266 FETCH_SCHEDULE;
00267 domain::Duration duration(durationSecs);
00268 domain::Schedule schedule(duration,startDate,dueDate);
00269 QCOMPARE(schedule.startDate(),startDate);
00270 QCOMPARE(schedule.dueDate(),dueDate);
00271 QCOMPARE(schedule.duration(),duration);
00272 }
00273
00274 void DomainTest::testScheduleInvalid()
00275 {
00276 FETCH_SCHEDULE;
00277
00278 domain::Duration duration(durationSecs);
00279 EXPECT_EXCEPTION(domain::Schedule(duration,startDate,dueDate));
00280 }
00281
00282 void DomainTest::testScheduleSetters()
00283 {
00284 QDateTime start = QDateTime::currentDateTime();
00285 QDateTime end = start.addSecs(100);
00286 domain::Duration duration(50);
00287
00288 EXPECT_EXCEPTION(domain::Schedule(duration, end, start));
00289
00290 domain::Schedule schedule(duration, start, end);
00291
00292
00293 QCOMPARE(schedule.startDate(), start);
00294 QCOMPARE(schedule.dueDate(), end);
00295 QCOMPARE(schedule.duration(), duration);
00296
00297
00298 domain::Schedule sched(schedule);
00299 sched.setDuration(100);
00300 QCOMPARE(sched.duration().totalSeconds(), 100);
00301 sched.setDuration(1);
00302 QCOMPARE(sched.duration().totalSeconds(), 1);
00303 EXPECT_EXCEPTION(sched.setDuration(101));
00304 EXPECT_EXCEPTION(sched.setDuration(0));
00305 EXPECT_EXCEPTION(sched.setDuration(-1));
00306
00307
00308 sched = schedule;
00309 EXPECT_EXCEPTION(sched.setStartDate(end));
00310 QDateTime newStart(start.addSecs(-10));
00311 sched.setStartDate(newStart);
00312 QCOMPARE(sched.startDate(), newStart);
00313 newStart = start.addSecs(60);
00314 EXPECT_EXCEPTION(sched.setStartDate(newStart));
00315
00316
00317 sched = schedule;
00318 EXPECT_EXCEPTION(sched.setDueDate(start));
00319 QDateTime newEnd(end.addSecs(10));
00320 sched.setDueDate(newEnd);
00321 QCOMPARE(sched.dueDate(), newEnd);
00322 newEnd = end.addSecs(-60);
00323 EXPECT_EXCEPTION(sched.setDueDate(newEnd));
00324 }
00325
00326 void DomainTest::testScheduleAssignment()
00327 {
00328 FETCH_SCHEDULE;
00329
00330 domain::Duration duration(durationSecs);
00331 domain::Schedule schedule(duration,startDate,dueDate);
00332
00333 domain::Schedule temp = schedule;
00334 QCOMPARE(temp, schedule);
00335 }
00336
00337 #undef FETCH_SCHEDULE
00338
00339 #define FETCH_SCHEDULE \
00340 QFETCH(QDateTime, startDate1); \
00341 QFETCH(QDateTime, dueDate1); \
00342 QFETCH(int, durationSecs1); \
00343 QFETCH(QDateTime, startDate2); \
00344 QFETCH(QDateTime, dueDate2); \
00345 QFETCH(int, durationSecs2)
00346
00347 void DomainTest::testScheduleEquals()
00348 {
00349 FETCH_SCHEDULE;
00350
00351 domain::Duration duration1(durationSecs1);
00352 domain::Duration duration2(durationSecs2);
00353
00354 domain::Schedule schedule1(duration1,startDate1,dueDate1);
00355 domain::Schedule schedule2(duration2,startDate2,dueDate2);
00356
00357 QVERIFY(schedule1 == schedule2);
00358 }
00359
00360 #undef FETCH_SCHEDULE
00361
00362 #define SCHEDULE_COLUMNS \
00363 QTest::addColumn<QDateTime>("startDate"); \
00364 QTest::addColumn<QDateTime>("dueDate"); \
00365 QTest::addColumn<int>("durationSecs");
00366
00367 void DomainTest::testScheduleValid_data()
00368 {
00369 SCHEDULE_COLUMNS;
00370
00371 QTest::newRow("valid2") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00372 << QDateTime(QDate(2009,1,1), QTime(0,0,1))
00373 << 1;
00374 QTest::newRow("valid3") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00375 << QDateTime(QDate(2009,1,1), QTime(0,0,2))
00376 << 1;
00377 QTest::newRow("valid4") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00378 << QDateTime(QDate(2009,1,1), QTime(0,0,2))
00379 << 2;
00380 QTest::newRow("valid5") << QDateTime(QDate(2000,1,1), QTime(0,0,0))
00381 << QDateTime(QDate(2001,1,1), QTime(0,0,0))
00382 << 60 * 60 * 24 * 7 * 52;
00383 }
00384
00385 void DomainTest::testScheduleInvalid_data()
00386 {
00387 SCHEDULE_COLUMNS;
00388
00389 QTest::newRow("invalid2") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00390 << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00391 << 1;
00392 QTest::newRow("invalid3") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00393 << QDateTime(QDate(2009,1,1), QTime(0,0,1))
00394 << 2;
00395 QTest::newRow("invalid4") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00396 << QDateTime(QDate(2009,1,1), QTime(0,0,2))
00397 << 3;
00398 }
00399
00400 void DomainTest::testScheduleSetters_data()
00401 {
00402 SCHEDULE_COLUMNS;
00403
00404 QTest::newRow("valid1") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00405 << QDateTime(QDate(2009,1,1), QTime(0,0,1))
00406 << 0;
00407 QTest::newRow("valid2") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00408 << QDateTime(QDate(2009,1,1), QTime(0,0,1))
00409 << 1;
00410 QTest::newRow("valid3") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00411 << QDateTime(QDate(2009,1,1), QTime(0,0,2))
00412 << 1;
00413 }
00414
00415 void DomainTest::testScheduleAssignment_data()
00416 {
00417 SCHEDULE_COLUMNS;
00418
00419 QTest::newRow("assign1") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00420 << QDateTime(QDate(2009,1,1), QTime(0,0,2))
00421 << 1;
00422 QTest::newRow("assign2") << QDateTime(QDate(2009,1,1), QTime(0,0,0))
00423 << QDateTime(QDate(2009,1,1), QTime(0,0,2))
00424 << 2;
00425
00426 QTest::newRow("assign3") << QDateTime(QDate(2000,1,1), QTime(0,0,0))
00427 << QDateTime(QDate(2001,1,1), QTime(0,0,0))
00428 << 60 * 60 * 24 * 7 * 52;
00429 }
00430
00431 #undef SCHEDULE_COLUMNS
00432
00433 #define SCHEDULE_COLUMNS \
00434 QTest::addColumn<QDateTime>("startDate1"); \
00435 QTest::addColumn<QDateTime>("dueDate1"); \
00436 QTest::addColumn<int>("durationSecs1"); \
00437 QTest::addColumn<QDateTime>("startDate2"); \
00438 QTest::addColumn<QDateTime>("dueDate2"); \
00439 QTest::addColumn<int>("durationSecs2"); \
00440
00441 void DomainTest::testScheduleEquals_data()
00442 {
00443 SCHEDULE_COLUMNS;
00444
00445 QTest::newRow("equals1") << QDateTime(QDate(2009,2,1), QTime(0,0,0))
00446 << QDateTime(QDate(2009,2,2), QTime(0,0,1))
00447 << 30
00448 << QDateTime(QDate(2009,2,1), QTime(0,0,0))
00449 << QDateTime(QDate(2009,2,2), QTime(0,0,1))
00450 << 30;
00451 QTest::newRow("equals2") << QDateTime(QDate(2008,1,1), QTime(24,0,0))
00452 << QDateTime(QDate(2009,1,2), QTime(1,0,1))
00453 << 2677
00454 << QDateTime(QDate(2008,1,1), QTime(24,0,0))
00455 << QDateTime(QDate(2009,1,2), QTime(1,0,1))
00456 << 2677;
00457 QTest::newRow("equals3") << QDateTime(QDate(2005,1,1), QTime(0,5,0))
00458 << QDateTime(QDate(2009,1,2), QTime(0,9,1))
00459 << 60
00460 << QDateTime(QDate(2005,1,1), QTime(0,5,0))
00461 << QDateTime(QDate(2009,1,2), QTime(0,9,1))
00462 << 60;
00463 }
00464
00465 #undef SCHEDULE_COLUMNS
00466
00467
00468
00469
00470
00471
00472
00473 void DomainTest::testUserType()
00474 {
00475 QVERIFY(taskManagerData->userTypes().isEmpty());
00476 domain::UserType* userType =
00477 taskManagerData->createUserType("testId1", "Test User Type 1");
00478 QVERIFY(userType->id() == "testId1");
00479 QVERIFY(userType->name() == "Test User Type 1");
00480 QVERIFY(taskManagerData->typeById("testId1")->name() == "Test User Type 1");
00481
00482 QCOMPARE(taskManagerData->userTypes().size(), 1);
00483 taskManagerData->createUserType("testId2", "Test User Type 2");
00484 QCOMPARE(taskManagerData->userTypes().size(), 2);
00485 taskManagerData->clear();
00486 QCOMPARE(taskManagerData->userTypes().size(), 2);
00487 taskManagerData->clearTheme();
00488 QVERIFY(taskManagerData->userTypes().isEmpty());
00489
00490 taskManagerData->createUserType("testId1", "Test User Type 1");
00491 EXPECT_EXCEPTION(taskManagerData->createUserType("testId1", "Test User Type 2"));
00492 }
00493
00494 void DomainTest::testUserCreation()
00495 {
00496 domain::UserType* userType =
00497 taskManagerData->createUserType("testId1", "Test User Type 1");
00498
00499 domain::User* user1;
00500 domain::User* user2;
00501 EXPECT_EXCEPTION(user1 = taskManagerData->createUser(0, "Test User 1"));
00502
00503 QVERIFY(taskManagerData->users().isEmpty());
00504 QVERIFY(!taskManagerData->users().contains(user1));
00505 user1 = taskManagerData->createUser(userType, "Test User1");
00506 QVERIFY(taskManagerData->users().contains(user1));
00507 QCOMPARE(taskManagerData->users().size(), 1);
00508 QVERIFY(!taskManagerData->users().contains(user2));
00509 user2 = taskManagerData->createUser(userType, "Test User2");
00510 QCOMPARE(taskManagerData->users().size(), 2);
00511 QVERIFY(taskManagerData->users().contains(user1));
00512 QVERIFY(taskManagerData->users().contains(user2));
00513
00514 taskManagerData->removeData(user1);
00515 QCOMPARE(taskManagerData->users().size(), 1);
00516 QVERIFY(!taskManagerData->users().contains(user1));
00517 QVERIFY(taskManagerData->users().contains(user2));
00518
00519
00520 EXPECT_EXCEPTION(user1 = taskManagerData->createUser(userType, "Test User2"));
00521
00522 taskManagerData->clearTheme();
00523 QVERIFY(taskManagerData->users().isEmpty());
00524 }
00525
00526 void DomainTest::testUserAdmin()
00527 {
00528 domain::UserType* userType =
00529 taskManagerData->createUserType("testId1", "Test User Type 1");
00530
00531 domain::User* user;
00532 user = taskManagerData->createUser(userType, "Test User");
00533 QVERIFY(!user->isAdmin());
00534 QCOMPARE(taskManagerData->users().size(), 1);
00535 QCOMPARE(taskManagerData->allUsers().size(), 2);
00536
00537 QList<domain::User*> list = taskManagerData->allUsers();
00538 domain::User* admin;
00539 if (list[0] == user)
00540 admin = list[1];
00541 else
00542 admin = list[0];
00543
00544 QVERIFY(admin->isAdmin());
00545
00546 taskManagerData->createUser(userType, "Test User1");
00547 taskManagerData->createUser(userType, "Test User2");
00548 taskManagerData->createUser(userType, "Test User3");
00549 QVERIFY(taskManagerData->adminUser() == admin);
00550 QVERIFY(!taskManagerData->users().contains(admin));
00551 QVERIFY(taskManagerData->allUsers().contains(admin));
00552 }
00553
00554 void DomainTest::testUserTasks()
00555 {
00556 domain::UserType* userType =
00557 taskManagerData->createUserType("testId1", "Test User Type 1");
00558
00559 domain::User* user;
00560 user = taskManagerData->createUser(userType, "Test User");
00561
00562 QVERIFY(user->tasks().isEmpty());
00563
00564 domain::Duration duration(0,0,0,1,0);
00565 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
00566 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
00567 domain::Schedule schedule(duration, startDate, dueDate);
00568 domain::TaskType* taskType = taskManagerData->
00569 createTaskType("testTaskType", "Test Task Type");
00570
00571
00572 EXPECT_EXCEPTION(taskManagerData->createTask(taskType, user ,schedule));
00573
00574 taskType->addPotentialOwner(userType);
00575 domain::Task* task = taskManagerData->createTask(taskType, user ,schedule);
00576
00577 QCOMPARE(user->tasks().size(), 1);
00578 QVERIFY(user->tasks().contains(task));
00579
00580
00581 domain::Task* task2 = taskManagerData->createTask(taskType, user ,schedule);
00582
00583 QCOMPARE(user->tasks().size(), 2);
00584 QVERIFY(user->tasks().contains(task));
00585 QVERIFY(user->tasks().contains(task2));
00586
00587 taskManagerData->removeData(task);
00588
00589 QCOMPARE(user->tasks().size(), 1);
00590 QVERIFY(user->tasks().contains(task2));
00591
00592 taskManagerData->removeData(task2);
00593
00594 QVERIFY(user->tasks().isEmpty());
00595 }
00596
00597 void DomainTest::testInvitationValid()
00598 {
00599 domain::UserType* userType =
00600 taskManagerData->createUserType("testId1", "Test User Type 1");
00601
00602 domain::User* userReceiving = taskManagerData->
00603 createUser(userType, "User Receiving");
00604 QVERIFY(userReceiving->invitations().isEmpty());
00605
00606
00607
00608 domain::User* userSending = taskManagerData->
00609 createUser(userType, "User Sending");
00610 QVERIFY(userSending->invitations().isEmpty());
00611
00612 domain::Duration duration(0,0,0,1,0);
00613 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
00614 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
00615 domain::Schedule schedule(duration, startDate, dueDate);
00616 domain::TaskType* taskType = taskManagerData->
00617 createTaskType("testTaskType", "Test Task Type");
00618 taskType->addPotentialOwner(userType);
00619 domain::UserRequirement* userReq = taskType->addRequirement(userType, 1, 1);
00620 domain::Task* task = taskManagerData->createTask(taskType,
00621 userSending, schedule);
00622
00623 QVERIFY(task->invitations().isEmpty());
00624
00625
00626 domain::Invitation* invitation = taskManagerData->
00627 createInvitation(task, userReceiving);
00628
00629 QCOMPARE(task->invitations().size(), 1);
00630 QVERIFY(task->invitations().contains(invitation));
00631
00632 QCOMPARE(userReceiving->invitations().size(), 1);
00633 QVERIFY(userReceiving->invitations().contains(invitation));
00634 QVERIFY(userSending->invitations().isEmpty());
00635 QVERIFY(!userReq->isFulfilled(task));
00636 invitation->setState(domain::Invitation::Accepted);
00637 QVERIFY(userReq->isFulfilled(task));
00638
00639
00640 domain::Task* task2 = taskManagerData->createTask(taskType,
00641 userSending, schedule);
00642
00643 QVERIFY(task2->invitations().isEmpty());
00644 QVERIFY(!task2->isAvailable());
00645
00646
00647 domain::Invitation* invitation2 = taskManagerData->
00648 createInvitation(task2, userReceiving);
00649
00650 QCOMPARE(task2->invitations().size(), 1);
00651 QVERIFY(task2->invitations().contains(invitation2));
00652
00653 QCOMPARE(userReceiving->invitations().size(), 2);
00654 QVERIFY(userReceiving->invitations().contains(invitation));
00655 QVERIFY(userReceiving->invitations().contains(invitation2));
00656 QVERIFY(userSending->invitations().isEmpty());
00657 QVERIFY(!userReq->isFulfilled(task2));
00658 QVERIFY(!task2->isAvailable());
00659 invitation2->setState(domain::Invitation::Accepted);
00660 QVERIFY(userReq->isFulfilled(task2));
00661 QVERIFY(task2->isAvailable());
00662
00663
00664 domain::UserType* userType2 =
00665 taskManagerData->createUserType("testId2", "Test User Type 2");
00666 domain::User* userSending2 = taskManagerData->
00667 createUser(userType2, "Sending User 2");
00668 domain::TaskType* taskType2 = taskManagerData->
00669 createTaskType("testTaskType2", "Test Task Type 2");
00670 domain::UserRequirement* userReq2 = taskType2->addRequirement(userType, 1, 1);
00671 taskType2->addPotentialOwner(userType2);
00672 domain::Task* task3 = taskManagerData->createTask(taskType2,
00673 userSending2, schedule);
00674
00675 QVERIFY(task3->invitations().isEmpty());
00676
00677
00678 domain::Invitation* invitation3 = taskManagerData->
00679 createInvitation(task3, userReceiving);
00680
00681 QCOMPARE(task3->invitations().size(), 1);
00682 QVERIFY(task3->invitations().contains(invitation3));
00683
00684 QCOMPARE(userReceiving->invitations().size(), 3);
00685 QVERIFY(userReceiving->invitations().contains(invitation));
00686 QVERIFY(userReceiving->invitations().contains(invitation2));
00687 QVERIFY(userReceiving->invitations().contains(invitation3));
00688 QVERIFY(userSending->invitations().isEmpty());
00689 QVERIFY(userSending2->invitations().isEmpty());
00690 QVERIFY(!userReq2->isFulfilled(task3));
00691 invitation3->setState(domain::Invitation::Accepted);
00692 QVERIFY(userReq2->isFulfilled(task3));
00693
00694
00695 taskManagerData->removeData(invitation2);
00696
00697 QVERIFY(task2->invitations().isEmpty());
00698
00699 QCOMPARE(userReceiving->invitations().size(), 2);
00700 QVERIFY(userReceiving->invitations().contains(invitation));
00701 QVERIFY(userReceiving->invitations().contains(invitation3));
00702 QVERIFY(userSending->invitations().isEmpty());
00703 QVERIFY(userSending2->invitations().isEmpty());
00704 QVERIFY(!userReq->isFulfilled(task2));
00705
00706 taskManagerData->removeData(invitation);
00707
00708 QVERIFY(task->invitations().isEmpty());
00709
00710 QCOMPARE(userReceiving->invitations().size(), 1);
00711 QVERIFY(userReceiving->invitations().contains(invitation3));
00712 QVERIFY(userSending->invitations().isEmpty());
00713 QVERIFY(userSending2->invitations().isEmpty());
00714 QVERIFY(!userReq->isFulfilled(task));
00715
00716 taskManagerData->removeData(invitation3);
00717
00718 QVERIFY(task3->invitations().isEmpty());
00719
00720 QVERIFY(userReceiving->invitations().isEmpty());
00721 QVERIFY(userSending->invitations().isEmpty());
00722 QVERIFY(userSending2->invitations().isEmpty());
00723 QVERIFY(!userReq2->isFulfilled(task3));
00724 }
00725
00726 void DomainTest::testInvitationInvalid()
00727 {
00728 domain::UserType* userType =
00729 taskManagerData->createUserType("testId1", "Test User Type 1");
00730
00731 domain::User* userReceiving = taskManagerData->
00732 createUser(userType, "User Receiving");
00733
00734 domain::User* userReceiving2 = taskManagerData->
00735 createUser(userType, "User Receiving2");
00736
00737 domain::User* userReceiving3 = taskManagerData->
00738 createUser(userType, "User Receiving3");
00739
00740
00741 domain::User* userSending = taskManagerData->
00742 createUser(userType, "User Sending");
00743 QVERIFY(userSending->invitations().isEmpty());
00744
00745 domain::Duration duration(0,0,0,1,0);
00746 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
00747 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
00748 domain::Schedule schedule(duration, startDate, dueDate);
00749 domain::TaskType* taskType = taskManagerData->
00750 createTaskType("testTaskType", "Test Task Type");
00751 taskType->addPotentialOwner(userType);
00752
00753 domain::Task* taskWrong1 = taskManagerData->createTask(taskType,
00754 userSending, schedule);
00755
00756 EXPECT_EXCEPTION(taskManagerData->createInvitation(taskWrong1, userReceiving));
00757
00758 taskType->addRequirement(userType, 1, 2);
00759 domain::Task* task = taskManagerData->createTask(taskType,
00760 userSending, schedule);
00761
00762 QVERIFY(task->invitations().isEmpty());
00763
00764
00765 EXPECT_EXCEPTION(taskManagerData->createInvitation(task, userSending));
00766
00767
00768 domain::Invitation* invitation = taskManagerData->
00769 createInvitation(task, userReceiving);
00770
00771
00772 EXPECT_EXCEPTION(taskManagerData->createInvitation(task, userReceiving));
00773
00774
00775 domain::Invitation* invitation2 = taskManagerData->
00776 createInvitation(task, userReceiving2);
00777
00778
00779 EXPECT_EXCEPTION(taskManagerData->createInvitation(task, userReceiving3));
00780
00781 invitation->setState(domain::Invitation::Accepted);
00782
00783
00784 EXPECT_EXCEPTION(taskManagerData->createInvitation(task, userReceiving3));
00785
00786 invitation2->setState(domain::Invitation::Declined);
00787
00788
00789 taskManagerData->createInvitation(task, userReceiving3);
00790 }
00791
00792
00793
00794
00795
00796
00797
00798
00799 void DomainTest::testResourceType()
00800 {
00801 domain::ResourceType* type =
00802 taskManagerData->createResourceType("testId","testName");
00803
00804 QVERIFY(type->name() == "testName");
00805 QVERIFY(type->id() == "testId");
00806
00807 EXPECT_EXCEPTION(taskManagerData->createResourceType("","testName"));
00808 EXPECT_EXCEPTION(taskManagerData->createResourceType("testId",""));
00809 EXPECT_EXCEPTION(taskManagerData->createResourceType("",""));
00810 EXPECT_EXCEPTION(taskManagerData->createResourceType("testId","testName2"));
00811
00812 taskManagerData->createResourceType("testId2","testName");
00813 }
00814
00815 void DomainTest::testResourceCreation()
00816 {
00817 domain::ResourceType* resourceType =
00818 taskManagerData->createResourceType("testId","testName");
00819
00820 domain::Resource* resource =
00821 taskManagerData->createResource("resource", resourceType);
00822
00823 QCOMPARE(resource->resourceTypeName(), QString("testName"));
00824
00825 QVERIFY(resource->resourceType() == resourceType);
00826 QVERIFY(resource->description() == "resource");
00827 QVERIFY(resource->dependentData().isEmpty());
00828 QVERIFY(resource->reservations().isEmpty());
00829 }
00830
00831
00832
00833
00834
00835
00836
00837 void DomainTest::testReservationValid()
00838 {
00839 domain::UserType* userType =
00840 taskManagerData->createUserType("testId1", "Test User Type 1");
00841 domain::User* user = taskManagerData->createUser(userType, "User for task");
00842
00843 domain::Duration duration(0,0,0,1,0);
00844 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
00845 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
00846 domain::Schedule schedule(duration, startDate, dueDate);
00847
00848 domain::ResourceType* resourceType1 = taskManagerData->
00849 createResourceType("resourceType1", "type 1");
00850 domain::Resource* resource1 = taskManagerData->
00851 createResource("resource1", resourceType1);
00852 domain::Resource* resource2 = taskManagerData->
00853 createResource("resource2", resourceType1);
00854 domain::ResourceType* resourceType2 = taskManagerData->
00855 createResourceType("resourceType2", "type 2");
00856 domain::Resource* resource3 = taskManagerData->
00857 createResource("resource3", resourceType2);
00858
00859 domain::TaskType* taskType1 =
00860 taskManagerData->createTaskType("taskType1", "foo");
00861 domain::TaskType* taskType2 =
00862 taskManagerData->createTaskType("taskType2", "foo");
00863
00864 taskType1->addPotentialOwner(userType);
00865 taskType2->addPotentialOwner(userType);
00866
00867 domain::ResourceRequirement* requirement1 = taskType1->addRequirement(resourceType1,1,2);
00868 domain::ResourceRequirement* requirement2 = taskType2->addRequirement(resourceType1,1,2);
00869 domain::ResourceRequirement* requirement3 = taskType2->addRequirement(resourceType2,1,1);
00870 domain::Task* task1 = taskManagerData->createTask(taskType1, user, schedule);
00871 domain::Task* task2 = taskManagerData->createTask(taskType2, user, schedule);
00872 domain::Duration durationReservation(0,0,0,1,0);
00873
00874
00875 QVERIFY(!requirement1->isFulfilled(task1));
00876 QCOMPARE(task1->reservations().size(), 0);
00877 domain::Reservation* reservation1 = taskManagerData->
00878 createReservation(task1, resource1, startDate, durationReservation);
00879 QCOMPARE(task1->reservations().size(), 1);
00880 QVERIFY(task1->reservations().contains(reservation1));
00881 QCOMPARE(resource1->reservations().size(), 1);
00882 QVERIFY(resource1->reservations().contains(reservation1));
00883
00884
00885 QVERIFY(requirement1->isFulfilled(task1));
00886 domain::Reservation* reservation2 = taskManagerData->
00887 createReservation(task1, resource2, startDate, durationReservation);
00888 QCOMPARE(task1->reservations().size(), 2);
00889 QVERIFY(task1->reservations().contains(reservation1));
00890 QVERIFY(task1->reservations().contains(reservation2));
00891 QVERIFY(requirement1->isFulfilled(task1));
00892 QCOMPARE(resource2->reservations().size(), 1);
00893 QVERIFY(resource2->reservations().contains(reservation2));
00894
00895 taskManagerData->removeData(reservation1);
00896 QVERIFY(requirement1->isFulfilled(task1));
00897 QCOMPARE(task1->reservations().size(), 1);
00898 QVERIFY(task1->reservations().contains(reservation2));
00899 QVERIFY(resource1->reservations().isEmpty());
00900 QCOMPARE(resource2->reservations().size(), 1);
00901 QVERIFY(resource2->reservations().contains(reservation2));
00902
00903 taskManagerData->removeData(reservation2);
00904 QVERIFY(!requirement1->isFulfilled(task1));
00905 QVERIFY(task1->reservations().isEmpty());
00906 QVERIFY(resource2->reservations().isEmpty());
00907
00908
00909
00910 QVERIFY(!requirement2->isFulfilled(task2));
00911 reservation1 = taskManagerData->
00912 createReservation(task2, resource1, startDate, durationReservation);
00913 QVERIFY(requirement2->isFulfilled(task2));
00914 QVERIFY(!task2->requirementsAreFulfilled());
00915
00916 QVERIFY(!requirement3->isFulfilled(task2));
00917 reservation2 = taskManagerData->
00918 createReservation(task2, resource3, startDate, durationReservation);
00919 QVERIFY(requirement2->isFulfilled(task2));
00920 QVERIFY(requirement3->isFulfilled(task2));
00921 QVERIFY(task2->requirementsAreFulfilled());
00922
00923 taskManagerData->removeData(reservation1);
00924 QVERIFY(!task2->requirementsAreFulfilled());
00925 QVERIFY(!requirement2->isFulfilled(task2));
00926 QVERIFY(requirement3->isFulfilled(task2));
00927
00928 taskManagerData->removeData(reservation2);
00929 QVERIFY(!task2->requirementsAreFulfilled());
00930 QVERIFY(!requirement2->isFulfilled(task2));
00931 QVERIFY(!requirement3->isFulfilled(task2));
00932 }
00933
00934 void DomainTest::testReservationInValid()
00935 {
00936 domain::UserType* userType =
00937 taskManagerData->createUserType("testId1", "Test User Type 1");
00938 domain::User* user = taskManagerData->createUser(userType, "User for task");
00939
00940 domain::Duration duration(0,0,0,1,0);
00941 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
00942 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
00943 domain::Schedule schedule(duration, startDate, dueDate);
00944
00945 domain::ResourceType* resourceType1 = taskManagerData->
00946 createResourceType("resourceType1", "type 1");
00947 domain::Resource* resource1 = taskManagerData->
00948 createResource("resource1", resourceType1);
00949 domain::Resource* resource2 = taskManagerData->
00950 createResource("resource2", resourceType1);
00951 domain::Resource* resource3 = taskManagerData->
00952 createResource("resource2", resourceType1);
00953 domain::ResourceType* resourceType2 = taskManagerData->
00954 createResourceType("resourceType2", "type 2");
00955 domain::Resource* resource4 = taskManagerData->
00956 createResource("resource3", resourceType2);
00957
00958 domain::TaskType* taskType1 =
00959 taskManagerData->createTaskType("taskType1", "foo");
00960 domain::TaskType* taskType2 =
00961 taskManagerData->createTaskType("taskType2", "foo");
00962
00963 taskType1->addPotentialOwner(userType);
00964 taskType2->addPotentialOwner(userType);
00965
00966 taskType1->addRequirement(resourceType1,1,2);
00967 taskType2->addRequirement(resourceType1,1,2);
00968 taskType2->addRequirement(resourceType2,1,1);
00969 domain::Task* task1 = taskManagerData->createTask(taskType1, user, schedule);
00970 domain::Task* task2 = taskManagerData->createTask(taskType2, user, schedule);
00971 domain::Duration durationReservation(0,0,0,2,5);
00972
00973
00974 domain::Reservation* reservation1 = taskManagerData->
00975 createReservation(task1, resource1, startDate, durationReservation);
00976 QCOMPARE(resource1->reservations().size(), 1);
00977 QVERIFY(resource1->reservations().contains(reservation1));
00978 QCOMPARE(task1->reservations().size(), 1);
00979 QVERIFY(task1->reservations().contains(reservation1));
00980
00981
00982 EXPECT_EXCEPTION(taskManagerData->
00983 createReservation(task2, resource1, startDate, durationReservation));
00984
00985
00986 QDateTime wrongStartDate = startDate.addSecs(durationReservation.totalSeconds() - 1);
00987 EXPECT_EXCEPTION(taskManagerData->
00988 createReservation(task2, resource1, wrongStartDate, durationReservation));
00989
00990
00991 QDateTime goodStartDate = startDate.addSecs(durationReservation.totalSeconds());
00992 domain::Reservation* reservation2 = taskManagerData->
00993 createReservation(task2, resource1, goodStartDate, durationReservation);
00994 QCOMPARE(resource1->reservations().size(), 2);
00995 QVERIFY(resource1->reservations().contains(reservation1));
00996 QVERIFY(resource1->reservations().contains(reservation2));
00997 QCOMPARE(task1->reservations().size(), 1);
00998 QVERIFY(task1->reservations().contains(reservation1));
00999 QCOMPARE(task2->reservations().size(), 1);
01000 QVERIFY(task2->reservations().contains(reservation2));
01001
01002 taskManagerData->removeData(reservation2);
01003 QCOMPARE(resource1->reservations().size(), 1);
01004 QVERIFY(resource1->reservations().contains(reservation1));
01005 QCOMPARE(task1->reservations().size(), 1);
01006 QVERIFY(task1->reservations().contains(reservation1));
01007 QVERIFY(task2->reservations().isEmpty());
01008
01009
01010 goodStartDate = startDate.addSecs(-60);
01011 domain::Duration badDuration(0, 0, 0, 1, 1);
01012 EXPECT_EXCEPTION(taskManagerData->
01013 createReservation(task2, resource1, goodStartDate, badDuration));
01014
01015
01016 domain::Duration goodDuration(0, 0, 0, 1, 0);
01017 reservation2 = taskManagerData->createReservation(
01018 task2, resource1, goodStartDate, goodDuration);
01019
01020 taskManagerData->removeData(reservation2);
01021
01022
01023 goodStartDate = startDate.addSecs(-60);
01024 badDuration = domain::Duration(0, 0, 0, 1, 0);
01025 EXPECT_EXCEPTION(taskManagerData->createReservation(
01026 task1, resource2, goodStartDate, badDuration));
01027
01028
01029
01030
01031 badDuration = domain::Duration(0, 0, 0, 1, 59);
01032 EXPECT_EXCEPTION(taskManagerData->createReservation(
01033 task1, resource2, goodStartDate, badDuration));
01034
01035
01036 goodDuration = domain::Duration(0, 0, 0, 2, 0);
01037 reservation2 = taskManagerData->
01038 createReservation(task1, resource2, goodStartDate, goodDuration);
01039
01040 QVERIFY(task1->requirementsAreFulfilled());
01041
01042 taskManagerData->removeData(reservation2);
01043
01044
01045 wrongStartDate = startDate.addSecs(durationReservation.totalSeconds());
01046 EXPECT_EXCEPTION(taskManagerData->createReservation(
01047 task1, resource2, wrongStartDate, goodDuration));
01048
01049
01050
01051
01052 wrongStartDate = startDate.addSecs(durationReservation.totalSeconds() -
01053 task1->schedule().duration().totalSeconds() + 1);
01054 EXPECT_EXCEPTION(taskManagerData->createReservation(
01055 task1, resource2, wrongStartDate, goodDuration));
01056
01057
01058 wrongStartDate = startDate.addSecs(durationReservation.totalSeconds() -
01059 task1->schedule().duration().totalSeconds());
01060 reservation2 = taskManagerData->
01061 createReservation(task1, resource2, wrongStartDate, goodDuration);
01062
01063 QVERIFY(task1->requirementsAreFulfilled());
01064
01065
01066 EXPECT_EXCEPTION(taskManagerData->
01067 createReservation(task1, resource3, goodStartDate, goodDuration));
01068
01069 QVERIFY(task1->requirementsAreFulfilled());
01070
01071 taskManagerData->removeData(reservation2);
01072
01073
01074 reservation2 = taskManagerData->
01075 createReservation(task1, resource3, goodStartDate, goodDuration);
01076
01077
01078 EXPECT_EXCEPTION(taskManagerData->
01079 createReservation(task1, resource4, startDate, durationReservation));
01080
01081 }
01082
01083
01084
01085
01086
01087
01088 void DomainTest::testProjectCreation()
01089 {
01090 EXPECT_EXCEPTION(taskManagerData->createProject(""));
01091
01092 QString description("Testproject");
01093 QVERIFY(taskManagerData->projects().isEmpty());
01094 domain::Project* testProject = taskManagerData->createProject(description);
01095 QCOMPARE(taskManagerData->projects().size(), 1);
01096 QCOMPARE(testProject->description(), description);
01097 QVERIFY(testProject->tasks().isEmpty());
01098
01099 taskManagerData->removeData(testProject);
01100 }
01101
01102 void DomainTest::testProjectDescription()
01103 {
01104 QString description("Testproject");
01105 domain::Project* testProject = taskManagerData->createProject(description);
01106 testProject->setDescription("foo");
01107 QCOMPARE(testProject->description(), QString("foo"));
01108
01109 EXPECT_EXCEPTION(testProject->setDescription(""););
01110 }
01111
01112 void DomainTest::testProjectTasks()
01113 {
01114 domain::Project* testProject = taskManagerData->createProject("Testproject");
01115
01116 domain::UserType* userType =
01117 taskManagerData->createUserType("testId1", "Test User Type 1");
01118 domain::User* user = taskManagerData->createUser(userType, "User for task");
01119
01120 domain::Duration duration(0,0,0,1,0);
01121 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
01122 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
01123 domain::Schedule schedule(duration, startDate, dueDate);
01124
01125 domain::TaskType* taskType1 =
01126 taskManagerData->createTaskType("taskType1", "foo");
01127
01128 taskType1->addPotentialOwner(userType);
01129
01130 domain::Task* task1 = taskManagerData->createTask(taskType1, user, schedule);
01131 domain::Task* task2 = taskManagerData->createTask(taskType1, user, schedule);
01132
01133
01134
01135 QCOMPARE(testProject->tasks().size(), 0);
01136 QVERIFY(!testProject->tasks().contains(task1));
01137 QVERIFY(!testProject->tasks().contains(task2));
01138 QVERIFY(task1->project() == 0);
01139 QVERIFY(task2->project() == 0);
01140 task1->setProject(testProject);
01141 QCOMPARE(testProject->tasks().size(), 1);
01142 QVERIFY(testProject->tasks().contains(task1));
01143 QVERIFY(!testProject->tasks().contains(task2));
01144 QCOMPARE(task1->project(), testProject);
01145 QVERIFY(task2->project() == 0);
01146
01147
01148 task2->setProject(testProject);
01149 QCOMPARE(testProject->tasks().size(), 2);
01150 QVERIFY(testProject->tasks().contains(task1));
01151 QVERIFY(testProject->tasks().contains(task2));
01152 QCOMPARE(task1->project(), testProject);
01153 QCOMPARE(task2->project(), testProject);
01154 QCOMPARE(testProject->tasks().size(), 2);
01155
01156
01157 taskManagerData->removeData(task1);
01158 QVERIFY(!testProject->tasks().contains(task1));
01159 QVERIFY(testProject->tasks().contains(task2));
01160 QCOMPARE(testProject->tasks().size(), 1);
01161 QCOMPARE(task2->project(), testProject);
01162
01163
01164 task1 = taskManagerData->createTask(taskType1, user, schedule);
01165 task1->setProject(testProject);
01166 QCOMPARE(testProject->tasks().size(), 2);
01167 QVERIFY(testProject->tasks().contains(task1));
01168 QVERIFY(testProject->tasks().contains(task2));
01169 QCOMPARE(task1->project(), testProject);
01170 QCOMPARE(task2->project(), testProject);
01171 QCOMPARE(taskManagerData->tasks().size(), 2);
01172 QCOMPARE(taskManagerData->projects().size(), 1);
01173
01174
01175 domain::Project* testProject2 = taskManagerData->createProject("TestProject2");
01176 task1->setProject(testProject2);
01177 QCOMPARE(testProject->tasks().size(), 1);
01178 QVERIFY(!testProject->tasks().contains(task1));
01179 QVERIFY(testProject->tasks().contains(task2));
01180 QCOMPARE(task2->project(), testProject);
01181 QCOMPARE(testProject2->tasks().size(), 1);
01182 QVERIFY(testProject2->tasks().contains(task1));
01183 QVERIFY(!testProject2->tasks().contains(task2));
01184 QCOMPARE(task1->project(), testProject2);
01185 QCOMPARE(taskManagerData->tasks().size(), 2);
01186 QCOMPARE(taskManagerData->projects().size(), 2);
01187
01188
01189
01190 QCOMPARE(taskManagerData->tasks().size(), 2);
01191 QVERIFY(taskManagerData->tasks().contains(task1));
01192 QVERIFY(taskManagerData->tasks().contains(task2));
01193 taskManagerData->removeData(testProject);
01194 QCOMPARE(taskManagerData->tasks().size(), 1);
01195 QVERIFY(taskManagerData->tasks().contains(task1));
01196 QVERIFY(!taskManagerData->tasks().contains(task2));
01197 QCOMPARE(taskManagerData->tasks().size(), 1);
01198 QCOMPARE(testProject2->tasks().size(), 1);
01199 QCOMPARE(taskManagerData->tasks().first(), testProject2->tasks().first());
01200 }
01201
01202
01203
01204
01205
01206
01207
01208 void DomainTest::testTaskType()
01209 {
01210 domain::TaskType* taskType =
01211 taskManagerData->createTaskType("TaskType", "TaskTypeName");
01212 QVERIFY(taskType->name() == "TaskTypeName");
01213 QVERIFY(taskType->id() == "TaskType");
01214
01215
01216 EXPECT_EXCEPTION(taskManagerData->createTaskType("", "TaskTypeName"));
01217 EXPECT_EXCEPTION(taskManagerData->createTaskType("TaskType", ""));
01218 EXPECT_EXCEPTION(taskManagerData->createTaskType("TaskType", "TaskTypeName"));
01219
01220 domain::UserType* userType1 =
01221 taskManagerData->createUserType("testId1", "Test User Type 1");
01222 domain::UserType* userType2 =
01223 taskManagerData->createUserType("testId2", "Test User Type 2");
01224 domain::ResourceType* resourceType1 =
01225 taskManagerData->createResourceType("testResourceId1","rt1");
01226 domain::ResourceType* resourceType2 =
01227 taskManagerData->createResourceType("testResourceId2","rt2");
01228
01229
01230 EXPECT_EXCEPTION(taskType->addRequirement(resourceType1,3,1));
01231
01232
01233 domain::UserRequirement* requirement1 = taskType->addRequirement(userType1,1,2);
01234 domain::UserRequirement* requirement2 = taskType->addRequirement(userType2,1,2);
01235 EXPECT_EXCEPTION(taskType->addRequirement(userType1,1,3));
01236
01237
01238 domain::ResourceRequirement* requirement3 =
01239 taskType->addRequirement(resourceType1,1,2);
01240 domain::ResourceRequirement* requirement4 =
01241 taskType->addRequirement(resourceType2,1,2);
01242 EXPECT_EXCEPTION(taskType->addRequirement(resourceType1,1,3));
01243
01244
01245 QCOMPARE(taskType->requirements().size(), 4);
01246 QVERIFY(taskType->requirements().contains(requirement1));
01247 QVERIFY(taskType->requirements().contains(requirement2));
01248 QVERIFY(taskType->requirements().contains(requirement3));
01249 QVERIFY(taskType->requirements().contains(requirement4));
01250 QVERIFY(taskType->requirementByType(userType1) == requirement1);
01251 QVERIFY(taskType->requirementByType(userType2) == requirement2);
01252 QVERIFY(taskType->requirementByType(resourceType1) == requirement3);
01253 QVERIFY(taskType->requirementByType(resourceType2) == requirement4);
01254 QCOMPARE(taskType->userRequirements().size(), 2);
01255 QVERIFY(taskType->userRequirements().contains(requirement1));
01256 QVERIFY(taskType->userRequirements().contains(requirement2));
01257 QCOMPARE(taskType->resourceRequirements().size(), 2);
01258 QVERIFY(taskType->resourceRequirements().contains(requirement3));
01259 QVERIFY(taskType->resourceRequirements().contains(requirement4));
01260 QVERIFY(taskType->potentialOwners().isEmpty());
01261
01262
01263 taskType->addPotentialOwner(userType1);
01264 QCOMPARE(taskType->potentialOwners().size(), 1);
01265
01266 QVERIFY(taskType->userCanCreate(userType1));
01267 QVERIFY(!taskType->userCanCreate(userType2));
01268
01269 taskType->addPotentialOwner(userType2);
01270 QCOMPARE(taskType->potentialOwners().size(), 2);
01271
01272 QVERIFY(taskType->userCanCreate(userType1));
01273 QVERIFY(taskType->userCanCreate(userType2));
01274 }
01275
01276 void DomainTest::testTaskFields()
01277 {
01278 domain::TaskType* taskType =
01279 taskManagerData->createTaskType("TaskType", "TaskTypeName");
01280
01281 domain::Field field1;
01282 field1.id = "field1";
01283 field1.name = "Field 1";
01284 field1.nature = domain::Field::Textual;
01285
01286 taskType->addField(field1);
01287 QCOMPARE(taskType->fields().size(), 1);
01288 QVERIFY(taskType->fieldById("field1").id == field1.id);
01289
01290 domain::Field field2;
01291 EXPECT_EXCEPTION(taskType->addField(field2));
01292 field2.name = "Field 2";
01293 EXPECT_EXCEPTION(taskType->addField(field2));
01294 field2.nature = domain::Field::Numerical;
01295 EXPECT_EXCEPTION(taskType->addField(field2));
01296 field2.id = "field1";
01297 EXPECT_EXCEPTION(taskType->addField(field2));
01298 field2.id = "field2";
01299 taskType->addField(field2);
01300 QCOMPARE(taskType->fields().size(), 2);
01301 QVERIFY(taskType->fieldById("field1").id == field1.id);
01302 QVERIFY(taskType->fieldById("field2").id == field2.id);
01303
01304 domain::Field badfield2;
01305 badfield2.id = "field3";
01306 EXPECT_EXCEPTION(taskType->addField(badfield2));
01307 domain::Field badfield3 = domain::Field();
01308 badfield3.name = "foo";
01309 EXPECT_EXCEPTION(taskType->addField(badfield3));
01310 domain::Field badfield4 = domain::Field();
01311 badfield4.nature = domain::Field::Textual;
01312 EXPECT_EXCEPTION(taskType->addField(badfield4));
01313
01314
01315 domain::UserType* userType =
01316 taskManagerData->createUserType("testId1", "Test User Type 1");
01317 domain::User* user = taskManagerData->createUser(userType, "User for task");
01318
01319 domain::Duration duration(0,0,0,1,0);
01320 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
01321 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
01322 domain::Schedule schedule(duration, startDate, dueDate);
01323
01324 taskType->addPotentialOwner(userType);
01325
01326 domain::Task* task = taskManagerData->createTask(taskType, user, schedule);
01327
01328 QCOMPARE(task->taskType()->fields().size(), 2);
01329 QVERIFY(task->field("field1").isNull());
01330 task->setField("field1", "test");
01331 QVERIFY(task->field("field1") == "test");
01332 task->setField("field1", "test2");
01333 QVERIFY(task->field("field1") == "test2");
01334 EXPECT_EXCEPTION(task->setField("field2", "text"));
01335 task->setField("field2", 2353243);
01336 QVERIFY(task->field("field2") == "2353243");
01337 task->setField("field2", "2353243");
01338 QVERIFY(task->field("field2") == "2353243");
01339
01340 }
01341
01342 void DomainTest::testTaskCreation()
01343 {
01344 domain::UserType* userType =
01345 taskManagerData->createUserType("testId1", "Test User Type 1");
01346 domain::User* user = taskManagerData->createUser(userType, "User for task");
01347
01348 domain::Duration duration(0,0,0,1,0);
01349 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
01350 QDateTime dueDate(QDate(2011,1,1), QTime(0,0,0));
01351 domain::Schedule schedule(duration, startDate, dueDate);
01352 domain::Duration duration2(0,0,0,2,0);
01353 domain::Schedule schedule2(duration2, startDate, dueDate);
01354
01355 domain::TaskType* taskType =
01356 taskManagerData->createTaskType("tasktype1", "Task Type 1");
01357 taskType->addPotentialOwner(userType);
01358 domain::TaskType* taskType2 =
01359 taskManagerData->createTaskType("tasktype2", "Task Type 2");
01360 taskType2->addPotentialOwner(userType);
01361
01362
01363
01364 domain::Task* subTask = taskManagerData->createTask(taskType, user, schedule,
01365 domain::TaskState::Unfinished);
01366
01367 QCOMPARE(taskManagerData->tasks().size(), 1);
01368 QCOMPARE(taskManagerData->tasksForUser(user).size(), 1);
01369 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01370
01371 QList<domain::Task*> subT = QList<domain::Task*>();
01372 subT.append(subTask);
01373
01374 EXPECT_EXCEPTION(taskManagerData->createTask(taskType2, user, schedule2,
01375 domain::TaskState::Successful,subT));
01376 QCOMPARE(taskManagerData->tasksForUser(user).size(), 1);
01377 domain::Task* task = taskManagerData->createTask(taskType2, user, schedule2,
01378 domain::TaskState::Unfinished, subT);
01379 QCOMPARE(taskManagerData->tasks().size(), 2);
01380 QCOMPARE(taskManagerData->tasksForUser(user).size(), 2);
01381 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01382 QVERIFY(taskManagerData->tasksForUser(user).contains(task));
01383
01384 QCOMPARE(task->subTasks().size(), 1);
01385 QVERIFY(task->subTasks().contains(subTask));
01386 QCOMPARE(subTask->allSuperTasks().size(), 1);
01387 QVERIFY(subTask->allSuperTasks().contains(task));
01388
01389 subT.append(task);
01390 domain::Task* superTask = taskManagerData->createTask(taskType2, user, schedule2,
01391 domain::TaskState::Unfinished, subT);
01392
01393
01394 QCOMPARE(taskManagerData->tasks().size(), 3);
01395 QCOMPARE(taskManagerData->tasksForUser(user).size(), 3);
01396 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01397 QVERIFY(taskManagerData->tasksForUser(user).contains(task));
01398 QVERIFY(taskManagerData->tasksForUser(user).contains(superTask));
01399 QCOMPARE(superTask->subTasks().size(), 2);
01400 QVERIFY(superTask->subTasks().contains(subTask));
01401 QVERIFY(superTask->subTasks().contains(task));
01402 QCOMPARE(subTask->allSuperTasks().size(), 2);
01403 QVERIFY(subTask->allSuperTasks().contains(task));
01404 QVERIFY(subTask->allSuperTasks().contains(superTask));
01405 QCOMPARE(task->allSuperTasks().size(), 1);
01406 QVERIFY(task->allSuperTasks().contains(superTask));
01407
01408 taskManagerData->removeData(task);
01409 QCOMPARE(taskManagerData->tasks().size(), 2);
01410 QCOMPARE(taskManagerData->tasksForUser(user).size(), 2);
01411 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01412 QVERIFY(taskManagerData->tasksForUser(user).contains(superTask));
01413 QCOMPARE(superTask->subTasks().size(), 1);
01414 QVERIFY(superTask->subTasks().contains(subTask));
01415 QCOMPARE(subTask->allSuperTasks().size(), 1);
01416 QVERIFY(subTask->allSuperTasks().contains(superTask));
01417
01418 taskManagerData->removeData(superTask);
01419 QCOMPARE(taskManagerData->tasks().size(), 1);
01420 QCOMPARE(taskManagerData->tasksForUser(user).size(), 1);
01421 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01422
01423 taskManagerData->removeData(subTask);
01424 QCOMPARE(taskManagerData->tasks().size(), 0);
01425 QCOMPARE(taskManagerData->tasksForUser(user).size(), 0);
01426
01427
01428 subTask = taskManagerData->createTask(taskType, user, schedule,
01429 domain::TaskState::Successful);
01430
01431 QCOMPARE(taskManagerData->tasks().size(), 1);
01432 QCOMPARE(taskManagerData->tasksForUser(user).size(), 1);
01433 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01434
01435 subT = QList<domain::Task*>();
01436 subT.append(subTask);
01437 task = taskManagerData->createTask(taskType2, user, schedule2,
01438 domain::TaskState::Successful, subT);
01439 QCOMPARE(taskManagerData->tasks().size(), 2);
01440 QCOMPARE(taskManagerData->tasksForUser(user).size(), 2);
01441 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01442 QVERIFY(taskManagerData->tasksForUser(user).contains(task));
01443
01444 QCOMPARE(task->subTasks().size(), 1);
01445 QVERIFY(task->subTasks().contains(subTask));
01446 QCOMPARE(subTask->allSuperTasks().size(), 1);
01447 QVERIFY(subTask->allSuperTasks().contains(task));
01448
01449 subT.append(task);
01450 superTask = taskManagerData->createTask(taskType2, user, schedule2,
01451 domain::TaskState::Unfinished, subT);
01452
01453
01454 QCOMPARE(taskManagerData->tasks().size(), 3);
01455 QCOMPARE(taskManagerData->tasksForUser(user).size(), 3);
01456 QVERIFY(taskManagerData->tasksForUser(user).contains(subTask));
01457 QVERIFY(taskManagerData->tasksForUser(user).contains(task));
01458 QVERIFY(taskManagerData->tasksForUser(user).contains(superTask));
01459 QCOMPARE(superTask->subTasks().size(), 2);
01460 QVERIFY(superTask->subTasks().contains(subTask));
01461 QVERIFY(superTask->subTasks().contains(task));
01462 QCOMPARE(subTask->allSuperTasks().size(), 2);
01463 QVERIFY(subTask->allSuperTasks().contains(task));
01464 QVERIFY(subTask->allSuperTasks().contains(superTask));
01465 QCOMPARE(task->allSuperTasks().size(), 1);
01466 QVERIFY(task->allSuperTasks().contains(superTask));
01467
01468 taskManagerData->removeData(subTask);
01469 QCOMPARE(taskManagerData->tasks().size(), 2);
01470 QCOMPARE(taskManagerData->tasksForUser(user).size(), 2);
01471 QVERIFY(taskManagerData->tasksForUser(user).contains(task));
01472 QVERIFY(taskManagerData->tasksForUser(user).contains(superTask));
01473 QCOMPARE(superTask->subTasks().size(), 1);
01474 QVERIFY(superTask->subTasks().contains(task));
01475 QCOMPARE(task->allSuperTasks().size(), 1);
01476 QVERIFY(task->allSuperTasks().contains(superTask));
01477
01478 taskManagerData->removeData(superTask);
01479 QCOMPARE(taskManagerData->tasks().size(), 1);
01480 QCOMPARE(taskManagerData->tasksForUser(user).size(), 1);
01481 QVERIFY(taskManagerData->tasksForUser(user).contains(task));
01482
01483 taskManagerData->removeData(task);
01484 QCOMPARE(taskManagerData->tasksForUser(user).size(), 0);
01485 QCOMPARE(taskManagerData->tasks().size(), 0);
01486
01487 }
01488
01489 void DomainTest::testTaskStates()
01490 {
01491 QDateTime date(QDate(2010,1,1), QTime(0,0,0));
01492 taskManagerData->clock()->setTime(date);
01493
01494 domain::Duration duration(0,0,0,1,0);
01495 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
01496 QDateTime dueDate(QDate(2010,2,1), QTime(0,0,0));
01497 domain::Schedule schedule(duration, startDate, dueDate);
01498
01499 domain::UserType* userType =
01500 taskManagerData->createUserType("testId1", "Test User Type 1");
01501 domain::User* user = taskManagerData->createUser(userType, "User for task");
01502
01503 domain::TaskType* taskType =
01504 taskManagerData->createTaskType("TaskType", "TaskTypeName");
01505
01506 taskType->addPotentialOwner(userType);
01507
01508
01509 domain::Task* task1 = taskManagerData->
01510 createTask(taskType, user, schedule, domain::TaskState::Successful);
01511 QCOMPARE(task1->state(), domain::TaskState::Successful);
01512
01513
01514 domain::Task* task2 = taskManagerData->
01515 createTask(taskType, user, schedule);
01516 QCOMPARE(task2->state(), domain::TaskState::Unfinished);
01517
01518
01519 domain::Task* task3 = taskManagerData->
01520 createTask(taskType, user, schedule, domain::TaskState::Failed);
01521 QCOMPARE(task3->state(), domain::TaskState::Failed);
01522
01523
01524
01525
01526 task1->setState(domain::TaskState::Unfinished);
01527 QCOMPARE(task1->state(), domain::TaskState::Unfinished);
01528
01529
01530 task1->setState(domain::TaskState::Failed);
01531 QCOMPARE(task1->state(), domain::TaskState::Failed);
01532
01533
01534 task1->setState(domain::TaskState::Unfinished);
01535 QCOMPARE(task1->state(), domain::TaskState::Unfinished);
01536
01537
01538 task1->setState(domain::TaskState::Successful);
01539 QCOMPARE(task1->state(), domain::TaskState::Successful);
01540
01541
01542 task1->setState(domain::TaskState::Failed);
01543 QCOMPARE(task1->state(), domain::TaskState::Failed);
01544
01545
01546
01547
01548 EXPECT_EXCEPTION(task1->setState(domain::TaskState::Successful));
01549
01550
01551 taskManagerData->clock()->setTime(date.addDays(4));
01552 QCOMPARE(task1->state(), domain::TaskState::Failed);
01553
01554
01555
01556 domain::TaskType* taskType2 =
01557 taskManagerData->createTaskType("TaskType2", "TaskTypeName");
01558 taskType2->addPotentialOwner(userType);
01559 domain::Task* task4 = taskManagerData->
01560 createTask(taskType2, user, schedule);
01561 taskManagerData->clock()->setTime(date);
01562 domain::ResourceType* resourceType = taskManagerData->
01563 createResourceType("resourceTypeId","resourceTypeName");
01564
01565 QVERIFY(task4->isAvailable());
01566 QCOMPARE(task4->state(), domain::TaskState::Unfinished);
01567 taskType2->addRequirement(resourceType, 1, 2);
01568 QVERIFY(!task4->isAvailable());
01569 QCOMPARE(task4->state(), domain::TaskState::Unfinished);
01570
01571
01572
01573 task1 = taskManagerData->
01574 createTask(taskType, user, schedule, domain::TaskState::Unfinished);
01575 task2 = taskManagerData->
01576 createTask(taskType, user, schedule, domain::TaskState::Successful);
01577 task1->addSubTask(task2);
01578 task1->setState(domain::TaskState::Successful);
01579
01580 QCOMPARE(task1->state(), domain::TaskState::Successful);
01581 QCOMPARE(task2->state(), domain::TaskState::Successful);
01582 task2->setState(domain::TaskState::Failed);
01583 QCOMPARE(task1->state(), domain::TaskState::Failed);
01584 QCOMPARE(task2->state(), domain::TaskState::Failed);
01585
01586
01587
01588 EXPECT_EXCEPTION(task1->setState(domain::TaskState::Unfinished));
01589 EXPECT_EXCEPTION(task1->setState(domain::TaskState::Successful));
01590 }
01591
01592 void DomainTest::testBusinessRule1()
01593 {
01594 domain::UserType* userType =
01595 taskManagerData->createUserType("testId1", "Test User Type 1");
01596 domain::User* user = taskManagerData->createUser(userType, "User for task");
01597
01598 domain::TaskType* taskType =
01599 taskManagerData->createTaskType("TaskType", "TaskTypeName");
01600
01601 taskType->addPotentialOwner(userType);
01602
01603
01604 domain::Duration duration(0,0,0,1,0);
01605 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
01606 QDateTime dueDate(QDate(2010,1,2), QTime(0,0,0));
01607 domain::Schedule scheduleSuper(duration, startDate, dueDate);
01608 domain::Task* superTask = taskManagerData->
01609 createTask(taskType, user, scheduleSuper, domain::TaskState::Unfinished);
01610
01611
01612 QCOMPARE(superTask->earliestEndTime(), startDate.addSecs(
01613 superTask->schedule().duration().totalSeconds()));
01614
01615
01616 duration = domain::Duration(0,0,0,1,0);
01617 startDate = QDateTime(QDate(2010,1,1), QTime(3,0,0));
01618 dueDate = QDateTime(QDate(2010,1,2), QTime(0,0,0));
01619 domain::Schedule scheduleSub1(duration, startDate, dueDate);
01620
01621 domain::Task* subTask1 = taskManagerData->
01622 createTask(taskType, user, scheduleSub1, domain::TaskState::Unfinished);
01623 QCOMPARE(subTask1->earliestEndTime(),
01624 startDate.addSecs(duration.totalSeconds()));
01625 superTask->addSubTask(subTask1);
01626
01627
01628 QCOMPARE(superTask->earliestEndTime(), subTask1->earliestEndTime().addSecs(
01629 superTask->schedule().duration().totalSeconds()));
01630
01631
01632 duration = domain::Duration(0,0,0,1,0);
01633 startDate = QDateTime(QDate(2010,1,1), QTime(23,58,0));
01634 dueDate = QDateTime(QDate(2010,1,3), QTime(0,0,0));
01635 domain::Schedule scheduleSub2(duration, startDate, dueDate);
01636
01637 domain::Task* subTask2 = taskManagerData->
01638 createTask(taskType, user, scheduleSub2, domain::TaskState::Unfinished);
01639
01640 superTask->addSubTask(subTask2);
01641
01642
01643 QCOMPARE(superTask->earliestEndTime(), subTask2->earliestEndTime().addSecs(
01644 superTask->schedule().duration().totalSeconds()));
01645
01646
01647 duration = domain::Duration(0,0,0,1,1);
01648 domain::Schedule scheduleSub3(duration, startDate, dueDate);
01649 domain::Task* subTask3 = taskManagerData->
01650 createTask(taskType, user, scheduleSub3, domain::TaskState::Unfinished);
01651
01652 EXPECT_EXCEPTION(superTask->addSubTask(subTask3));
01653 }
01654
01655 void DomainTest::testBusinessRule2()
01656 {
01657 domain::Duration duration(0,0,0,1,0);
01658 QDateTime startDate(QDate(2010,1,1), QTime(0,0,0));
01659 QDateTime dueDate(QDate(2010,2,1), QTime(0,0,0));
01660 domain::Schedule schedule(duration, startDate, dueDate);
01661
01662 domain::UserType* userType =
01663 taskManagerData->createUserType("testId1", "Test User Type 1");
01664 domain::User* user = taskManagerData->createUser(userType, "User for task");
01665
01666 domain::TaskType* taskType =
01667 taskManagerData->createTaskType("TaskType", "TaskTypeName");
01668
01669 taskType->addPotentialOwner(userType);
01670
01671
01672
01673
01674
01675 domain::Task* superTask = taskManagerData->
01676 createTask(taskType, user, schedule);
01677 QCOMPARE(superTask->state(), domain::TaskState::Unfinished);
01678
01679
01680 domain::Task* subTask1 = taskManagerData->
01681 createTask(taskType, user, schedule, domain::TaskState::Failed);
01682 QCOMPARE(subTask1->state(), domain::TaskState::Failed);
01683
01684 superTask->addSubTask(subTask1);
01685 QCOMPARE(superTask->state(), domain::TaskState::Failed);
01686 EXPECT_EXCEPTION(superTask->setState(domain::TaskState::Unfinished));
01687 EXPECT_EXCEPTION(superTask->setState(domain::TaskState::Successful));
01688
01689
01690
01691
01692
01693 subTask1 = taskManagerData->
01694 createTask(taskType, user, schedule, domain::TaskState::Successful);
01695 QList<domain::Task*> list;
01696 list << subTask1;
01697
01698
01699 superTask = taskManagerData->createTask(taskType, user,
01700 schedule, domain::TaskState::Successful, list);
01701 QCOMPARE(superTask->state(), domain::TaskState::Successful);
01702 QCOMPARE(subTask1->state(), domain::TaskState::Successful);
01703 QVERIFY(superTask->subTasks().contains(subTask1));
01704
01705 subTask1->setState(domain::TaskState::Unfinished);
01706
01707 QCOMPARE(superTask->state(), domain::TaskState::Unfinished);
01708 QCOMPARE(subTask1->state(), domain::TaskState::Unfinished);
01709
01710
01711
01712
01713
01714 subTask1 = taskManagerData->
01715 createTask(taskType, user, schedule, domain::TaskState::Successful);
01716 list.clear();
01717 list << subTask1;
01718
01719
01720 superTask = taskManagerData->createTask(taskType, user,
01721 schedule, domain::TaskState::Successful, list);
01722 QCOMPARE(superTask->state(), domain::TaskState::Successful);
01723 QCOMPARE(subTask1->state(), domain::TaskState::Successful);
01724 QVERIFY(superTask->subTasks().contains(subTask1));
01725
01726 subTask1->setState(domain::TaskState::Failed);
01727
01728 QCOMPARE(superTask->state(), domain::TaskState::Failed);
01729 QCOMPARE(subTask1->state(), domain::TaskState::Failed);
01730
01731
01732
01733
01734 subTask1 = taskManagerData->
01735 createTask(taskType, user, schedule);
01736 list.clear();
01737 list << subTask1;
01738 EXPECT_EXCEPTION(taskManagerData->createTask(taskType, user,
01739 schedule, domain::TaskState::Successful, list));
01740 QVERIFY(subTask1->allSuperTasks().isEmpty());
01741
01742
01743 subTask1 = taskManagerData->
01744 createTask(taskType, user, schedule, domain::TaskState::Failed);
01745 list.clear();
01746 list << subTask1;
01747 EXPECT_EXCEPTION(taskManagerData->createTask(taskType, user,
01748 schedule, domain::TaskState::Successful, list));
01749 QVERIFY(subTask1->allSuperTasks().isEmpty());
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760 superTask = taskManagerData->createTask(taskType, user, schedule);
01761
01762 subTask1 = taskManagerData->
01763 createTask(taskType, user, schedule, domain::TaskState::Unfinished);
01764
01765 QCOMPARE(superTask->state(), domain::TaskState::Unfinished);
01766 superTask->addSubTask(subTask1);
01767 superTask->setState(domain::TaskState::Failed);
01768 QCOMPARE(superTask->state(), domain::TaskState::Failed);
01769 superTask->setState(domain::TaskState::Unfinished);
01770 QCOMPARE(superTask->state(), domain::TaskState::Unfinished);
01771 EXPECT_EXCEPTION(superTask->setState(domain::TaskState::Successful));
01772 QCOMPARE(superTask->state(), domain::TaskState::Unfinished);
01773 }
01774
01775 void DomainTest::testBusinessRule3()
01776 {
01777 domain::Duration duration(0,0,0,1,0);
01778 QDateTime startDate(QDate(2010,2,1), QTime(0,0,0));
01779 QDateTime dueDate(QDate(2010,3,1), QTime(0,0,0));
01780 domain::Schedule schedule(duration, startDate, dueDate);
01781
01782 domain::UserType* userType =
01783 taskManagerData->createUserType("testId1", "Test User Type 1");
01784 domain::User* user = taskManagerData->createUser(userType, "User for task");
01785
01786 domain::TaskType* taskType =
01787 taskManagerData->createTaskType("TaskType", "TaskTypeName");
01788
01789 taskType->addPotentialOwner(userType);
01790
01791
01792
01793 domain::Task* task = taskManagerData->
01794 createTask(taskType, user, schedule);
01795
01796 QCOMPARE(task->state(), domain::TaskState::Unfinished);
01797 QVERIFY(!task->isAvailable());
01798
01799
01800 taskManagerData->clock()->setTime(startDate.addSecs(10));
01801 QCOMPARE(task->state(), domain::TaskState::Unfinished);
01802 QVERIFY(task->isAvailable());
01803
01804
01805 taskManagerData->clock()->setTime(dueDate.addSecs(10));
01806 QCOMPARE(task->state(), domain::TaskState::Failed);
01807 QVERIFY(!task->isAvailable());
01808
01809
01810
01811
01812
01813
01814
01815
01816 taskManagerData->clock()->setTime(QDateTime(QDate(2010,1,1), QTime(0,0,0)));
01817
01818 task = taskManagerData->
01819 createTask(taskType, user, schedule, domain::TaskState::Failed);
01820 QCOMPARE(task->state(), domain::TaskState::Failed);
01821
01822 task = taskManagerData->
01823 createTask(taskType, user, schedule, domain::TaskState::Unfinished);
01824 QCOMPARE(task->state(), domain::TaskState::Unfinished);
01825 QVERIFY(!task->isAvailable());
01826
01827 EXPECT_EXCEPTION(taskManagerData->
01828 createTask(taskType, user, schedule, domain::TaskState::Successful));
01829
01830
01831 taskManagerData->clock()->setTime(startDate.addSecs(10));
01832
01833 task = taskManagerData->
01834 createTask(taskType, user, schedule, domain::TaskState::Failed);
01835 QCOMPARE(task->state(), domain::TaskState::Failed);
01836
01837 task = taskManagerData->
01838 createTask(taskType, user, schedule, domain::TaskState::Unfinished);
01839 QCOMPARE(task->state(), domain::TaskState::Unfinished);
01840 QVERIFY(task->isAvailable());
01841
01842 task = taskManagerData->
01843 createTask(taskType, user, schedule, domain::TaskState::Successful);
01844 QCOMPARE(task->state(), domain::TaskState::Successful);
01845 QVERIFY(!task->isAvailable());
01846
01847
01848 taskManagerData->clock()->setTime(dueDate.addSecs(10));
01849
01850 task = taskManagerData->
01851 createTask(taskType, user, schedule, domain::TaskState::Failed);
01852 QCOMPARE(task->state(), domain::TaskState::Failed);
01853
01854 EXPECT_EXCEPTION(taskManagerData->
01855 createTask(taskType, user, schedule, domain::TaskState::Unfinished));
01856
01857 task = taskManagerData->
01858 createTask(taskType, user, schedule, domain::TaskState::Successful);
01859
01860 QCOMPARE(task->state(), domain::TaskState::Successful);
01861 QVERIFY(!task->isAvailable());
01862 }
01863
01864 Q_EXPORT_PLUGIN2(test_domain, DomainTest)