source: trunk/test/integration/TaskServiceTests.groovy @ 680

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

Small adjustment to TaskSearchServiceTests and TaskServiceTests tearDown().

File size: 4.7 KB
Line 
1import grails.test.*
2
3/**
4* Integration tests for TaskService.
5*/
6class TaskServiceTests 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
15    def taskA
16    def taskB
17    def taskCount = 0
18
19    // Setup is called before each test.
20    protected void setUp() {
21        super.setUp()
22
23        // Check environment state.
24        assert Task.count() == 0
25        assert Entry.count() == 0
26        assert TaskModification.count() == 0
27
28        def p = [:]
29        def result
30
31        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
32                taskPriority:TaskPriority.get(2),
33                taskType:TaskType.get(1),
34                leadPerson:Person.get(1),
35                description:"TestA",
36                comment:"Service test task.",
37                targetStartDate: dateUtilService.today,
38                targetCompletionDate: dateUtilService.today]
39
40        result = taskService.save(p)
41        assert result.error == null
42        taskCount++
43        taskA = result.taskInstance.refresh()
44
45        p.description = "TestB"
46        result = taskService.save(p)
47        assert result.error == null
48        taskCount++
49        taskB = result.taskInstance.refresh()
50    }
51
52    // Tear down is called after each test.
53    protected void tearDown() {
54
55        taskService.delete(taskA)
56        taskService.delete(taskB)
57
58        // Ensure that we leave environment clean.
59        assert Task.count() == 0
60        assert TaskModification.count() == 0
61        assert Entry.count() == 0
62
63        super.tearDown()
64    }
65
66    def testSave() {
67
68        // Task are created by setUp().
69        assert Task.count() == taskCount
70
71        taskA.refresh()
72        assert taskA.taskModifications.size() == 1
73        assert taskA.taskModifications.each() {
74            it.taskModificationType.id == 1 // Created.
75        }
76
77        taskB.refresh()
78        assert taskB.taskModifications.size() == 1
79        assert taskB.taskModifications.each() {
80            it.taskModificationType.id == 1 // Created.
81        }
82
83    } // testSave()
84
85    void testComplete() {
86
87        def modificationCount = 0
88
89        taskA.refresh()
90        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
91        assert taskA.taskModifications.size() == ++modificationCount
92
93        taskService.complete(taskA)
94        taskA.refresh()
95        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
96        assert taskA.taskModifications.size() == ++modificationCount
97
98    } // testComplete()
99
100    void testReopen() {
101
102        def entryParams = [:]
103        def modificationCount = 0
104
105        taskA.refresh()
106        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
107        assert taskA.taskModifications.size() == ++modificationCount
108
109        taskService.complete(taskA)
110        taskA.refresh()
111        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
112        assert taskA.taskModifications.size() == ++modificationCount
113
114        taskService.reopen(taskA)
115        taskA.refresh()
116        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
117        assert taskA.taskModifications.size() == ++modificationCount
118
119        // Work Done Entry, with zero time booked.
120        entryParams = [task: taskA,
121                                        entryType: EntryType.read(3),
122                                        comment: "Test entry.",
123                                        durationHour: 0,
124                                        durationMinute: 0]
125
126        assert taskService.saveEntry(entryParams).error == null
127
128        taskService.complete(taskA)
129        taskA.refresh()
130        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
131        assert taskA.taskModifications.size() == ++modificationCount
132
133        taskService.reopen(taskA)
134        taskA.refresh()
135        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
136        assert taskA.taskModifications.size() == ++modificationCount
137
138        // Work Done Entry, with time booked.
139        entryParams.durationMinute = 1
140        assert taskService.saveEntry(entryParams).error == null
141        taskA.refresh()
142        assert taskA.taskStatus ==  TaskStatus.read(2) // In Progress.
143        assert taskA.taskModifications.size() == ++modificationCount
144
145        taskService.complete(taskA)
146        taskA.refresh()
147        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
148        assert taskA.taskModifications.size() == ++modificationCount
149
150        taskService.reopen(taskA)
151        taskA.refresh()
152        assert taskA.taskStatus ==  TaskStatus.read(2) // In Progress.
153        assert taskA.taskModifications.size() == ++modificationCount
154
155    } // testReopen()
156
157} // end class
Note: See TracBrowser for help on using the repository browser.