Example #1
1
 public <T extends AbstractTask> T createTask(Class<T> type, Project project, String name) {
   Task task =
       TASK_FACTORY.createTask(
           (ProjectInternal) project, GUtil.map(Task.TASK_TYPE, type, Task.TASK_NAME, name));
   assertTrue(type.isAssignableFrom(task.getClass()));
   return type.cast(task);
 }
Example #2
0
 @Test
 public void find_findsTaskInDatabase_true() {
   Task myTask = new Task("Mow the lawn", 1);
   myTask.save();
   Task savedTask = Task.find(myTask.getId());
   assertTrue(myTask.equals(savedTask));
 }
 @Test
 public void testGetTaskFulltext() throws Exception {
   String search = "Third Task";
   List<Task> tasks = taskService.getTaskFulltext("\"" + search + "\"");
   for (Task task : tasks) {
     assertTrue(
         task.getName().contains(search)
             || task.getDescription().contains(search)
             || task.getTestSteps().contains(search));
   }
 }
Example #4
0
  @Test
  public void testDependsOn() {
    Task dependsOnTask = createTask(project, "somename");
    Task task = createTask(project, TEST_TASK_NAME);
    project.getTasks().add("path1");
    project.getTasks().add("path2");

    task.dependsOn(Project.PATH_SEPARATOR + "path1");
    assertThat(task, dependsOn("path1"));
    task.dependsOn("path2", dependsOnTask);
    assertThat(task, dependsOn("path1", "path2", "somename"));
  }
 @Test
 public void testGetTasks() throws Exception {
   List<Task> tasks = taskService.getTasks();
   for (Task task : tasks) {
     assertNotNull(task);
     assertTrue(task.getId() > 0);
     assertNotNull(task.getName());
     assertNotNull(task.getDescription());
     assertNotNull(task.getTestSteps());
     assertNotNull(task.getCreator());
     assertNotNull(task.getAssignee());
     assertNotNull(task.getStatus());
     assertNotNull(task.getPriority());
     assertNotNull(task.getType());
   }
 }
 @Test
 public void testGetTaskByID() throws Exception {
   Optional<Task> optTask = taskService.getTaskByID(1);
   assertTrue(optTask.isPresent());
   Task task = optTask.get();
   assertNotNull(task);
   assertEquals(1, task.getId());
   assertNotNull(task.getName());
   assertNotNull(task.getDescription());
   assertNotNull(task.getTestSteps());
   assertNotNull(task.getCreator());
   assertNotNull(task.getAssignee());
   assertNotNull(task.getStatus());
   assertNotNull(task.getPriority());
   assertNotNull(task.getType());
 }
Example #7
0
 @Test
 public void save_assignsIdToObject() {
   Task myTask = new Task("Mow the lawn", 1);
   myTask.save();
   Task savedTask = Task.all().get(0);
   assertEquals(myTask.getId(), savedTask.getId());
 }
Example #8
0
  @Test
  public void testPath() {
    DefaultProject rootProject = HelperUtil.createRootProject();
    DefaultProject childProject = HelperUtil.createChildProject(rootProject, "child");
    childProject.getProjectDir().mkdirs();
    DefaultProject childchildProject = HelperUtil.createChildProject(childProject, "childchild");
    childchildProject.getProjectDir().mkdirs();

    Task task = createTask(rootProject, TEST_TASK_NAME);
    assertEquals(Project.PATH_SEPARATOR + TEST_TASK_NAME, task.getPath());
    task = createTask(childProject, TEST_TASK_NAME);
    assertEquals(
        Project.PATH_SEPARATOR + "child" + Project.PATH_SEPARATOR + TEST_TASK_NAME, task.getPath());
    task = createTask(childchildProject, TEST_TASK_NAME);
    assertEquals(
        Project.PATH_SEPARATOR
            + "child"
            + Project.PATH_SEPARATOR
            + "childchild"
            + Project.PATH_SEPARATOR
            + TEST_TASK_NAME,
        task.getPath());
  }
Example #9
0
 @Test
 public void save_savesCategoryIdIntoDB_true() {
   Category myCategory = new Category("Household chores");
   myCategory.save();
   Task myTask = new Task("Mow the lawn", myCategory.getId());
   myTask.save();
   Task savedTask = Task.find(myTask.getId());
   assertEquals(savedTask.getCategoryId(), myCategory.getId());
 }
