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

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

Adding an entry to a task with no time booked will now leave the task as "Not Started".
Reopening a task will check if the task should be "In Progress" or "Not Started".
Added integration tests for above.
Added TaskService.delete() since it is required for integration tests.

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        super.tearDown()
55
56        taskService.delete(taskA)
57        taskService.delete(taskB)
58
59        // Ensure that we leave environment clean.
60        assert Task.count() == 0
61        assert TaskModification.count() == 0
62        assert Entry.count() == 0
63    }
64
65    def testSave() {
66
67        // Task are created by setUp().
68        assert Task.count() == taskCount
69
70        taskA.refresh()
71        assert taskA.taskModifications.size() == 1
72        assert taskA.taskModifications.each() {
73            it.taskModificationType.id == 1 // Created.
74        }
75
76        taskB.refresh()
77        assert taskB.taskModifications.size() == 1
78        assert taskB.taskModifications.each() {
79            it.taskModificationType.id == 1 // Created.
80        }
81
82    } // testSave()
83
84    void testComplete() {
85
86        def modificationCount = 0
87
88        taskA.refresh()
89        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
90        assert taskA.taskModifications.size() == ++modificationCount
91
92        taskService.complete(taskA)
93        taskA.refresh()
94        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
95        assert taskA.taskModifications.size() == ++modificationCount
96
97    } // testComplete()
98
99    void testReopen() {
100
101        def entryParams = [:]
102        def modificationCount = 0
103
104        taskA.refresh()
105        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
106        assert taskA.taskModifications.size() == ++modificationCount
107
108        taskService.complete(taskA)
109        taskA.refresh()
110        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
111        assert taskA.taskModifications.size() == ++modificationCount
112
113        taskService.reopen(taskA)
114        taskA.refresh()
115        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
116        assert taskA.taskModifications.size() == ++modificationCount
117
118        // Work Done Entry, with zero time booked.
119        entryParams = [task: taskA,
120                                        entryType: EntryType.read(3),
121                                        comment: "Test entry.",
122                                        durationHour: 0,
123                                        durationMinute: 0]
124
125        assert taskService.saveEntry(entryParams).error == null
126
127        taskService.complete(taskA)
128        taskA.refresh()
129        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
130        assert taskA.taskModifications.size() == ++modificationCount
131
132        taskService.reopen(taskA)
133        taskA.refresh()
134        assert taskA.taskStatus ==  TaskStatus.read(1) // Not Started.
135        assert taskA.taskModifications.size() == ++modificationCount
136
137        // Work Done Entry, with time booked.
138        entryParams.durationMinute = 1
139        assert taskService.saveEntry(entryParams).error == null
140        taskA.refresh()
141        assert taskA.taskStatus ==  TaskStatus.read(2) // In Progress.
142        assert taskA.taskModifications.size() == ++modificationCount
143
144        taskService.complete(taskA)
145        taskA.refresh()
146        assert taskA.taskStatus ==  TaskStatus.read(3) // Complete.
147        assert taskA.taskModifications.size() == ++modificationCount
148
149        taskService.reopen(taskA)
150        taskA.refresh()
151        assert taskA.taskStatus ==  TaskStatus.read(2) // In Progress.
152        assert taskA.taskModifications.size() == ++modificationCount
153
154    } // testReopen()
155
156} // end class
Note: See TracBrowser for help on using the repository browser.