00001 #include "controltest.h"
00002
00003 #include <domain/schedule.h>
00004 #include <domain/task.h>
00005 #include <domain/schedule.h>
00006 #include <domain/project.h>
00007 #include <domain/user.h>
00008 #include <domain/project.h>
00009 #include <domain/taskstates.h>
00010 #include <domain/reservation.h>
00011 #include <domain/resourcetype.h>
00012
00013 #include <control/focusinterface.h>
00014 #include <control/controllerfactory.h>
00015 #include <control/controldata.h>
00016 #include <control/models/usermodel.h>
00017 #include <control/models/taskmodel.h>
00018 #include <control/models/projectmodel.h>
00019 #include <control/models/resourcemodel.h>
00020 #include <control/models/invitationmodel.h>
00021
00022 #include <plugins/focusstrategies/duration/durationfocus.h>
00023
00024 #include <tools/functions.h>
00025 #include <tools/stringexception.h>
00026
00027 #include <QPluginLoader>
00028 #include <QDir>
00029 #include <QDebug>
00030
00031 #ifdef Q_OS_WIN32
00032 #define FILTER "focus_*.dll"
00033 #else
00034 #define FILTER "libfocus_*.so"
00035 #endif
00036
00037 QString ControlTest::name() const
00038 {
00039 return "controltest";
00040 }
00041
00042 void ControlTest::initTestCase()
00043 {
00044
00045 }
00046
00047 void ControlTest::cleanupTestCase()
00048 {
00049
00050 }
00051
00052 void ControlTest::init()
00053 {
00054
00055
00056 controller = 0;
00057
00058 ui = new TestUi();
00059 taskManagerData = domain::TaskManagerData::instance();
00060 factory = new control::ControllerFactory(taskManagerData, ui);
00061
00062 ui->data->error = false;
00063 ui->data->warning = false;
00064 ui->data->message = false;
00065 ui->data->model = false;
00066 ui->data->models = false;
00067 ui->data->start = false;
00068 ui->data->questionAsked = false;
00069 ui->data->questionAnswer = false;
00070 ui->data->openFileNamesCounter = 0;
00071 ui->data->selectionCounter = 0;
00072 ui->data->choiceCounter = 0;
00073 ui->data->taskDetailsAnswerCounter = 0;
00074 }
00075
00076 void ControlTest::cleanup()
00077 {
00078
00079 delete ui;
00080 delete factory;
00081 delete controller;
00082
00083 taskManagerData->clearTheme();
00084 }
00085
00086 QList<control::FocusInterface*> getfocusStrategies(TestUi* ui)
00087 {
00088 QDir pluginsDir = PLUGINS_PATH;
00089 pluginsDir.setNameFilters(QStringList() << FILTER);
00090
00091
00092 QStringList files = pluginsDir.entryList(QDir::Files);
00093
00094 QList<control::FocusInterface*> focusStrategies;
00095
00096 Q_FOREACH (QString fileName, files)
00097 {
00098 QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
00099
00100 if (pluginLoader.load())
00101 {
00102 control::FocusInterface* strategy =
00103 qobject_cast<control::FocusInterface*>(pluginLoader.instance());
00104
00105 if (strategy != 0)
00106 {
00107 strategy->init(domain::TaskManagerData::instance(), ui);
00108 focusStrategies << strategy;
00109 }
00110 }
00111 else
00112 {
00113 qDebug() << "Failed to load" << fileName
00114 << "because" << pluginLoader.errorString();
00115 }
00116 }
00117
00118 return focusStrategies;
00119 }
00120
00121 bool ControlTest::loadData()
00122 {
00123 taskManagerData->clearTheme();
00124
00125 ui->data->error = false;
00126
00127 ui->data->questionAnswer = true;
00128
00129 ui->data->openFileNames << QCoreApplication::instance()->applicationDirPath() +
00130 "/../../theme.xml";
00131 ui->data->openFileNames << QCoreApplication::instance()->applicationDirPath() +
00132 "/../../data.xml";
00133 control::ControllerInterface* cont = factory->controllerByType(
00134 control::ControllerInterface::FileData,
00135 control::ControllerInterface::LoadDataAction);
00136 cont->run();
00137
00138 Q_ASSERT(taskManagerData->users().size() != 0);
00139
00140 return !ui->data->error;
00141 }
00142
00143 void ControlTest::testSelectUser()
00144 {
00145 controller = factory->controllerByType(control::ControllerInterface::UserData,
00146 control::ControllerInterface::SelectAction);
00147 QVERIFY(controller->name() == "SelectUser");
00148 QVERIFY(controller->description() == "Select user");
00149
00150 domain::UserType* userType =
00151 taskManagerData->createUserType("UserTypeId","UserTypeName");
00152 domain::User* user1 = taskManagerData->createUser(userType, "User1");
00153 domain::User* user2 = taskManagerData->createUser(userType, "User2");
00154 taskManagerData->createUser(userType, "User3");
00155
00156
00157 QVERIFY(ui->user() == 0);
00158 control::data::SelectionData selectionData;
00159 selectionData.processData = false;
00160 ui->data->selectionDataList.append(selectionData);
00161 controller->run();
00162 QVERIFY(ui->user() == 0);
00163
00164
00165 QVERIFY(ui->user() == 0);
00166 selectionData.processData = true;
00167 selectionData.selection.append(
00168 control::UserModel(taskManagerData).indexForUser(user1));
00169 ui->data->selectionDataList.append(selectionData);
00170 controller->run();
00171 QCOMPARE(ui->user(), user1);
00172
00173
00174 QCOMPARE(ui->user(), user1);
00175 selectionData.processData = true;
00176 selectionData.selection.clear();
00177 selectionData.selection.append(
00178 control::UserModel(taskManagerData).indexForUser(user2));
00179 ui->data->selectionDataList.append(selectionData);
00180 controller->run();
00181 QCOMPARE(ui->user(), user2);
00182 }
00183
00184 void ControlTest::testCreateUser()
00185 {
00186 controller = factory->controllerByType(control::ControllerInterface::UserData,
00187 control::ControllerInterface::CreateAction);
00188 QVERIFY(controller->name() == "UserCreator");
00189 QVERIFY(controller->description() == "Create user");
00190
00191 controller->run();
00192 QVERIFY(ui->data->error);
00193 ui->data->error = false;
00194
00195 ui->setUser(taskManagerData->adminUser());
00196
00197 controller->run();
00198 QVERIFY(ui->data->error);
00199 ui->data->error = false;
00200
00201 taskManagerData->createUserType("UserTypeId","UserTypeName");
00202
00203
00204 QCOMPARE(taskManagerData->users().size(), 0);
00205 control::data::StringInputData stringInputData;
00206 stringInputData.processData = false;
00207 ui->data->choiceAnswers.append(stringInputData);
00208 controller->run();
00209 QVERIFY(!ui->data->error);
00210 QCOMPARE(taskManagerData->users().size(), 0);
00211
00212
00213 QCOMPARE(taskManagerData->users().size(), 0);
00214 stringInputData.processData = true;
00215 stringInputData.data.append("UserTypeName");
00216 ui->data->choiceAnswers.append(stringInputData);
00217 ui->data->text = "UserName";
00218 controller->run();
00219 QVERIFY(!ui->data->error);
00220 QCOMPARE(taskManagerData->users().size(), 1);
00221 QVERIFY(!taskManagerData->users().first()->isAdmin());
00222 QCOMPARE(taskManagerData->users().first()->name(), QString("UserName"));
00223
00224
00225 ui->data->choiceAnswers.append(stringInputData);
00226 ui->data->text = "UserName";
00227 controller->run();
00228 QVERIFY(ui->data->error);
00229 ui->data->error = false;
00230 QCOMPARE(taskManagerData->users().size(), 1);
00231
00232
00233 ui->data->choiceAnswers.append(stringInputData);
00234 ui->data->text = "UserName2";
00235 controller->run();
00236 QVERIFY(!ui->data->error);
00237 QCOMPARE(taskManagerData->users().size(), 2);
00238 QVERIFY(!taskManagerData->users().first()->isAdmin());
00239 }
00240
00241 void ControlTest::testAdjustClock()
00242 {
00243 controller = factory->controllerByType(control::ControllerInterface::NoData,
00244 control::ControllerInterface::ModifyAction);
00245 QVERIFY(controller->name() == "ClockAdjuster");
00246 QVERIFY(controller->description() == "Adjust clock");
00247
00248
00249 domain::UserType* userType =
00250 taskManagerData->createUserType("UserTypeId","UserTypeName");
00251 domain::User* user = taskManagerData->createUser(userType, "User");
00252
00253
00254 #define clock taskManagerData->clock()
00255 QDateTime time = clock->currentTime();
00256 control::data::DateTimeInputData dateTimeData;
00257
00258 ui->setUser(user);
00259
00260 dateTimeData.processData = true;
00261 dateTimeData.data = time.addSecs(-55);
00262 ui->data->dateInput = dateTimeData;
00263 QCOMPARE(clock->time(), time);
00264 QVERIFY(!ui->data->error);
00265 controller->run();
00266 QVERIFY(!clock->isTicking());
00267 QCOMPARE(clock->time(), time);
00268 QVERIFY(ui->data->error);
00269 ui->data->error = false;
00270
00271
00272 ui->setUser(taskManagerData->adminUser());
00273 dateTimeData.processData = false;
00274 ui->data->dateInput = dateTimeData;
00275 QCOMPARE(clock->time(), time);
00276 QVERIFY(!ui->data->error);
00277 controller->run();
00278 QVERIFY(!clock->isTicking());
00279 QCOMPARE(clock->time(), time);
00280 QVERIFY(!ui->data->error);
00281
00282
00283 dateTimeData.processData = true;
00284 dateTimeData.data = time.addSecs(-55);
00285 ui->data->dateInput = dateTimeData;
00286 QCOMPARE(clock->time(), time);
00287 QVERIFY(!ui->data->error);
00288 controller->run();
00289 QVERIFY(!clock->isTicking());
00290 QCOMPARE(clock->time(), time);
00291 QVERIFY(ui->data->error);
00292 ui->data->error = false;
00293
00294
00295 dateTimeData.processData = true;
00296 dateTimeData.data = time.addSecs(55);
00297 ui->data->dateInput = dateTimeData;
00298 QCOMPARE(clock->time(), time);
00299 QVERIFY(!clock->isTicking());
00300 controller->run();
00301 QVERIFY(!ui->data->error);
00302 QCOMPARE(clock->time(), time.addSecs(55));
00303 QVERIFY(clock->isTicking());
00304
00305 #undef clock
00306 }
00307
00308 void ControlTest::testTaskCreator()
00309 {
00310 controller = factory->controllerByType(control::ControllerInterface::TaskData,
00311 control::ControllerInterface::CreateAction);
00312 QVERIFY(controller->name() == "TaskCreator");
00313 QVERIFY(controller->description() == "Create task");
00314
00315 domain::UserType* userType =
00316 taskManagerData->createUserType("UserTypeId","UserTypeName");
00317 domain::User* user = taskManagerData->createUser(userType, "user1");
00318 ui->setUser(user);
00319
00320
00321 QVERIFY(!ui->data->error);
00322 controller->run();
00323 QCOMPARE(taskManagerData->tasks().size(), 0);
00324 QVERIFY(ui->data->error);
00325 ui->data->error = false;
00326
00327 domain::TaskType* taskType1 =
00328 taskManagerData->createTaskType("TaskTypeId1","TaskTypeName1");
00329 domain::TaskType* taskType2 =
00330 taskManagerData->createTaskType("TaskTypeId2","TaskTypeName2");
00331 taskType2->addPotentialOwner(userType);
00332
00333
00334 QVERIFY(!ui->data->error);
00335 control::data::StringInputData inputData;
00336 inputData.processData = false;
00337 inputData.data = taskType2->name();
00338 inputData.processData = false;
00339 ui->data->choiceAnswers.append(inputData);
00340 controller->run();
00341 QCOMPARE(taskManagerData->tasks().size(), 0);
00342 QVERIFY(!ui->data->error);
00343
00344
00345 QVERIFY(!ui->data->error);
00346 inputData.processData = true;
00347 inputData.data = taskType1->name();
00348 ui->data->choiceAnswers.append(inputData);
00349 controller->run();
00350 QCOMPARE(taskManagerData->tasks().size(), 0);
00351 QVERIFY(ui->data->error);
00352 ui->data->error = false;
00353
00354
00355 inputData.processData = true;
00356 inputData.data = taskType2->name();
00357 ui->data->choiceAnswers.append(inputData);
00358
00359 QDateTime startTime(QDate(2009,10,20),QTime(1,30));
00360 QDateTime endTime(QDate(2009,10,21),QTime(1,30));
00361 domain::Duration duration(600);
00362 domain::Schedule schedule(duration, startTime, endTime);
00363
00364 taskManagerData->clock()->setTime(endTime.addDays(1));
00365
00366 ui->data->taskDetails.processData = true;
00367 ui->data->taskDetails.startTime = startTime;
00368 ui->data->taskDetails.endTime = endTime;
00369 ui->data->taskDetails.duration = duration;
00370
00371 control::data::SelectionData selectedTasks;
00372 selectedTasks.processData = true;
00373 selectedTasks.selection = QModelIndexList();
00374 ui->data->taskDetails.selectedTasks = selectedTasks;
00375
00376 QMap<QString, QVariant> fields;
00377 ui->data->taskDetails.fields = fields;
00378
00379 QVERIFY(!ui->data->error);
00380 controller->run();
00381 QCOMPARE(taskManagerData->tasks().size(), 0);
00382 QVERIFY(ui->data->error);
00383 ui->data->error = false;
00384
00385
00386 inputData.processData = true;
00387 inputData.data = taskType2->name();
00388 ui->data->choiceAnswers.append(inputData);
00389
00390 taskManagerData->clock()->setTime(startTime);
00391
00392 ui->data->taskDetails.processData = true;
00393 ui->data->taskDetails.startTime = startTime;
00394 ui->data->taskDetails.endTime = endTime;
00395 ui->data->taskDetails.duration = duration;
00396
00397 selectedTasks.processData = true;
00398 selectedTasks.selection = QModelIndexList();
00399 ui->data->taskDetails.selectedTasks = selectedTasks;
00400
00401 fields.clear();
00402 ui->data->taskDetails.fields = fields;
00403
00404 controller->run();
00405 QCOMPARE(taskManagerData->tasks().size(), 1);
00406 QVERIFY(!ui->data->error);
00407
00408
00409 domain::Field field;
00410 field.id = "field1";
00411 field.name = "field1";
00412 field.nature = domain::Field::Numerical;
00413 QVERIFY(!field.isValid("test"));
00414 taskType2->addField(field);
00415
00416 inputData.processData = true;
00417 inputData.data = taskType2->name();
00418 ui->data->choiceAnswers.append(inputData);
00419
00420 selectedTasks.processData = true;
00421 selectedTasks.selection = QModelIndexList();
00422 ui->data->taskDetails.selectedTasks = selectedTasks;
00423
00424 fields.clear();
00425 fields.insert("field1", QVariant());
00426 ui->data->taskDetails.fields = fields;
00427
00428 controller->run();
00429 QCOMPARE(taskManagerData->tasks().size(), 1);
00430 QVERIFY(ui->data->error);
00431 ui->data->error = false;
00432
00433
00434 inputData.processData = true;
00435 inputData.data = taskType2->name();
00436 ui->data->choiceAnswers.append(inputData);
00437
00438 selectedTasks.processData = true;
00439 selectedTasks.selection = QModelIndexList();
00440 ui->data->taskDetails.selectedTasks = selectedTasks;
00441
00442 fields.clear();
00443 fields.insert("field1", QVariant("test"));
00444 ui->data->taskDetails.fields = fields;
00445
00446 controller->run();
00447 QCOMPARE(taskManagerData->tasks().size(), 1);
00448 QVERIFY(ui->data->error);
00449 ui->data->error = false;
00450
00451
00452 inputData.processData = true;
00453 inputData.data = taskType2->name();
00454 ui->data->choiceAnswers.append(inputData);
00455
00456 fields.clear();
00457 fields.insert("field1", QVariant("0928"));
00458 ui->data->taskDetails.fields = fields;
00459
00460 controller->run();
00461 QCOMPARE(taskManagerData->tasks().size(), 2);
00462 QVERIFY(!ui->data->error);
00463
00464 inputData.processData = true;
00465 inputData.data = taskType2->name();
00466 ui->data->choiceAnswers.append(inputData);
00467
00468 fields.clear();
00469 fields.insert("field1", QVariant(14425));
00470 ui->data->taskDetails.fields = fields;
00471
00472 controller->run();
00473 QCOMPARE(taskManagerData->tasks().size(), 3);
00474 QVERIFY(!ui->data->error);
00475
00476
00477 domain::Project* project = taskManagerData->createProject("project1");
00478 domain::Task* task =
00479 taskManagerData->createTask(taskType2, user, schedule);
00480
00481 selectedTasks.processData = true;
00482 ui->data->taskDetails.selectedTasks.processData = true;
00483 ui->data->taskDetails.selectedTasks.selection.clear();
00484 ui->data->taskDetails.selectedTasks.selection.
00485 append(control::TaskModel(taskManagerData).indexForTask(task));
00486
00487 inputData.processData = true;
00488 inputData.data = taskType2->name();
00489 ui->data->choiceAnswers.append(inputData);
00490
00491 inputData.processData = true;
00492 inputData.data = project->description();
00493 ui->data->choiceAnswers.append(inputData);
00494
00495 QList<const domain::Task*> tasks = tools::makeConstList(taskManagerData->tasks());
00496 QCOMPARE(task->allSuperTasks().size(), 0);
00497 controller->run();
00498 QCOMPARE(task->allSuperTasks().size(), 1);
00499 QVERIFY(!tasks.contains(task->allSuperTasks().first()));
00500 QVERIFY(!ui->data->error);
00501 }
00502
00503 void ControlTest::testTaskModifier()
00504 {
00505
00506 controller = factory->controllerByType(control::ControllerInterface::TaskData,
00507 control::ControllerInterface::ModifyAction);
00508 QVERIFY(controller->name() == "TaskModifier");
00509 QVERIFY(controller->description() == "Modify task");
00510
00511
00512 domain::UserType* userType = taskManagerData->createUserType("testUserType","test");
00513 domain::User* user = taskManagerData->createUser(userType, "test");
00514 ui->setUser(user);
00515
00516 QVERIFY(!ui->data->warning);
00517 controller->run();
00518 QVERIFY(ui->data->warning);
00519 ui->data->warning = false;
00520
00521
00522 QDateTime startTime(QDate(2009,10,20),QTime(1,30));
00523 QDateTime endTime(QDate(2009,10,21),QTime(1,30));
00524 domain::Duration duration(600);
00525 domain::Schedule schedule(duration, startTime, endTime);
00526
00527 domain::TaskType* taskType = taskManagerData->createTaskType("testTaskType","test");
00528 taskType->addPotentialOwner(userType);
00529 domain::Task* task = taskManagerData->
00530 createTask(taskType, user, schedule, domain::TaskState::Successful);
00531
00532 control::data::SelectionData selectionData;
00533 selectionData.processData = true;
00534 QList<const domain::Task*> tasksList =
00535 tools::makeConstList(taskManagerData->tasksForUser(user));
00536 selectionData.selection.append(
00537 (control::TaskModel(taskManagerData, tasksList)).indexForTask(task));
00538 ui->data->selectionDataList.append(selectionData);
00539
00540 QVERIFY(!ui->data->error);
00541 QCOMPARE(task->state(), domain::TaskState::Successful);
00542 controller->run();
00543 QVERIFY(ui->data->error);
00544 ui->data->error = false;
00545
00546
00547 task->setState(domain::TaskState::Failed);
00548 QCOMPARE(task->state(), domain::TaskState::Failed);
00549 ui->data->selectionDataList.append(selectionData);
00550 QVERIFY(!ui->data->error);
00551 controller->run();
00552 QVERIFY(ui->data->error);
00553 ui->data->error = false;
00554
00555
00556 task->setState(domain::TaskState::Unfinished);
00557 QCOMPARE(task->state(), domain::TaskState::Unfinished);
00558 ui->data->selectionDataList.append(selectionData);
00559
00560 ui->data->taskDetails.processData = true;
00561 ui->data->taskDetails.duration = task->schedule().duration();
00562 ui->data->taskDetails.startTime = task->schedule().startDate().addDays(1);
00563 ui->data->taskDetails.endTime = task->schedule().dueDate().addDays(1);
00564
00565 domain::Task* subTask = taskManagerData->createTask(taskType, user, schedule);
00566 QList<const domain::Task*> taskList =
00567 tools::makeConstList(taskManagerData->tasksForUser(user));
00568 taskList.removeAll(task);
00569 control::TaskModel(taskManagerData, taskList).indexForTask(subTask);
00570 ui->data->taskDetails.selectedTasks.processData = true;
00571 ui->data->taskDetails.selectedTasks.selection.append(
00572 (control::TaskModel(taskManagerData, taskList)).indexForTask(subTask));
00573
00574 ui->data->taskDetails.fields = task->fields();
00575
00576 QVERIFY(!ui->data->error);
00577 QCOMPARE(taskManagerData->tasks().size(), 2);
00578 controller->run();
00579 QVERIFY(!ui->data->error);
00580 QCOMPARE(taskManagerData->tasks().size(), 2);
00581
00582 QList<domain::Task*> tasks = taskManagerData->tasks();
00583 tasks.removeAll(subTask);
00584 domain::Task* taskToCheck = tasks.first();
00585
00586 QCOMPARE(taskToCheck->schedule().duration(), ui->data->taskDetails.duration);
00587 QCOMPARE(taskToCheck->schedule().startDate(), ui->data->taskDetails.startTime);
00588 QCOMPARE(taskToCheck->schedule().dueDate(), ui->data->taskDetails.endTime);
00589 QCOMPARE(taskToCheck->schedule().duration(), ui->data->taskDetails.duration);
00590 QCOMPARE(taskToCheck->fields(), ui->data->taskDetails.fields);
00591 QCOMPARE(taskToCheck->subTasks().size(), 1);
00592 QVERIFY(taskToCheck->subTasks().contains(subTask));
00593
00594 task = taskToCheck;
00595
00596
00597 QCOMPARE(task->state(), domain::TaskState::Unfinished);
00598
00599 selectionData.selection.clear();
00600 tasksList = tools::makeConstList(taskManagerData->tasksForUser(user));
00601 selectionData.selection.append(
00602 (control::TaskModel(taskManagerData, tasksList)).indexForTask(task));
00603 ui->data->selectionDataList.append(selectionData);
00604
00605 ui->data->taskDetails.processData = true;
00606 ui->data->taskDetails.duration = task->schedule().duration();
00607 ui->data->taskDetails.startTime = task->schedule().startDate();
00608 ui->data->taskDetails.endTime = task->schedule().dueDate();
00609
00610 ui->data->taskDetails.selectedTasks.processData = true;
00611 ui->data->taskDetails.selectedTasks.selection.clear();
00612
00613 domain::Field field;
00614 field.name = "fieldName";
00615 field.id = "fieldId";
00616 field.nature = domain::Field::Numerical;
00617 taskType->addField(field);
00618 task->setField(field.id, QVariant(1234));
00619
00620 QMap<QString, QVariant> map;
00621 map[QString("fieldId")] = QVariant(500);
00622 ui->data->taskDetails.fields = map;
00623
00624 QVERIFY(!ui->data->error);
00625 QCOMPARE(taskManagerData->tasks().size(), 2);
00626 controller->run();
00627 QVERIFY(!ui->data->error);
00628 QCOMPARE(taskManagerData->tasks().size(), 2);
00629
00630 tasks = taskManagerData->tasks();
00631 tasks.removeAll(subTask);
00632 taskToCheck = tasks.first();
00633
00634 QCOMPARE(taskToCheck->schedule().duration(), ui->data->taskDetails.duration);
00635 QCOMPARE(taskToCheck->schedule().startDate(), ui->data->taskDetails.startTime);
00636 QCOMPARE(taskToCheck->schedule().dueDate(), ui->data->taskDetails.endTime);
00637 QCOMPARE(taskToCheck->schedule().duration(), ui->data->taskDetails.duration);
00638 QCOMPARE(taskToCheck->fields(), ui->data->taskDetails.fields);
00639 QVERIFY(taskToCheck->subTasks().isEmpty());
00640
00641 task = taskToCheck;
00642 }
00643
00644 void ControlTest::testTaskUpdater()
00645 {
00646 loadData();
00647
00648 controller = factory->controllerByType(control::ControllerInterface::TaskData,
00649 control::ControllerInterface::UpdateAction);
00650
00651 QVERIFY(controller->name() == "TaskUpdater");
00652 QVERIFY(controller->description() == "Update task");
00653
00654
00655 control::data::SelectionData selectionData;
00656
00657
00658 domain::Task* taskToUpdate = taskManagerData->tasks().at(0);
00659 QList<const domain::Task*> superTasks = taskToUpdate->allSuperTasks();
00660
00661 QVERIFY(superTasks.size() != 0);
00662 domain::TaskState::SettableState oldTaskState = taskToUpdate->state();
00663 QModelIndexList indexList;
00664 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToUpdate));
00665 selectionData.selection = indexList;
00666 selectionData.processData = true;
00667 ui->data->selectionCounter = 0;
00668 ui->data->selectionDataList.append(selectionData);
00669 ui->setUser(taskToUpdate->user());
00670
00671
00672 control::data::StringInputData unfinished;
00673 unfinished.processData = true;
00674 unfinished.data = "Unfinished";
00675 ui->data->choiceAnswers.append(unfinished);
00676
00677
00678 int beforeTaskCount = taskManagerData->tasks().size();
00679 control::data::StringInputData inputData;
00680 inputData.processData = true;
00681 ui->data->taskDetailsAnswer.append(inputData);
00682
00683 QVERIFY(!ui->data->error);
00684 controller->run();
00685 QVERIFY(ui->data->error);
00686 int afterTaskCount = taskManagerData->tasks().size();
00687 QVERIFY(beforeTaskCount == afterTaskCount);
00688 QVERIFY(oldTaskState == taskToUpdate->state());
00689
00690
00691 taskToUpdate = taskManagerData->tasks().at(4);
00692 oldTaskState = taskToUpdate->state();
00693 indexList.clear();
00694 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToUpdate));
00695 ui->data->selectionCounter = 0;
00696 ui->data->choiceCounter = 0;
00697 ui->data->selectionDataList.clear();
00698 ui->data->choiceAnswers.clear();
00699 selectionData.selection = indexList;
00700 selectionData.processData = true;
00701 ui->data->selectionDataList.append(selectionData);
00702 ui->data->error = false;
00703 ui->data->model = false;
00704
00705
00706 control::data::StringInputData successful;
00707 successful.processData = true;
00708 successful.data = "Successful";
00709 ui->data->choiceAnswers.append(successful);
00710
00711
00712 beforeTaskCount = taskManagerData->tasks().size();
00713 ui->data->taskDetailsAnswer.append(inputData);
00714 QVERIFY(!ui->data->error);
00715 QVERIFY(!ui->data->model);
00716 controller->run();
00717 QVERIFY(!ui->data->error);
00718 QVERIFY(ui->data->model);
00719 afterTaskCount = taskManagerData->tasks().size();
00720 QVERIFY(beforeTaskCount == afterTaskCount);
00721 QVERIFY(oldTaskState == taskToUpdate->state());
00722
00723
00724 taskToUpdate = taskManagerData->tasks().at(2);
00725 indexList.clear();
00726 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToUpdate));
00727 ui->data->selectionCounter = 0;
00728 ui->data->choiceCounter = 0;
00729 ui->data->selectionDataList.clear();
00730 ui->data->choiceAnswers.clear();
00731 selectionData.selection = indexList;
00732 selectionData.processData = true;
00733 ui->data->selectionDataList.append(selectionData);
00734 ui->data->error = false;
00735 ui->data->model = false;
00736
00737
00738 ui->data->choiceAnswers.append(unfinished);
00739
00740
00741 beforeTaskCount = taskManagerData->tasks().size();
00742 ui->data->taskDetailsAnswer.append(inputData);
00743 QVERIFY(!ui->data->error);
00744 QVERIFY(!ui->data->model);
00745 controller->run();
00746 QVERIFY(!ui->data->error);
00747 QVERIFY(!ui->data->model);
00748 afterTaskCount = taskManagerData->tasks().size();
00749 QVERIFY(beforeTaskCount == afterTaskCount);
00750 QVERIFY(domain::TaskState::Unfinished == taskToUpdate->state());
00751
00752
00753
00754 taskToUpdate = taskManagerData->tasks().at(0);
00755 oldTaskState = taskToUpdate->state();
00756 indexList.clear();
00757 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToUpdate));
00758 ui->data->selectionCounter = 0;
00759 ui->data->choiceCounter = 0;
00760 ui->data->selectionDataList.clear();
00761 ui->data->choiceAnswers.clear();
00762 selectionData.selection = indexList;
00763 selectionData.processData = true;
00764 ui->data->selectionDataList.append(selectionData);
00765 ui->data->error = false;
00766 ui->data->model = false;
00767 ui->data->questionAnswer = false;
00768
00769
00770 control::data::StringInputData failed;
00771 failed.processData = true;
00772 failed.data = "Failed";
00773 ui->data->choiceAnswers.append(failed);
00774
00775
00776 beforeTaskCount = taskManagerData->tasks().size();
00777 ui->data->taskDetailsAnswer.append(inputData);
00778 QVERIFY(!ui->data->error);
00779 QVERIFY(!ui->data->model);
00780 QVERIFY(!ui->data->questionAsked);
00781 controller->run();
00782 QVERIFY(!ui->data->error);
00783 QVERIFY(!ui->data->model);
00784 QVERIFY(ui->data->questionAsked);
00785 afterTaskCount = taskManagerData->tasks().size();
00786 QVERIFY(oldTaskState == taskToUpdate->state());
00787 QVERIFY(afterTaskCount == beforeTaskCount);
00788
00789
00790
00791 taskToUpdate = taskManagerData->tasks().at(0);
00792 indexList.clear();
00793 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToUpdate));
00794 ui->data->selectionCounter = 0;
00795 ui->data->choiceCounter = 0;
00796 ui->data->selectionDataList.clear();
00797 ui->data->choiceAnswers.clear();
00798 selectionData.selection = indexList;
00799 selectionData.processData = true;
00800 ui->data->selectionDataList.append(selectionData);
00801 ui->data->error = false;
00802 ui->data->model = false;
00803 ui->data->questionAsked = false;
00804 ui->data->questionAnswer = true;
00805
00806
00807 ui->data->choiceAnswers.append(failed);
00808
00809
00810 beforeTaskCount = taskManagerData->tasks().size();
00811 ui->data->taskDetailsAnswer.append(inputData);
00812 QVERIFY(!ui->data->error);
00813 QVERIFY(!ui->data->model);
00814 QVERIFY(!ui->data->questionAsked);
00815 controller->run();
00816 QVERIFY(!ui->data->error);
00817 QVERIFY(!ui->data->model);
00818 QVERIFY(ui->data->questionAsked);
00819 afterTaskCount = taskManagerData->tasks().size();
00820 QVERIFY(beforeTaskCount == afterTaskCount);
00821 QVERIFY(domain::TaskState::Failed == taskToUpdate->state());
00822 Q_FOREACH (const domain::Task* task, taskToUpdate->allSuperTasks()) {
00823 QVERIFY(domain::TaskState::Failed == task->state());
00824 }
00825 }
00826
00827 void ControlTest::testTaskRemover()
00828 {
00829 controller = factory->controllerByType(control::ControllerInterface::TaskData,
00830 control::ControllerInterface::RemoveAction);
00831
00832 QVERIFY(controller->name() == "TaskRemover");
00833 QVERIFY(controller->description() == "Remove task");
00834
00835 controller->run();
00836 QVERIFY(ui->data->error);
00837 ui->data->error = false;
00838
00839 loadData();
00840 QVERIFY(taskManagerData->tasks().size() != 0);
00841
00842
00843 control::data::SelectionData selectionData;
00844
00845
00846 domain::Task* taskToRemove = taskManagerData->tasks().at(0);
00847 domain::Schedule oldTaskSchedule = taskToRemove->schedule();
00848 const domain::User* oldTaskUser = taskToRemove->user();
00849 QMap<QString, QVariant> oldTaskFields = taskToRemove->fields();
00850 QList<const domain::Task*> superTasks = taskToRemove->allSuperTasks();
00851
00852 int nbOfSuperTasks = superTasks.size();
00853 QVERIFY(nbOfSuperTasks != 0);
00854 QModelIndexList indexList;
00855 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToRemove));
00856 selectionData.selection = indexList;
00857 selectionData.processData = true;
00858 ui->data->selectionDataList.append(selectionData);
00859 ui->setUser(taskToRemove->user());
00860
00861 ui->data->questionAnswer = true;
00862
00863
00864 int beforeTaskCount = taskManagerData->tasks().size();
00865 QVERIFY(!ui->data->error);
00866 QVERIFY(!ui->data->questionAsked);
00867 controller->run();
00868 QVERIFY(!ui->data->error);
00869 QVERIFY(ui->data->questionAsked);
00870 int afterTaskCount = taskManagerData->tasks().size();
00871
00872
00873 bool taskPresent = false;
00874 Q_FOREACH (domain::Task* tmpTask, taskManagerData->tasks())
00875 {
00876 if (tmpTask->user() != oldTaskUser)
00877 continue;
00878 if (!(tmpTask->schedule() == oldTaskSchedule))
00879 continue;
00880 if (!(tmpTask->fields() == oldTaskFields))
00881 continue;
00882
00883 taskPresent = true;
00884 }
00885 QVERIFY(beforeTaskCount - afterTaskCount == 1 + nbOfSuperTasks);
00886 QVERIFY(!taskPresent);
00887
00888
00889 loadData();
00890 taskToRemove = taskManagerData->tasks().at(1);
00891 oldTaskSchedule = taskToRemove->schedule();
00892 oldTaskUser = taskToRemove->user();
00893 superTasks = taskToRemove->allSuperTasks();
00894
00895 QVERIFY(superTasks.size() != 0);
00896 indexList.clear();
00897 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToRemove));
00898 selectionData.selection = indexList;
00899 selectionData.processData = true;
00900 ui->data->selectionDataList.clear();
00901 ui->data->selectionDataList.append(selectionData);
00902 ui->data->selectionCounter = 0;
00903 ui->setUser(taskToRemove->user());
00904
00905 ui->data->questionAnswer = false;
00906 ui->data->questionAsked = false;
00907
00908
00909 beforeTaskCount = taskManagerData->tasks().size();
00910 QVERIFY(!ui->data->error);
00911 QVERIFY(!ui->data->questionAsked);
00912 controller->run();
00913 QVERIFY(!ui->data->error);
00914 QVERIFY(ui->data->questionAsked);
00915 afterTaskCount = taskManagerData->tasks().size();
00916
00917
00918 taskPresent = false;
00919 Q_FOREACH (domain::Task* tmpTask, taskManagerData->tasks())
00920 {
00921 if (tmpTask->user() != oldTaskUser)
00922 continue;
00923 if (!(tmpTask->schedule() == oldTaskSchedule))
00924 continue;
00925 if (!(tmpTask->fields() == oldTaskFields))
00926 continue;
00927 taskPresent = true;
00928 }
00929 QVERIFY(beforeTaskCount - afterTaskCount == 1);
00930 QVERIFY(!taskPresent);
00931
00932
00933 loadData();
00934 taskToRemove = taskManagerData->tasks().at(4);
00935 oldTaskSchedule = taskToRemove->schedule();
00936 oldTaskUser = taskToRemove->user();
00937 superTasks = taskToRemove->allSuperTasks();
00938
00939 QVERIFY(superTasks.size() == 0);
00940 indexList.clear();
00941 indexList.append(control::TaskModel(taskManagerData).indexForTask(taskToRemove));
00942 selectionData.selection = indexList;
00943 selectionData.processData = true;
00944 ui->data->selectionDataList.clear();
00945 ui->data->selectionDataList.append(selectionData);
00946 ui->data->selectionCounter = 0;
00947 ui->setUser(taskToRemove->user());
00948
00949 ui->data->questionAnswer = false;
00950 ui->data->questionAsked = false;
00951
00952
00953 beforeTaskCount = taskManagerData->tasks().size();
00954 QVERIFY(!ui->data->error);
00955 QVERIFY(!ui->data->questionAsked);
00956 controller->run();
00957 QVERIFY(!ui->data->error);
00958 QVERIFY(!ui->data->questionAsked);
00959 afterTaskCount = taskManagerData->tasks().size();
00960
00961
00962 taskPresent = false;
00963 Q_FOREACH (domain::Task* tmpTask, taskManagerData->tasks())
00964 {
00965 if (tmpTask->user() != oldTaskUser)
00966 continue;
00967 if (!(tmpTask->schedule() == oldTaskSchedule))
00968 continue;
00969 if (!(tmpTask->fields() == oldTaskFields))
00970 continue;
00971 taskPresent = true;
00972 }
00973 QVERIFY(beforeTaskCount - afterTaskCount == 1);
00974 QVERIFY(!taskPresent);
00975 }
00976
00977 void ControlTest::testTaskWorker()
00978 {
00979 controller = factory->controllerByType(control::ControllerInterface::NoData,
00980 control::ControllerInterface::CustomAction);
00981 QVERIFY(controller->name() == "TaskWorker");
00982 QVERIFY(controller->description() == "Focus work");
00983 QVERIFY(loadData());
00984
00985
00986 domain::User* user = taskManagerData->users().first();
00987 ui->setUser(user);
00988
00989
00990 control::data::StringInputData inputData;
00991 inputData.processData = true;
00992 inputData.data = "Duration-based focus";
00993 ui->data->choiceAnswers.append(inputData);
00994
00995 control::data::MinMaxDurationData minMaxData;
00996 minMaxData.minDurationSet = false;
00997 minMaxData.maxDurationSet = true;
00998 minMaxData.processData = true;
00999
01000 domain::Duration duration(604800);
01001 minMaxData.maxDuration = duration;
01002 ui->data->minMaxDurationData = minMaxData;
01003
01004
01005 control::data::SelectionData selectionData;
01006 selectionData.processData = true;
01007 ui->data->selectionDataList.append(selectionData);
01008
01009 QVERIFY(user->tasks().size() > 0);
01010 QVERIFY(!ui->data->warning);
01011 controller->run();
01012 QVERIFY(ui->data->warning);
01013 ui->data->warning = false;
01014
01015
01016 ui->data->choiceAnswers.append(inputData);
01017 ui->data->minMaxDurationData = minMaxData;
01018
01019 QList<domain::Task*> tasks = taskManagerData->tasksForUser(user);
01020 Q_FOREACH (const domain::Invitation* inv, user->invitations())
01021 tasks << taskManagerData->task(inv->task());
01022
01023 QMap<QString, control::FocusInterface*> focusMap;
01024 Q_FOREACH(control::FocusInterface* focus, getfocusStrategies(ui))
01025 focusMap[focus->description()] = focus;
01026
01027 QVERIFY(focusMap["Duration-based focus"]->applyFocus(&tasks));
01028 control::TaskModel model(taskManagerData, tools::makeConstList(tasks));
01029
01030 selectionData.selection.clear();
01031 selectionData.selection.append(model.indexForTask(tasks.first()));
01032 ui->data->selectionDataList.append(selectionData);
01033
01034
01035
01036 inputData.processData = true;
01037 inputData.data = "Modify task details";
01038 ui->data->taskDetailsAnswer.append(inputData);
01039 QList<domain::Task*> oldTasks = taskManagerData->tasks();
01040
01041
01042 const domain::Task* oldTask = model.taskForIndex(
01043 selectionData.selection.first());
01044 control::data::TaskDetails taskDetails(oldTask);
01045 taskDetails.processData = true;
01046 ui->data->taskDetails = taskDetails;
01047
01048
01049 QVERIFY(!ui->data->warning);
01050 QVERIFY(!ui->data->error);
01051 controller->run();
01052 QVERIFY(!ui->data->warning);
01053 QVERIFY(!ui->data->error);
01054
01055 bool oldTaskFound = false, newTaskFound = false;
01056 Q_FOREACH(domain::Task* task, taskManagerData->tasks())
01057 {
01058 if (!oldTasks.contains(task))
01059 {
01060 if (newTaskFound)
01061 QVERIFY(false);
01062 else
01063 {
01064 newTaskFound = true;
01065 }
01066 }
01067 }
01068 Q_FOREACH (domain::Task* task, taskManagerData->tasks())
01069 {
01070 if (task == oldTask)
01071 oldTaskFound = true;
01072 }
01073 QVERIFY(!oldTaskFound);
01074 QVERIFY(newTaskFound);
01075
01076
01077 oldTask = taskManagerData->tasks().at(1);
01078 selectionData.selection.clear();
01079 selectionData.selection.append(
01080 control::TaskModel(taskManagerData).indexForTask(oldTask));
01081 selectionData.processData = true;
01082 ui->data->selectionDataList.append(selectionData);
01083 inputData.processData = true;
01084 inputData.data = "Duration-based focus";
01085 ui->data->choiceAnswers.append(inputData);
01086
01087 inputData.processData = false;
01088 inputData.data = "";
01089 ui->data->taskDetailsAnswer.append(inputData);
01090 inputData.processData = true;
01091
01092
01093 inputData.data = "Successful";
01094 ui->data->choiceAnswers.append(inputData);
01095 ui->setUser(oldTask->user());
01096
01097
01098 inputData.data = "Update task status";
01099 ui->data->taskDetailsAnswer.append(inputData);
01100
01101 QVERIFY(!ui->data->warning);
01102 controller->run();
01103 QVERIFY(!ui->data->warning);
01104 QVERIFY(oldTask->state() == domain::TaskState::Successful);
01105
01106
01107 ui->data->choiceAnswers.clear();
01108 ui->data->choiceCounter = 0;
01109 ui->data->taskDetailsAnswer.clear();
01110 ui->data->taskDetailsAnswerCounter = 0;
01111 inputData.data = "Duration-based focus";
01112 ui->data->choiceAnswers.append(inputData);
01113
01114 oldTask = taskManagerData->tasks().at(1);
01115
01116 selectionData.selection.clear();
01117 selectionData.selection.append(
01118 control::TaskModel(taskManagerData).indexForTask(oldTask));
01119 selectionData.processData = true;
01120 ui->data->selectionDataList.append(selectionData);
01121
01122
01123 inputData.data = "Change focus";
01124 ui->data->taskDetailsAnswer.append(inputData);
01125 inputData.data = "Duration-based focus";
01126 ui->data->choiceAnswers.append(inputData);
01127
01128 selectionData.selection.clear();
01129 selectionData.processData = true;
01130 ui->data->selectionDataList.append(selectionData);
01131
01132 inputData.processData = false;
01133 ui->data->taskDetailsAnswer.append(inputData);
01134
01135 QVERIFY(!ui->data->warning);
01136 QVERIFY(!ui->data->error);
01137 controller->run();
01138 QVERIFY(ui->data->warning);
01139 QVERIFY(!ui->data->error);
01140 }
01141
01142 void ControlTest::testProjectCreator()
01143 {
01144 loadData();
01145
01146
01147 controller = factory->controllerByType(control::ControllerInterface::ProjectData,
01148 control::ControllerInterface::CreateAction);
01149
01150 ui->setUser(taskManagerData->users().first());
01151 QVERIFY(controller->name() == "ProjectCreator");
01152 QVERIFY(controller->description() == "Create project");
01153 domain::Project* project = taskManagerData->projects().first();
01154 const QString description = project->description();
01155 QList<domain::Project*> initialProject = taskManagerData->projects();
01156
01157 ui->data->projectDetails.description = project->description();
01158 ui->data->projectDetails.processData = true;
01159
01160
01161
01162 ui->data->projectDetails.description = "";
01163 QVERIFY(!ui->data->error);
01164 controller->run();
01165 QList<domain::Project*> newProjects = taskManagerData->projects();
01166 QVERIFY(ui->data->error);
01167 QVERIFY(initialProject == newProjects);
01168
01169
01170 ui->data->error = false;
01171 ui->data->projectDetails.description = "foo";
01172 bool contains = false;
01173
01174 Q_FOREACH (domain::Project* project, taskManagerData->projects())
01175 {
01176 if (project->description() == ui->data->projectDetails.description)
01177 contains = true;
01178 }
01179 QVERIFY(!contains);
01180 controller->run();
01181 QVERIFY(!ui->data->error);
01182 newProjects = taskManagerData->projects();
01183 QVERIFY(initialProject != newProjects);
01184 Q_FOREACH (domain::Project* project, taskManagerData->projects())
01185 {
01186 if (project->description() == ui->data->projectDetails.description)
01187 contains = true;
01188 }
01189 QVERIFY(contains);
01190 }
01191
01192 void ControlTest::testProjectAssigner()
01193 {
01194 loadData();
01195 ui->setUser(taskManagerData->users().first());
01196
01197 controller = factory->controllerByType(control::ControllerInterface::ProjectData,
01198 control::ControllerInterface::AssignAction);
01199
01200 QVERIFY(controller->name() == "ProjectAssigner");
01201 QVERIFY(controller->description() == "Assign task to project");
01202
01203 control::data::SelectionData selectionData;
01204 selectionData.processData = true;
01205 control::data::SelectionData selectionData2;
01206 selectionData2.processData = true;
01207
01208
01209 domain::Task* selectedTask = taskManagerData->tasks().first();
01210 const domain::Project* oldProject = selectedTask->project();
01211 domain::Project* newProject = taskManagerData->projects().first();
01212 QList<const domain::Task*> tasksOfNewProject = newProject->tasks();
01213
01214 QModelIndexList indexList;
01215 indexList.append(control::TaskModel(taskManagerData).indexForTask(selectedTask));
01216 selectionData.selection = indexList;
01217 ui->data->selectionDataList.append(selectionData);
01218 QModelIndexList indexList2;
01219 indexList2.append(control::ProjectModel(taskManagerData).indexForProject(newProject));
01220 selectionData2.selection = indexList2;
01221 ui->data->selectionDataList.append(selectionData2);
01222 QVERIFY(selectedTask->project() == oldProject);
01223 ui->data->error = false;
01224 controller->run();
01225 QVERIFY(!ui->data->error);
01226 QVERIFY(selectedTask->project() == oldProject);
01227 QVERIFY(oldProject == newProject);
01228
01229
01230 selectedTask = taskManagerData->tasks().first();
01231 oldProject = selectedTask->project();
01232 newProject = taskManagerData->createProject("foo");
01233 tasksOfNewProject = newProject->tasks();
01234
01235 ui->data->selectionCounter = 0;
01236 ui->data->selectionDataList.clear();
01237 indexList.clear();
01238 indexList.append(control::TaskModel(taskManagerData).indexForTask(selectedTask));
01239 selectionData.selection = indexList;
01240 ui->data->selectionDataList.append(selectionData);
01241 indexList2.clear();
01242 indexList2.append(control::ProjectModel(taskManagerData).indexForProject(newProject));
01243 selectionData2.selection = indexList2;
01244 ui->data->selectionDataList.append(selectionData2);
01245 ui->data->error = false;
01246 QVERIFY(selectedTask->project() == oldProject);
01247 controller->run();
01248 QVERIFY(!ui->data->error);
01249 QVERIFY(selectedTask->project() == newProject);
01250 QVERIFY(!(oldProject == newProject));
01251 }
01252
01253 void ControlTest::testProjectRemover()
01254 {
01255 loadData();
01256
01257 controller = factory->controllerByType(control::ControllerInterface::ProjectData,
01258 control::ControllerInterface::RemoveAction);
01259 QVERIFY(controller->name() == "ProjectRemover");
01260 QVERIFY(controller->description() == "Remove project");
01261
01262
01263 ui->data->error = false;
01264 controller->run();
01265 QVERIFY(ui->data->error);
01266
01267
01268 ui->setUser(taskManagerData->adminUser());
01269 ui->data->error = false;
01270 controller->run();
01271 QVERIFY(ui->data->error);
01272
01273
01274 ui->setUser(taskManagerData->users().first());
01275
01276
01277 control::data::SelectionData selectionData;
01278 ui->data->selectionDataList.append(selectionData);
01279 ui->data->selectionDataList.first().processData = true;
01280
01281
01282 domain::Project* projectToRemove = taskManagerData->projects().first();
01283 QString oldProjectDescription = projectToRemove->description();
01284 QList<const domain::Task*> constTasksOfProject = projectToRemove->tasks();
01285 QList<domain::Task*> tasksOfProject = QList<domain::Task*>();
01286 Q_FOREACH (const domain::Task* constTask, constTasksOfProject)
01287 {
01288 tasksOfProject << taskManagerData->task(constTask);
01289 }
01290 QModelIndexList indexList;
01291 indexList.append(control::ProjectModel(taskManagerData).indexForProject(projectToRemove));
01292 ui->data->selectionDataList.first().selection = indexList;
01293
01294
01295 int beforeProjectCount = taskManagerData->projects().size();
01296 int beforeTaskCount = taskManagerData->tasks().size();
01297 ui->data->error = false;
01298 controller->run();
01299 QVERIFY(!ui->data->error);
01300 int afterProjectCount = taskManagerData->projects().size();
01301 int afterTaskCount = taskManagerData->tasks().size();
01302
01303 QVERIFY(!taskManagerData->projects().contains(projectToRemove));
01304 QVERIFY(beforeProjectCount - afterProjectCount == 1);
01305
01306
01307 Q_FOREACH (domain::Task* taskRemoved, tasksOfProject) {
01308 QVERIFY(!taskManagerData->tasks().contains(taskRemoved));
01309 }
01310 QVERIFY(beforeTaskCount - afterTaskCount == tasksOfProject.size());
01311 }
01312
01313 void ControlTest::testResourceCreator()
01314 {
01315 loadData();
01316
01317
01318 controller = factory->controllerByType(control::ControllerInterface::ResourceData,
01319 control::ControllerInterface::CreateAction);
01320 QVERIFY(controller->name() == "ResourceCreator");
01321 QVERIFY(controller->description() == "Create Resource");
01322 domain::Resource* resource = taskManagerData->resources().first();
01323 const QString description = resource->description();
01324 QList<domain::Resource*> initialResources = taskManagerData->resources();
01325 ui->data->resourceDetails.description = resource->description();
01326 ui->data->resourceDetails.type = resource->resourceType()->id();
01327 ui->data->resourceDetails.processData = true;
01328
01329
01330
01331 ui->setUser(taskManagerData->adminUser());
01332 ui->data->error = false;
01333 controller->run();
01334 QVERIFY(ui->data->error);
01335
01336
01337 ui->setUser(taskManagerData->users().first());
01338
01339
01340 ui->data->error = false;
01341 ui->data->resourceDetails.description = "";
01342 QVERIFY(!ui->data->error);
01343 controller->run();
01344 QList<domain::Resource*> newResources = taskManagerData->resources();
01345 QVERIFY(ui->data->error);
01346 QVERIFY(initialResources == newResources);
01347
01348
01349 ui->data->error = false;
01350 ui->data->resourceDetails.description = "foo";
01351 ui->data->resourceDetails.type =
01352 taskManagerData->resourceTypes().first()->name();
01353 bool contains = false;
01354
01355 int count = taskManagerData->resources().size();
01356 QVERIFY(!contains);
01357 controller->run();
01358 QVERIFY(!ui->data->error);
01359 newResources = taskManagerData->resources();
01360 QVERIFY(initialResources != newResources);
01361 Q_FOREACH (domain::Resource* resource, taskManagerData->resources())
01362 {
01363 if (resource->description() == ui->data->resourceDetails.description &&
01364 resource->resourceType()->id() ==
01365 taskManagerData->resourceTypes().first()->name())
01366 {
01367 contains = true;
01368 }
01369 }
01370 QVERIFY(taskManagerData->resources().size() == count + 1);
01371 QVERIFY(contains);
01372 }
01373
01374 void ControlTest::testResourceReservationMaker()
01375 {
01376 loadData();
01377
01378 controller = factory->controllerByType(control::ControllerInterface::ReservationData,
01379 control::ControllerInterface::CreateAction);
01380 QVERIFY(controller->name() == "ResourceReservationMaker");
01381 QVERIFY(controller->description() == "Make resource reservation");
01382
01383
01384 ui->data->error = false;
01385 controller->run();
01386 QVERIFY(ui->data->error);
01387
01388
01389 ui->setUser(taskManagerData->adminUser());
01390 ui->data->error = false;
01391 controller->run();
01392 QVERIFY(ui->data->error);
01393
01394
01395 domain::User* user1 = taskManagerData->users().at(1);
01396 ui->setUser(user1);
01397 ui->data->warning = false;
01398 controller->run();
01399 QVERIFY(user1->tasks().isEmpty());
01400 QVERIFY(ui->data->warning);
01401
01402
01403 domain::User* user2 = taskManagerData->users().first();
01404 ui->setUser(user2);
01405 QList<domain::Task*> tasksToShow;
01406 Q_FOREACH (domain::Task* task, taskManagerData->tasksForUser(user2))
01407 {
01408 if (task->state() == domain::TaskState::Unfinished)
01409 tasksToShow << task;
01410 }
01411 QVERIFY(!tasksToShow.isEmpty());
01412
01413
01414 domain::Resource* resourceToReserve = taskManagerData->resources().at(4);
01415 QCOMPARE(resourceToReserve->resourceTypeName(), QString("caffeine"));
01416 QList<const domain::Reservation*> oldReservations = resourceToReserve->reservations();
01417 int oldReservationSize = oldReservations.size();
01418 domain::Task* task1 = tasksToShow.at(2);
01419 QDateTime latestEndTime = task1->schedule().startDate();
01420 const domain::Duration reservationDuration(21*24*60*60);
01421 Q_FOREACH (const domain::Reservation* reservation, oldReservations) {
01422 if (latestEndTime < reservation->time().addSecs(reservation->duration().totalSeconds()))
01423 latestEndTime = reservation->time().addSecs(reservation->duration().totalSeconds());
01424 }
01425 QDateTime startTime = latestEndTime.addSecs(1);
01426
01427 ui->data->reservationDetails.time = startTime;
01428 ui->data->reservationDetails.duration = reservationDuration;
01429 ui->data->reservationDetails.processData = true;
01430
01431
01432 control::data::SelectionData selectionData;
01433 selectionData.processData = true;
01434 QModelIndexList indexList;
01435 indexList.append(control::TaskModel(taskManagerData,
01436 tools::makeConstList(tasksToShow)).indexForTask(task1));
01437 selectionData.selection = indexList;
01438 ui->data->selectionDataList.append(selectionData);
01439
01440
01441 control::data::SelectionData selectionData2;
01442 selectionData2.processData = true;
01443 QModelIndexList indexList2;
01444 indexList2.append(control::ResourceModel(taskManagerData).indexForResource(resourceToReserve));
01445 selectionData2.selection = indexList2;
01446 ui->data->selectionDataList.append(selectionData2);
01447
01448 ui->data->error = false;
01449 controller->run();
01450 QVERIFY(!ui->data->error);
01451
01452 QVERIFY(oldReservationSize + 1 == resourceToReserve->reservations().size());
01453
01454 bool reservationPresent = false;
01455 Q_FOREACH (domain::Reservation* reservation, taskManagerData->reservations()) {
01456 if (!(reservation->duration() == reservationDuration))
01457 continue;
01458 if (reservation->resource() != resourceToReserve)
01459 continue;
01460 if (reservation->time() != startTime)
01461 continue;
01462 reservationPresent = true;
01463 }
01464 QVERIFY(reservationPresent);
01465 }
01466
01467 void ControlTest::testInvitationReplier()
01468 {
01469 loadData();
01470
01471 controller = factory->controllerByType(control::ControllerInterface::InvitationData,
01472 control::ControllerInterface::ModifyAction);
01473 QVERIFY(controller->name() == "InvitationReplier");
01474 QVERIFY(controller->description() == "Accept/Decline invitation");
01475
01476
01477 ui->data->error = false;
01478 controller->run();
01479 QVERIFY(ui->data->error);
01480
01481
01482 ui->setUser(taskManagerData->adminUser());
01483 ui->data->error = false;
01484 controller->run();
01485 QVERIFY(ui->data->error);
01486
01487
01488
01489
01490 ui->setUser(taskManagerData->users().at(2));
01491
01492 control::InvitationModel pendingInvitations(taskManagerData, ui->user(),
01493 domain::Invitation::Pending);
01494 control::InvitationModel acceptedInvitations(taskManagerData, ui->user(),
01495 domain::Invitation::Accepted);
01496 int pendingInvitationsBefore = pendingInvitations.rowCount();
01497 int acceptedInvitationsBefore = acceptedInvitations.rowCount();
01498 domain::Invitation* selectedInvitation =
01499 taskManagerData->invitation(ui->user()->invitations().at(0));
01500 ui->data->invitationsSelection.processData = true;
01501 QModelIndexList indexList;
01502 indexList.append(pendingInvitations.indexForInvitation(selectedInvitation));
01503 ui->data->invitationsSelection.selection = indexList;
01504
01505 control::data::StringInputData input;
01506 input.processData = true;
01507 input.data = "Decline";
01508 ui->data->choiceAnswers.append(input);
01509
01510 ui->data->error = false;
01511 controller->run();
01512 QVERIFY(!ui->data->error);
01513
01514 int pendingInvitationsAfter = pendingInvitations.rowCount();
01515 int acceptedInvitationsAfter = pendingInvitations.rowCount();
01516
01517 QVERIFY(pendingInvitationsBefore - pendingInvitationsAfter == 1);
01518 QVERIFY(acceptedInvitationsBefore - acceptedInvitationsAfter == 0);
01519
01520
01521 loadData();
01522
01523 ui->setUser(taskManagerData->users().at(2));
01524
01525 control::InvitationModel pendingInvitations2(taskManagerData, ui->user(),
01526 domain::Invitation::Pending);
01527 control::InvitationModel acceptedInvitations2(taskManagerData, ui->user(),
01528 domain::Invitation::Accepted);
01529
01530 int pendingInvitationsBefore2 = pendingInvitations2.rowCount();
01531 int acceptedInvitationsBefore2 = acceptedInvitations2.rowCount();
01532
01533 domain::Invitation* selectedInvitation2 =
01534 taskManagerData->invitation(ui->user()->invitations().at(0));
01535 ui->data->invitationsSelection.processData = true;
01536 QModelIndexList indexList2;
01537 indexList2.append(pendingInvitations2.indexForInvitation(selectedInvitation2));
01538 ui->data->invitationsSelection.selection = indexList2;
01539
01540 control::data::StringInputData input2;
01541 input2.processData = true;
01542 input2.data = "Accept";
01543 ui->data->choiceAnswers.append(input2);
01544
01545 ui->data->error = false;
01546 controller->run();
01547 QVERIFY(!ui->data->error);
01548
01549 int pendingInvitationsAfter2 = pendingInvitations2.rowCount();
01550 int acceptedInvitationsAfter2 = acceptedInvitations2.rowCount();
01551
01552 QVERIFY(pendingInvitationsBefore2 - pendingInvitationsAfter2 == 1);
01553 QVERIFY(acceptedInvitationsAfter2 - acceptedInvitationsBefore2 == 1);
01554
01555 }
01556
01557 void ControlTest::testInvitationManager()
01558 {
01559 loadData();
01560
01561 controller = factory->controllerByType(control::ControllerInterface::InvitationData,
01562 control::ControllerInterface::ManageAction);
01563 QVERIFY(controller->name() == "InvitationManager");
01564 QVERIFY(controller->description() == "Manage invitations");
01565
01566
01567 ui->data->error = false;
01568 controller->run();
01569 QVERIFY(ui->data->error);
01570
01571
01572 ui->setUser(taskManagerData->adminUser());
01573 ui->data->error = false;
01574 controller->run();
01575 QVERIFY(ui->data->error);
01576
01577
01578 ui->setUser(taskManagerData->users().at(1));
01579 ui->data->warning = false;
01580 controller->run();
01581 QVERIFY(ui->data->warning);
01582
01583
01584 ui->setUser(taskManagerData->users().first());
01585
01586 control::TaskModel taskModel(taskManagerData,
01587 tools::makeConstList(taskManagerData->tasksForUser(ui->user())));
01588
01589
01590 control::data::SelectionData selectionData3;
01591 domain::Task* selectedTask2 = taskManagerData->tasksForUser(ui->user()).at(1);
01592 QModelIndexList indexList3;
01593 indexList3.append(taskModel.indexForTask(selectedTask2));
01594 selectionData3.processData = true;
01595 selectionData3.selection = indexList3;
01596 ui->data->selectionDataList.append(selectionData3);
01597
01598
01599 control::data::StringInputData input2;
01600 input2.processData = true;
01601 input2.data = "Remove";
01602 ui->data->choiceAnswers.append(input2);
01603
01604 control::InvitationModel invitationModel(taskManagerData, selectedTask2);
01605 int invitationsBefore = invitationModel.rowCount();
01606
01607
01608 control::data::SelectionData selectionData4;
01609 domain::Invitation* selectedInvitation =
01610 taskManagerData->invitation(selectedTask2->invitations().at(0));
01611 domain::User* userOfInvitation =
01612 taskManagerData->user(selectedInvitation->user());
01613 QModelIndexList indexList4;
01614 indexList4.append(invitationModel.indexForInvitation(selectedInvitation));
01615 selectionData4.processData = true;
01616 selectionData4.selection = indexList4;
01617 ui->data->selectionDataList.append(selectionData4);
01618
01619
01620 control::data::SelectionData selectionDataStop;
01621 selectionDataStop.processData = false;
01622 ui->data->selectionDataList.append(selectionDataStop);
01623
01624 ui->data->error = false;
01625 ui->data->model = false;
01626 controller->run();
01627 QVERIFY(ui->data->model);
01628 QVERIFY(!ui->data->error);
01629
01630 int invitationsAfter = invitationModel.rowCount();
01631 QVERIFY(invitationsBefore - invitationsAfter == 1);
01632 QVERIFY(!userOfInvitation->invitations().contains(selectedInvitation));
01633
01634
01635 control::data::SelectionData selectionData;
01636 domain::Task* selectedTask1 = taskManagerData->tasksForUser(ui->user()).at(1);
01637 QModelIndexList indexList1;
01638 indexList1.append(taskModel.indexForTask(selectedTask1));
01639 selectionData.processData = true;
01640 selectionData.selection = indexList1;
01641 ui->data->selectionDataList.append(selectionData);
01642
01643
01644 control::data::StringInputData input1;
01645 input1.processData = true;
01646 input1.data = "Add";
01647 ui->data->choiceAnswers.append(input1);
01648
01649 control::UserModel userModel(taskManagerData);
01650
01651
01652 control::data::SelectionData selectionData2;
01653 domain::User* user1 = taskManagerData->users().at(2);
01654 QModelIndexList indexList2;
01655 indexList2.append(userModel.indexForUser(user1));
01656 selectionData2.processData = true;
01657 selectionData2.selection = indexList2;
01658 ui->data->selectionDataList.append(selectionData2);
01659
01660 invitationsBefore = invitationModel.rowCount();
01661
01662 ui->data->error = false;
01663 ui->data->model = false;
01664 controller->run();
01665 QVERIFY(ui->data->model);
01666 QVERIFY(!ui->data->error);
01667
01668 bool containsNewInvitation = false;
01669 Q_FOREACH(const domain::Invitation* inv, user1->invitations())
01670 {
01671 domain::Task* nonConstTask = taskManagerData->task(inv->task());
01672 if (!(nonConstTask == selectedTask1))
01673 continue;
01674 containsNewInvitation = true;
01675 }
01676 QVERIFY(containsNewInvitation);
01677
01678 invitationsAfter = invitationModel.rowCount();
01679 QVERIFY(invitationsAfter - invitationsBefore == 1);
01680
01681
01682 control::data::SelectionData selectionData5;
01683 domain::Task* selectedTask3 = taskManagerData->tasksForUser(ui->user()).first();
01684 QModelIndexList indexList5;
01685 indexList5.append(taskModel.indexForTask(selectedTask3));
01686 selectionData5.processData = true;
01687 selectionData5.selection = indexList5;
01688 ui->data->selectionDataList.append(selectionData5);
01689
01690
01691 control::data::StringInputData input3;
01692 input3.processData = true;
01693 input3.data = "Remove";
01694 ui->data->choiceAnswers.append(input3);
01695
01696 ui->data->warning = false;
01697 ui->data->model = false;
01698 controller->run();
01699 QVERIFY(ui->data->warning);
01700 QVERIFY(ui->data->model);
01701
01702
01703 ui->data->selectionDataList.append(selectionData5);
01704 ui->data->choiceAnswers.append(input1);
01705 control::data::SelectionData selectionData6;
01706 domain::User* user2 = taskManagerData->users().first();
01707 QModelIndexList indexList6;
01708 indexList6.append(userModel.indexForUser(user2));
01709 selectionData5.processData = true;
01710 selectionData5.selection = indexList6;
01711 ui->data->selectionDataList.append(selectionData5);
01712 ui->data->selectionDataList.append(selectionDataStop);
01713
01714 invitationsBefore = invitationModel.rowCount();
01715 ui->data->error = false;
01716 controller->run();
01717 QVERIFY(ui->data->error);
01718 invitationsAfter = invitationModel.rowCount();
01719 QVERIFY(invitationsBefore == invitationsAfter);
01720
01721 }
01722
01723 void ControlTest::testFocusStrategies()
01724 {
01725 loadData();
01726
01727 QList<control::FocusInterface*> focusStrategies = getfocusStrategies(ui);
01728
01729 QMap<QString, control::FocusInterface*> strategyMap;
01730
01731 Q_FOREACH (control::FocusInterface* c, focusStrategies)
01732 strategyMap[c->description()] = c;
01733
01734 domain::User* user1 = taskManagerData->users().first();
01735
01736
01737 control::FocusInterface* durationFocus = strategyMap["Duration-based focus"];
01738 QList<domain::Task*> tasks = taskManagerData->tasksForUser(user1);
01739 control::data::MinMaxDurationData durationData;
01740 durationData.maxDuration = domain::Duration(1,3,0,0,0);
01741 durationData.minDuration = domain::Duration(0,0,4,0,0);
01742 durationData.maxDurationSet = true;
01743 durationData.minDurationSet = true;
01744 durationData.processData = true;
01745 ui->data->minMaxDurationData = durationData;
01746
01747 QVERIFY(durationFocus->applyFocus(&tasks));
01748 QVERIFY(tasks.size() == 3);
01749
01750 Q_FOREACH(domain::Task* task, tasks)
01751 {
01752 QVERIFY(task->schedule().duration().totalSeconds()
01753 >= durationData.minDuration.totalSeconds());
01754 QVERIFY(task->schedule().duration().totalSeconds()
01755 <= durationData.maxDuration.totalSeconds());
01756 }
01757
01758 for (int i = 0; i < tasks.size() - 1; i++)
01759 {
01760 QVERIFY(tasks.at(i)->schedule().duration().totalSeconds() <=
01761 tasks.at(i+1)->schedule().duration().totalSeconds());
01762 }
01763
01764
01765 durationData.maxDuration = domain::Duration(0,3,0,0,0);
01766 durationData.minDuration = domain::Duration(1,0,4,0,0);
01767 durationData.maxDurationSet = true;
01768 durationData.minDurationSet = true;
01769 durationData.processData = true;
01770 ui->data->minMaxDurationData = durationData;
01771
01772 QVERIFY(durationFocus->applyFocus(&tasks));
01773 QVERIFY(tasks.isEmpty());
01774
01775
01776 control::FocusInterface* taskTypeFocus = strategyMap["Task-type focus"];
01777 tasks = taskManagerData->tasksForUser(user1);
01778 domain::TaskType* type = taskManagerData->taskTypes().first();
01779 control::data::StringInputData choice;
01780 choice.processData = true;
01781 choice.data = type->name();
01782 ui->data->choiceAnswers.append(choice);
01783
01784 QVERIFY(taskTypeFocus->applyFocus(&tasks));
01785 QVERIFY(tasks.size() == 2);
01786
01787 Q_FOREACH(domain::Task* task, tasks)
01788 {
01789 QVERIFY(task->taskType() == type);
01790 }
01791
01792
01793 control::FocusInterface* deadlineFocus = strategyMap["Deadline-based focus"];
01794 tasks = taskManagerData->tasksForUser(user1);
01795 QDateTime newTime(QDate(2009, 10, 25), QTime(0,0));
01796 taskManagerData->clock()->setTime(newTime);
01797
01798 domain::TaskType* newType = taskManagerData->createTaskType("id", "name");
01799 newType->addPotentialOwner(user1->userType());
01800 domain::Schedule schedule1(domain::Duration(0,0,5,0,0),
01801 QDateTime(QDate(2009,10,20), QTime(0,0)),
01802 QDateTime(QDate(2009,11,1), QTime(0,0)));
01803 domain::Task* newTask1 = taskManagerData->createTask(newType, user1, schedule1);
01804 tasks << newTask1;
01805 domain::Schedule schedule2(domain::Duration(0,1,0,40,0),
01806 QDateTime(QDate(2009,10,21), QTime(0,0)),
01807 QDateTime(QDate(2009,12,1), QTime(4,0)));
01808 domain::Task* newTask2 = taskManagerData->createTask(newType, user1, schedule2);
01809 tasks << newTask2;
01810
01811 ui->data->integer = 10;
01812
01813 QVERIFY(deadlineFocus->applyFocus(&tasks));
01814 QVERIFY(tasks.size() == 3);
01815
01816 Q_FOREACH (domain::Task* task, tasks)
01817 {
01818 QVERIFY(task->isAvailable());
01819 }
01820
01821 for (int i = 0; i < tasks.size() - 1; i++)
01822 {
01823 QVERIFY(tasks.at(i)->schedule().dueDate()
01824 < tasks.at(i+1)->schedule().dueDate());
01825 }
01826
01827 ui->data->integer = 1;
01828 QVERIFY(deadlineFocus->applyFocus(&tasks));
01829 QVERIFY(tasks.size() == 1);
01830 }
01831
01832 Q_EXPORT_PLUGIN2(test_control, ControlTest)