source: trunk/test/integration/TaskSearchServiceTests.groovy @ 511

Last change on this file since 511 was 511, checked in by gav, 14 years ago

Adjust TaskSearchService.getPersonsTasks() so that if a person created it and is leadPerson then that task is returned.
Started on integration tests for TaskSearchService.

File size: 3.4 KB
Line 
1import grails.test.*
2
3/**
4* Integration tests for TaskSearchService.
5*/
6class TaskSearchServiceTests extends GroovyTestCase {
7
8    // Data will be saved, not rolled back.
9    // Be sure to clean up in tearDown().
10    boolean transactional = false
11
12    def taskService
13    def dateUtilService
14    def taskSearchService
15
16    def taskA
17    def taskB
18    def taskCount = 0
19
20    // Setup is called before each test.
21    protected void setUp() {
22        super.setUp()
23
24        // Check environment state.
25        assert Task.count() == 0
26        assert Entry.count() == 0
27        assert TaskModification.count() == 0
28
29        def p = [:]
30        def result
31
32        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
33                taskPriority:TaskPriority.get(2),
34                taskType:TaskType.get(1),
35                leadPerson:Person.get(1),
36                description:"TestA",
37                comment:"Service test task.",
38                targetStartDate: dateUtilService.today,
39                targetCompletionDate: dateUtilService.today]
40
41        result = taskService.save(p)
42        assert result.error == null
43        taskCount++
44        taskA = result.taskInstance.refresh()
45
46        p.description = "TestB"
47        result = taskService.save(p)
48        assert result.error == null
49        taskCount++
50        taskB = result.taskInstance.refresh()
51    }
52
53    // Tear down is called after each test.
54    protected void tearDown() {
55        super.tearDown()
56
57        taskService.delete(taskA)
58        taskService.delete(taskB)
59
60        // Ensure that we leave environment clean.
61        assert Task.count() == 0
62        assert TaskModification.count() == 0
63        assert Entry.count() == 0
64    }
65
66    void testGetTasks() {
67        // Todays tasks should be returned
68        def tasks = taskSearchService.getTasks([:])
69        assert tasks.totalCount == taskCount
70
71        // Tasks in the trash should not be returned.
72        tasks[0].trash = true
73        tasks[0].save(flush:true)
74        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
75        tasks[1].trash = true
76        tasks[1].save(flush:true)
77        assert taskSearchService.getTasks([:]).totalCount == taskCount - 2
78
79        // Restored tasks should be returned.
80        tasks[0].trash = false
81        tasks[0].save(flush:true)
82        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
83        tasks[1].trash = false
84        tasks[1].save(flush:true)
85        assert taskSearchService.getTasks([:]).totalCount == taskCount
86
87        // Tomorrows tasks should not be returned.
88        tasks[0].targetStartDate = dateUtilService.tomorrow
89        tasks[0].targetCompletionDate = dateUtilService.tomorrow
90        tasks[0].save(flush:true)
91        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
92
93        // Yesterdays tasks should not be returned.
94        tasks[0].targetStartDate = dateUtilService.yesterday
95        tasks[0].targetCompletionDate = dateUtilService.yesterday
96        tasks[0].save(flush:true)
97        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
98
99        // Tasks that span today should be returned.
100        tasks[0].targetStartDate = dateUtilService.yesterday
101        tasks[0].targetCompletionDate = dateUtilService.tomorrow
102        tasks[0].save(flush:true)
103        assert taskSearchService.getTasks([:]).totalCount == taskCount
104    } // testGetTasks()
105
106} // end class
Note: See TracBrowser for help on using the repository browser.