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

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

Remove stale testGetBudgetTasks.

File size: 8.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
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
[640]65
66        super.tearDown()
[511]67    }
68
[514]69
70    /**
71    * Test GetTasks.
72    */
[511]73    void testGetTasks() {
[514]74        // Todays tasks should be returned.
[511]75        def tasks = taskSearchService.getTasks([:])
76        assert tasks.totalCount == taskCount
77
78        // Tasks in the trash should not be returned.
[512]79        taskA.trash = true
80        taskA.save(flush:true)
[511]81        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
[512]82        taskB.trash = true
83        taskB.save(flush:true)
[511]84        assert taskSearchService.getTasks([:]).totalCount == taskCount - 2
85
86        // Restored tasks should be returned.
[512]87        taskA.trash = false
88        taskA.save(flush:true)
[511]89        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
[512]90        taskB.trash = false
91        taskB.save(flush:true)
[511]92        assert taskSearchService.getTasks([:]).totalCount == taskCount
93
94        // Tomorrows tasks should not be returned.
[512]95        taskA.targetStartDate = dateUtilService.tomorrow
96        taskA.targetCompletionDate = dateUtilService.tomorrow
97        taskA.save(flush:true)
[511]98        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
99
[512]100        // Tomorrows tasks should be returned, if we ask for them.
101        assert taskSearchService.getTasks([:], dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
102
[511]103        // Yesterdays tasks should not be returned.
[512]104        taskA.targetStartDate = dateUtilService.yesterday
105        taskA.targetCompletionDate = dateUtilService.yesterday
106        taskA.save(flush:true)
[511]107        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
108
[512]109        // Yesterdays tasks should be returned, if we ask for them.
110        assert taskSearchService.getTasks([:], dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
111
[511]112        // Tasks that span today should be returned.
[512]113        taskA.targetStartDate = dateUtilService.yesterday
114        taskA.targetCompletionDate = dateUtilService.tomorrow
115        taskA.save(flush:true)
[511]116        assert taskSearchService.getTasks([:]).totalCount == taskCount
117    } // testGetTasks()
118
[514]119    /**
120    * Test GetPersonsTasks.
121    */
122    void testGetPersonsTasks() {
123
124        def p = [:]
[529]125        def params = [:]
[514]126
127        // Todays tasks should be returned, since Person #1 is lead and created the tasks.
[529]128        def tasks = taskSearchService.getPersonsTasks(params)
[514]129        assert tasks.totalCount == taskCount
130
131        // Tasks in the trash should not be returned.
132        taskA.trash = true
133        taskA.save(flush:true)
[529]134        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]135        taskB.trash = true
136        taskB.save(flush:true)
[529]137        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 2
[514]138
139        // Restored tasks should be returned.
140        taskA.trash = false
141        taskA.save(flush:true)
[529]142        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]143        taskB.trash = false
144        taskB.save(flush:true)
[529]145        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount
[514]146
147        // Tomorrows tasks should not be returned.
148        taskA.targetStartDate = dateUtilService.tomorrow
149        taskA.targetCompletionDate = dateUtilService.tomorrow
150        taskA.save(flush:true)
[529]151        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]152
153        // Tomorrows tasks should be returned, if we ask for them.
[529]154        assert taskSearchService.getPersonsTasks(params, null, dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
[514]155
156        // Yesterdays tasks should not be returned.
157        taskA.targetStartDate = dateUtilService.yesterday
158        taskA.targetCompletionDate = dateUtilService.yesterday
159        taskA.save(flush:true)
[529]160        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]161
162        // Yesterdays tasks should be returned, if we ask for them.
[529]163        assert taskSearchService.getPersonsTasks(params, null, dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
[514]164
165        // Tasks that span today should be returned.
166        taskA.targetStartDate = dateUtilService.yesterday
167        taskA.targetCompletionDate = dateUtilService.tomorrow
168        taskA.save(flush:true)
[529]169        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount
[514]170
171        // Tasks for a different person should not be returned.
172        taskA.leadPerson = Person.get(2)
173        taskA.save(flush:true)
[529]174        assert taskSearchService.getPersonsTasks(params).totalCount == taskCount - 1
[514]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)
[529]180        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
[514]181        taskA.approved = true
182        taskA.save(flush:true)
[529]183        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1
[514]184        // Moving the task to the trash, stops it being returned.
185        taskA.trash = true
186        taskA.save(flush:true)
[529]187        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
[514]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
[529]196        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 0
[514]197        taskB.approved = true
198        taskB.save(flush:true)
[529]199        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1
[514]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
[529]212        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 1 // Only taskB from above.
[514]213        taskA.approved = true
214        taskA.save(flush:true)
[529]215        assert taskSearchService.getPersonsTasks(params, Person.get(2)).totalCount == 2 // taskA and taskB.
[514]216
[745]217    } // testGetPersonsTasks()
[514]218
[511]219} // end class
Note: See TracBrowser for help on using the repository browser.