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

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

Remove stale testGetBudgetTasks.

File size: 8.1 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    def assignedGroupService
16    def assignedPersonService
17
18    def taskA
19    def taskB
20    def taskCount = 0
21
22    // Setup is called before each test.
23    protected void setUp() {
24        super.setUp()
25
26        // Check environment state.
27        assert Task.count() == 0
28        assert Entry.count() == 0
29        assert TaskModification.count() == 0
30
31        def p = [:]
32        def result
33
34        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
35                taskPriority:TaskPriority.get(2),
36                taskType:TaskType.get(1),
37                leadPerson:Person.get(1),
38                description:"TestA",
39                comment:"Service test task.",
40                targetStartDate: dateUtilService.today,
41                targetCompletionDate: dateUtilService.today]
42
43        result = taskService.save(p)
44        assert result.error == null
45        taskCount++
46        taskA = result.taskInstance.refresh()
47
48        p.description = "TestB"
49        result = taskService.save(p)
50        assert result.error == null
51        taskCount++
52        taskB = result.taskInstance.refresh()
53    }
54
55    // Tear down is called after each test.
56    protected void tearDown() {
57
58        taskService.delete(taskA)
59        taskService.delete(taskB)
60
61        // Ensure that we leave environment clean.
62        assert Task.count() == 0
63        assert TaskModification.count() == 0
64        assert Entry.count() == 0
65
66        super.tearDown()
67    }
68
69
70    /**
71    * Test GetTasks.
72    */
73    void testGetTasks() {
74        // Todays tasks should be returned.
75        def tasks = taskSearchService.getTasks([:])
76        assert tasks.totalCount == taskCount
77
78        // Tasks in the trash should not be returned.
79        taskA.trash = true
80        taskA.save(flush:true)
81        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
82        taskB.trash = true
83        taskB.save(flush:true)
84        assert taskSearchService.getTasks([:]).totalCount == taskCount - 2
85
86        // Restored tasks should be returned.
87        taskA.trash = false
88        taskA.save(flush:true)
89        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
90        taskB.trash = false
91        taskB.save(flush:true)
92        assert taskSearchService.getTasks([:]).totalCount == taskCount
93
94        // Tomorrows tasks should not be returned.
95        taskA.targetStartDate = dateUtilService.tomorrow
96        taskA.targetCompletionDate = dateUtilService.tomorrow
97        taskA.save(flush:true)
98        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
99
100        // Tomorrows tasks should be returned, if we ask for them.
101        assert taskSearchService.getTasks([:], dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
102
103        // Yesterdays tasks should not be returned.
104        taskA.targetStartDate = dateUtilService.yesterday
105        taskA.targetCompletionDate = dateUtilService.yesterday
106        taskA.save(flush:true)
107        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
108
109        // Yesterdays tasks should be returned, if we ask for them.
110        assert taskSearchService.getTasks([:], dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
111
112        // Tasks that span today should be returned.
113        taskA.targetStartDate = dateUtilService.yesterday
114        taskA.targetCompletionDate = dateUtilService.tomorrow
115        taskA.save(flush:true)
116        assert taskSearchService.getTasks([:]).totalCount == taskCount
117    } // testGetTasks()
118
119    /**
120    * Test GetPersonsTasks.
121    */
122    void testGetPersonsTasks() {
123
124        def p = [:]
125        def params = [:]
126
127        // Todays tasks should be returned, since Person #1 is lead and created the tasks.
128        def tasks = taskSearchService.getPersonsTasks(params)
129        assert tasks.totalCount == taskCount
130
131        // Tasks in the trash should not be returned.
132        taskA.trash = true
133        taskA.save(flush:true)
134        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
135        taskB.trash = true
136        taskB.save(flush:true)
137        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 2
138
139        // Restored tasks should be returned.
140        taskA.trash = false
141        taskA.save(flush:true)
142        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
143        taskB.trash = false
144        taskB.save(flush:true)
145        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount
146
147        // Tomorrows tasks should not be returned.
148        taskA.targetStartDate = dateUtilService.tomorrow
149        taskA.targetCompletionDate = dateUtilService.tomorrow
150        taskA.save(flush:true)
151        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
152
153        // Tomorrows tasks should be returned, if we ask for them.
154        assert taskSearchService.getPersonsTasks(params, null, dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
155
156        // Yesterdays tasks should not be returned.
157        taskA.targetStartDate = dateUtilService.yesterday
158        taskA.targetCompletionDate = dateUtilService.yesterday
159        taskA.save(flush:true)
160        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
161
162        // Yesterdays tasks should be returned, if we ask for them.
163        assert taskSearchService.getPersonsTasks(params, null, dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
164
165        // Tasks that span today should be returned.
166        taskA.targetStartDate = dateUtilService.yesterday
167        taskA.targetCompletionDate = dateUtilService.tomorrow
168        taskA.save(flush:true)
169        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount
170
171        // Tasks for a different person should not be returned.
172        taskA.leadPerson = Person.get(2)
173        taskA.save(flush:true)
174        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
175
176        // Tasks for a specified leadPerson should be returned.
177        // But only if approved since this person did not create the tasks.
178        taskA.leadPerson = Person.get(2)
179        taskA.save(flush:true)
180        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
181        taskA.approved = true
182        taskA.save(flush:true)
183        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1
184        // Moving the task to the trash, stops it being returned.
185        taskA.trash = true
186        taskA.save(flush:true)
187        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
188
189        // Tasks assigned to a person should be returned.
190        // But only if approved.
191        p = [person: Person.get(2),
192                task: taskB,
193                estimatedHour: 1,
194                estimatedMinute: 20]
195        assert assignedPersonService.save(p).error == null
196        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
197        taskB.approved = true
198        taskB.save(flush:true)
199        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1
200
201        // Tasks assigned to a person via a group should be returned.
202        // But only if approved.
203        Person.get(2).addToPersonGroups(PersonGroup.read(1)).save(flush:true)
204        taskA.trash = false
205        taskA.approved = false
206        taskA.save(flush:true)
207        p = [personGroup: PersonGroup.read(1),
208                task: taskA,
209                estimatedHour: 2,
210                estimatedMinute: 30]
211        assert assignedGroupService.save(p).error == null
212        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1 // Only taskB from above.
213        taskA.approved = true
214        taskA.save(flush:true)
215        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 2 // taskA and taskB.
216
217    } // testGetPersonsTasks()
218
219} // end class
Note: See TracBrowser for help on using the repository browser.