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

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

Refactor TaskSearchService.getTasks() to use HQL and avoid bug in ticket #64, also extend associated tests.

File size: 3.7 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
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.
[512]72        taskA.trash = true
73        taskA.save(flush:true)
[511]74        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
[512]75        taskB.trash = true
76        taskB.save(flush:true)
[511]77        assert taskSearchService.getTasks([:]).totalCount == taskCount - 2
78
79        // Restored tasks should be returned.
[512]80        taskA.trash = false
81        taskA.save(flush:true)
[511]82        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
[512]83        taskB.trash = false
84        taskB.save(flush:true)
[511]85        assert taskSearchService.getTasks([:]).totalCount == taskCount
86
87        // Tomorrows tasks should not be returned.
[512]88        taskA.targetStartDate = dateUtilService.tomorrow
89        taskA.targetCompletionDate = dateUtilService.tomorrow
90        taskA.save(flush:true)
[511]91        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
92
[512]93        // Tomorrows tasks should be returned, if we ask for them.
94        assert taskSearchService.getTasks([:], dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount
95
[511]96        // Yesterdays tasks should not be returned.
[512]97        taskA.targetStartDate = dateUtilService.yesterday
98        taskA.targetCompletionDate = dateUtilService.yesterday
99        taskA.save(flush:true)
[511]100        assert taskSearchService.getTasks([:]).totalCount == taskCount - 1
101
[512]102        // Yesterdays tasks should be returned, if we ask for them.
103        assert taskSearchService.getTasks([:], dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount
104
[511]105        // Tasks that span today should be returned.
[512]106        taskA.targetStartDate = dateUtilService.yesterday
107        taskA.targetCompletionDate = dateUtilService.tomorrow
108        taskA.save(flush:true)
[511]109        assert taskSearchService.getTasks([:]).totalCount == taskCount
110    } // testGetTasks()
111
112} // end class
Note: See TracBrowser for help on using the repository browser.