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

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

Small adjustment to TaskSearchServiceTests and TaskServiceTests tearDown().

File size: 10.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    } // testGetTasks()
218
219    void testGetBudgetTasks() {
220
221        def tasks
222        def params = [:]
223        def today = dateUtilService.today
224        def yesterday = dateUtilService.yesterday
225        def tomorrow = dateUtilService.tomorrow
226        def unplanned = TaskBudgetStatus.read(1)
227        def planned = TaskBudgetStatus.read(2)
228
229        assert planned != null
230        assert unplanned != null
231
232        // Default is to return planned.
233        // TaskA and taskB should be unplanned and therefore not returned.
234        tasks = taskSearchService.getBudgetTasks(params)
235        assert tasks.totalCount == 0
236        tasks = taskSearchService.getBudgetTasks(params, planned)
237        assert tasks.totalCount == 0
238
239        tasks = taskSearchService.getBudgetTasks(params, unplanned)
240        assert tasks.totalCount == taskCount
241        assert tasks.contains(taskA)
242        assert tasks.contains(taskB)
243
244        // Planned tasks are returned.
245        taskA.taskBudgetStatus = planned
246        taskA.save(flush:true)
247        tasks = taskSearchService.getBudgetTasks(params, planned)
248        assert tasks.totalCount == 1
249        assert tasks.contains(taskA)
250
251        // Tasks are returned when dates and budget status are specified.
252        tasks = taskSearchService.getBudgetTasks(params, planned, today, tomorrow)
253        assert tasks.totalCount == 1
254        assert tasks.contains(taskA)
255        tasks = taskSearchService.getBudgetTasks(params, unplanned, today, tomorrow)
256        assert tasks.totalCount == 1
257        assert tasks.contains(taskB)
258
259        // No tasks for yesterday
260        tasks = taskSearchService.getBudgetTasks(params, null, yesterday, today)
261        assert tasks.totalCount == 0
262
263        // Tasks that span today are returned.
264        taskA.targetStartDate = yesterday
265        taskA.targetCompletionDate = tomorrow+2
266        taskA.save(flush:true)
267        tasks = taskSearchService.getBudgetTasks(params, planned, today, tomorrow)
268        assert tasks.totalCount == 1
269        assert tasks.contains(taskA)
270
271    } // testGetBudgetTasks()
272
273} // end class
Note: See TracBrowser for help on using the repository browser.