Example #10
0
 @Test
 public void save_returnsTrueIfDescriptionsAretheSame() {
   Task myTask = new Task("Mow the lawn", 1);
   myTask.save();
   assertTrue(Task.all().get(0).equals(myTask));
 }
  @Test
  public void testCreateTask() throws Exception {
    TaskBuilder builder = taskService.createTask();
    builder.creator(user);
    builder.project(project);
    builder.name(name);
    builder.description(desc);
    builder.testSteps(teststeps);
    builder.type(type);
    builder.estimated(8);
    builder.priority(priority);
    Task task = builder.build();

    task.store();

    assertNotNull(task);
    assertTrue(task.getId() > 0);
    assertEquals(name, task.getName());
    assertEquals(desc, task.getDescription());
    assertEquals(teststeps, task.getTestSteps());
    assertEquals(user.getName(), task.getCreator().getName());
    assertEquals(user.getName(), task.getAssignee().getName());
    assertEquals("New", task.getStatus().getName());
    assertEquals(priority, task.getPriority());
    assertEquals(type, task.getType());
  }
  @Test
  public void testExecuteCommand() throws ParseException {
    String userInput = null;

    HashMap<String, Object> expected = null;
    HashMap<String, Object> actual = null;
    ArrayList<String> errorList = new ArrayList<String>();
    ArrayList<String> successList = new ArrayList<String>();
    ArrayList<String> warningList = new ArrayList<String>();
    ArrayList<String> helpList = new ArrayList<String>();
    ArrayList<String> paramList = new ArrayList<String>();
    ArrayList<Task> taskList = new ArrayList<Task>();

    Task task1 = null;
    Task task2 = null;
    Task task3 = null;
    Task task4 = null;
    Task task5 = null;
    Task task6 = null;

    Date startTime = null;
    Date endTime = null;
    // Test display
    userInput = "display";

    errorList = new ArrayList<String>();
    errorList.add(ERROR_EMPTY_TASKLIST);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for misspelling
    userInput = "dsplay";

    errorList = new ArrayList<String>();
    errorList.add(ERROR_INVALID_COMMAND);

    helpList = new ArrayList<String>();
    helpList.add(HELP_ADD_TASK);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for add floating task
    userInput = "add do \"sth1\"";
    task1 = new Task(1, "sth1", null, null);

    successList = new ArrayList<String>();
    successList.add(MESSAGE_ADD_TASK);
    taskList.add(task1);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for add event task
    userInput = "add on 12/10/15 from 1200 to 1240 do \"sth2\"";
    try {
      startTime = df.parse("12/10/15 1200");
      endTime = df.parse("12/10/15 1240");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task2 = new Task(2, "sth2", startTime, endTime, null);

    successList = new ArrayList<String>();
    successList.add(MESSAGE_ADD_TASK);
    taskList = new ArrayList<Task>();
    taskList.add(task2);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for add event task with different start and end dates
    userInput = "add do \"sth3\" from 12/10/15 1200 to 14/10/15 1340";
    try {
      startTime = df.parse("12/10/15 1200");
      endTime = df.parse("14/10/15 1340");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task3 = new Task(3, "sth3", startTime, endTime, null);

    successList = new ArrayList<String>();
    successList.add(MESSAGE_ADD_TASK);
    errorList = new ArrayList<String>();
    errorList.add(ERROR_START_BEFORE_END);
    taskList = new ArrayList<Task>();
    taskList.add(task3);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for add event task with unspecified end time
    userInput = "add do \"sth4\" on 12/10/15 from 1200";
    try {
      startTime = df.parse("12/10/15 1200");
      endTime = df.parse("12/10/15 1300");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task4 = new Task(4, "sth4", startTime, endTime, null);

    successList = new ArrayList<String>();
    successList.add(MESSAGE_ADD_TASK);
    taskList = new ArrayList<Task>();
    taskList.add(task4);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for add event task with unspecified start time
    userInput = "add do \"sth5\" on 12/10/15 to 1240";
    try {
      startTime = df.parse("12/10/15 1100");
      endTime = df.parse("12/10/15 1240");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);

    successList = new ArrayList<String>();
    successList.add(MESSAGE_ADD_TASK);
    taskList = new ArrayList<Task>();
    taskList.add(task5);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for add deadline task
    userInput = "add do \"sth6\" by 12/10/15 2359";
    try {
      df.parse("12/10/15 2359");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task6 = new Task(6, "sth6", startTime, endTime, null);

    successList = new ArrayList<String>();
    successList.add(MESSAGE_ADD_TASK);
    taskList = new ArrayList<Task>();
    taskList.add(task6);

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit desc only
    userInput = "edit 1 do \"nothing-5\"";

    task1 = new Task(1, "nothing-5", null, null);
    taskList.add(task1);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 1));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit floating to event (set startDate, startTime, endDate and endTime
    userInput = "edit 2 on 12/10/15 from 1200 to 1400";

    try {
      startTime = df.parse("12/10/15 1200");
      endTime = df.parse("12/10/15 1400");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task2 = new Task(2, "sth2", startTime, endTime, null);
    taskList.add(task2);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 2));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit floating task startDate only
    userInput = "edit 5 from 10/15/15";
    try {
      startTime = df.parse("10/15/15 0000");
      endTime = task5.getEndDateTime();

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit floating task startDate and startTime
    userInput = "edit 5 from 10/15/15 2115";
    try {
      startTime = df.parse("10/15/15 2115");
      endTime = task5.getEndDateTime();

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task startDate, startTime and endTime
    userInput = "edit 5 on 10/25/15 from 1130 to 1409";
    try {
      startTime = df.parse("10/25/15 1130");
      endTime = df.parse("10/25/15 1409");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task endDate and endTime
    userInput = "edit 5 to 10/27/15 2220";
    try {
      startTime = task5.getStartDateTime();
      endTime = df.parse("10/27/15 2220");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task endDate only
    userInput = "edit 5 to 12/24/15";
    try {
      startTime = task5.getStartDateTime();
      endTime = df.parse("12/24/15 2220");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task startDate and endDate only
    userInput = "edit 5 on 12/25/15";
    try {
      startTime = df.parse("10/25/15 1130");
      endTime = df.parse("12/24/15 2220");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertFalse(isSameObjHash(expected, actual)); // @A0118772 endtime should not change!
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task startDate and startTime only
    userInput = "edit 5 on 09/25/15 from 1000";
    try {
      startTime = df.parse("09/25/15 1000");
      endTime = df.parse("12/24/15 2220");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task endDate and endTime only
    userInput = "edit 5 on 10/25/15 to 0030";
    try {
      startTime = df.parse("09/25/15 1000");
      endTime = df.parse("10/25/15 0030");

    } catch (ParseException e) {
      e.printStackTrace();
    }
    task5 = new Task(5, "sth5", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for edit task venue
    userInput = "edit 5 at \"do from on to at by\"";

    startTime = task5.getStartDateTime();
    endTime = task5.getEndDateTime();

    task5 = new Task(5, "do from on to at by", startTime, endTime, null);
    taskList.add(task5);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_EDIT_TASK, 5));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);

    // Test for delete task
    userInput = "delete 2";

    taskList.add(task2);
    successList = new ArrayList<String>();
    successList.add(String.format(MESSAGE_DELETE_TASK, 2));

    expected =
        buildExpectedHashmap(successList, warningList, helpList, paramList, errorList, taskList);

    TaskHandler.executeCommand(userInput);
    actual = stripJson(context.getDataModel());
    assertTrue(isSameObjHash(expected, actual));
    context.clearAllMessages();
    clearArrayLists(successList, warningList, helpList, paramList, errorList, taskList);
  }
  @Test
  public void testGetTask() {
    Task testTask = new Task(1, "Task2", Priority.HIGH);

    assertTrue(testTask.equals(userstory.getTaskById(1)));
  }
Example #14
0
 @Test
 public void all_emptyAtFirst() {
   assertEquals(Task.all().size(), 0);
 }
Example #15
0
  @Test
  public void createTasks() throws Exception {
    List<int[]> selectedCubes = new ArrayList<>();
    Statement stmt = f.createPrint(new True(), null);
    List<Task> tasks = f.createTasks("blub", 10, stmt, selectedCubes);

    assertEquals(1, tasks.size());
    assertEquals("blub", tasks.get(0).getName());
    assertEquals(10, tasks.get(0).getPriority());
    assertEquals(stmt, tasks.get(0).getActivity());
    assertEquals(null, tasks.get(0).getSelectedCube());

    selectedCubes.addAll(Arrays.asList(new int[] {0, 0, 0}, new int[] {1, 1, 1}));
    tasks = f.createTasks("test", 25, stmt, selectedCubes);

    assertEquals(2, tasks.size());
    for (Task t : tasks) {
      assertEquals("test", t.getName());
      assertEquals(25, t.getPriority());
      assertEquals(stmt, t.getActivity());
      assertTrue(
          t.getSelectedCube().equals(new Vector(0, 0, 0))
              || t.getSelectedCube().equals(new Vector(1, 1, 1)));
    }
  }
Example #16
0
 @Test
 public void Task_intantiatesWithDescription_true() {
   Task myTask = new Task("Mow the lawn");
   assertEquals("Mow the lawn", myTask.getDescription());
 }
 @Test
 public void testGetTaskByUserCompleted() throws Exception {
   List<Task> tasks = taskService.getTaskByUserCompleted(4);
   for (Task task : tasks) {
     assertNotNull(task);
     assertTrue(task.getId() > 0);
     assertNotNull(task.getName());
     assertNotNull(task.getDescription());
     assertNotNull(task.getTestSteps());
     assertNotNull(task.getCreator());
     assertNotNull(task.getAssignee());
     assertNotNull(task.getStatus());
     assertNotNull(task.getPriority());
     assertNotNull(task.getType());
     assertTrue(
         "Resolved".equals(task.getStatus().getName())
             || "Closed".equals(task.getStatus().getName()));
   }
 }
Example #18
0
 @Test
 public void equals_returnsTrueIfDescriptionsAretheSame() {
   Task firstTask = new Task("Mow the lawn", 1);
   Task secondTask = new Task("Mow the lawn", 1);
   assertTrue(firstTask.equals(secondTask));
 }