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

Last change on this file since 604 was 529, checked in by gav, 15 years ago

Tweak CreateDataService to prevent issues during testing.
Repair getBudgetTasks() search.
Complete testGetBudgetTasks() test.

File size: 10.1 KB
RevLine 
[511]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
[514]15    def assignedGroupService
16    def assignedPersonService
[511]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        super.tearDown()
58
59        taskService.delete(taskA)
60        taskService.delete(taskB)
61
62        // Ensure that we leave environment clean.
63        assert Task.count() == 0
64        assert TaskModification.count() == 0
65        assert Entry.count() == 0
66    }
67
[514]68
69    /**
70    * Test GetTasks.
71    */
[511]72    void testGetTasks() {
[514]73        // Todays tasks should be returned.
[511]74        def tasks = taskSearchService.getTasks([:])
75        assert tasks.totalCount == taskCount
76
77        // Tasks in the trash should not be returned.
[512]78        taskA.trash = true
79        taskA.save(flush:true)
[511]80        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
[512]81        taskB.trash = true
82        taskB.save(flush:true)
[511]83        assert taskSearchService.getTasks([:]).totalCount == taskCount - 2
84
85        // Restored tasks should be returned.
[512]86        taskA.trash = false
87        taskA.save(flush:true)
[511]88        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
[512]89        taskB.trash = false
90        taskB.save(flush:true)
[511]91        assert taskSearchService.getTasks([:]).totalCount == taskCount
92
93        // Tomorrows tasks should not be returned.
[512]94        taskA.targetStartDate = dateUtilService.tomorrow
95        taskA.targetCompletionDate = dateUtilService.tomorrow
96        taskA.save(flush:true)
[511]97        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
98
[512]99        // Tomorrows tasks should be returned, if we ask for them.
100        assert taskSearchService.getTasks([:], dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
101
[511]102        // Yesterdays tasks should not be returned.
[512]103        taskA.targetStartDate = dateUtilService.yesterday
104        taskA.targetCompletionDate = dateUtilService.yesterday
105        taskA.save(flush:true)
[511]106        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
107
[512]108        // Yesterdays tasks should be returned, if we ask for them.
109        assert taskSearchService.getTasks([:], dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
110
[511]111        // Tasks that span today should be returned.
[512]112        taskA.targetStartDate = dateUtilService.yesterday
113        taskA.targetCompletionDate = dateUtilService.tomorrow
114        taskA.save(flush:true)
[511]115        assert taskSearchService.getTasks([:]).totalCount == taskCount
116    } // testGetTasks()
117
[514]118    /**
119    * Test GetPersonsTasks.
120    */
121    void testGetPersonsTasks() {
122
123        def p = [:]
[529]124        def params = [:]
[514]125
126        // Todays tasks should be returned, since Person #1 is lead and created the tasks.
[529]127        def tasks = taskSearchService.getPersonsTasks(params)
[514]128        assert tasks.totalCount == taskCount
129
130        // Tasks in the trash should not be returned.
131        taskA.trash = true
132        taskA.save(flush:true)
[529]133        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]134        taskB.trash = true
135        taskB.save(flush:true)
[529]136        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 2
[514]137
138        // Restored tasks should be returned.
139        taskA.trash = false
140        taskA.save(flush:true)
[529]141        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]142        taskB.trash = false
143        taskB.save(flush:true)
[529]144        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount
[514]145
146        // Tomorrows tasks should not be returned.
147        taskA.targetStartDate = dateUtilService.tomorrow
148        taskA.targetCompletionDate = dateUtilService.tomorrow
149        taskA.save(flush:true)
[529]150        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]151
152        // Tomorrows tasks should be returned, if we ask for them.
[529]153        assert taskSearchService.getPersonsTasks(params, null, dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
[514]154
155        // Yesterdays tasks should not be returned.
156        taskA.targetStartDate = dateUtilService.yesterday
157        taskA.targetCompletionDate = dateUtilService.yesterday
158        taskA.save(flush:true)
[529]159        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]160
161        // Yesterdays tasks should be returned, if we ask for them.
[529]162        assert taskSearchService.getPersonsTasks(params, null, dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
[514]163
164        // Tasks that span today should be returned.
165        taskA.targetStartDate = dateUtilService.yesterday
166        taskA.targetCompletionDate = dateUtilService.tomorrow
167        taskA.save(flush:true)
[529]168        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount
[514]169
170        // Tasks for a different person should not be returned.
171        taskA.leadPerson = Person.get(2)
172        taskA.save(flush:true)
[529]173        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]174
175        // Tasks for a specified leadPerson should be returned.
176        // But only if approved since this person did not create the tasks.
177        taskA.leadPerson = Person.get(2)
178        taskA.save(flush:true)
[529]179        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
[514]180        taskA.approved = true
181        taskA.save(flush:true)
[529]182        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1
[514]183        // Moving the task to the trash, stops it being returned.
184        taskA.trash = true
185        taskA.save(flush:true)
[529]186        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
[514]187
188        // Tasks assigned to a person should be returned.
189        // But only if approved.
190        p = [person: Person.get(2),
191                task: taskB,
192                estimatedHour: 1,
193                estimatedMinute: 20]
194        assert assignedPersonService.save(p).error == null
[529]195        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
[514]196        taskB.approved = true
197        taskB.save(flush:true)
[529]198        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1
[514]199
200        // Tasks assigned to a person via a group should be returned.
201        // But only if approved.
202        Person.get(2).addToPersonGroups(PersonGroup.read(1)).save(flush:true)
203        taskA.trash = false
204        taskA.approved = false
205        taskA.save(flush:true)
206        p = [personGroup: PersonGroup.read(1),
207                task: taskA,
208                estimatedHour: 2,
209                estimatedMinute: 30]
210        assert assignedGroupService.save(p).error == null
[529]211        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1 // Only taskB from above.
[514]212        taskA.approved = true
213        taskA.save(flush:true)
[529]214        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 2 // taskA and taskB.
[514]215
216    } // testGetTasks()
217
[529]218    void testGetBudgetTasks() {
219
220        def tasks
221        def params = [:]
222        def today = dateUtilService.today
223        def yesterday = dateUtilService.yesterday
224        def tomorrow = dateUtilService.tomorrow
225        def unplanned = TaskBudgetStatus.read(1)
226        def planned = TaskBudgetStatus.read(2)
227
228        assert planned != null
229        assert unplanned != null
230
231        // Default is to return planned.
232        // TaskA and taskB should be unplanned and therefore not returned.
233        tasks = taskSearchService.getBudgetTasks(params)
234        assert tasks.totalCount == 0
235        tasks = taskSearchService.getBudgetTasks(params, planned)
236        assert tasks.totalCount == 0
237
238        tasks = taskSearchService.getBudgetTasks(params, unplanned)
239        assert tasks.totalCount == taskCount
240        assert tasks.contains(taskA)
241        assert tasks.contains(taskB)
242
243        // Planned tasks are returned.
244        taskA.taskBudgetStatus = planned
245        taskA.save(flush:true)
246        tasks = taskSearchService.getBudgetTasks(params, planned)
247        assert tasks.totalCount == 1
248        assert tasks.contains(taskA)
249
250        // Tasks are returned when dates and budget status are specified.
251        tasks = taskSearchService.getBudgetTasks(params, planned, today, tomorrow)
252        assert tasks.totalCount == 1
253        assert tasks.contains(taskA)
254        tasks = taskSearchService.getBudgetTasks(params, unplanned, today, tomorrow)
255        assert tasks.totalCount == 1
256        assert tasks.contains(taskB)
257
258        // No tasks for yesterday
259        tasks = taskSearchService.getBudgetTasks(params, null, yesterday, today)
260        assert tasks.totalCount == 0
261
262        // Tasks that span today are returned.
263        taskA.targetStartDate = yesterday
264        taskA.targetCompletionDate = tomorrow+2
265        taskA.save(flush:true)
266        tasks = taskSearchService.getBudgetTasks(params, planned, today, tomorrow)
267        assert tasks.totalCount == 1
268        assert tasks.contains(taskA)
269
270    } // testGetBudgetTasks()
271
[511]272} // end class
Note: See TracBrowser for help on using the repository browser.