1 | import grails.test.* |
---|
2 | |
---|
3 | /** |
---|
4 | * Integration tests for CreateDataService. |
---|
5 | */ |
---|
6 | class CreateDataServiceTests extends GroovyTestCase { |
---|
7 | |
---|
8 | def appConfigService |
---|
9 | def createDataService |
---|
10 | |
---|
11 | // Setup is called before each test and any data saved is discarded after each test. |
---|
12 | protected void setUp() { |
---|
13 | super.setUp() |
---|
14 | } |
---|
15 | |
---|
16 | protected void tearDown() { |
---|
17 | super.tearDown() |
---|
18 | } |
---|
19 | |
---|
20 | void testBaseDataCreated() { |
---|
21 | |
---|
22 | // Base data should have been created during bootstrap. |
---|
23 | assertTrue appConfigService.exists("baseDataCreated") |
---|
24 | |
---|
25 | // Some base data has indeed been created. |
---|
26 | assert PersonGroupType.count() > 0 |
---|
27 | |
---|
28 | } // testBaseDataCreated() |
---|
29 | |
---|
30 | void testCreateBaseData() { |
---|
31 | |
---|
32 | // Base data has already been created in bootstrap, |
---|
33 | // therefore simply running this will create a host of unique constraint errors |
---|
34 | // if the method does not exit at the correct point and return false. |
---|
35 | assertFalse createDataService.createBaseData() |
---|
36 | |
---|
37 | } // testCreateBaseData() |
---|
38 | |
---|
39 | void testCreateDemoData() { |
---|
40 | |
---|
41 | def taskCount |
---|
42 | |
---|
43 | // No demo tasks yet. |
---|
44 | taskCount = Task.count() |
---|
45 | assert taskCount == 0 |
---|
46 | |
---|
47 | // Base data has already been created in bootstrap so |
---|
48 | // demo data creation should go forward. |
---|
49 | assertTrue createDataService.createDemoData() |
---|
50 | |
---|
51 | // Should now have some demo tasks. |
---|
52 | taskCount = Task.count() |
---|
53 | assert taskCount > 0 |
---|
54 | |
---|
55 | // Returns false since demo data has already been created. |
---|
56 | assertFalse createDataService.createDemoData() |
---|
57 | |
---|
58 | // Task count should not have changed. |
---|
59 | assert Task.count() == taskCount |
---|
60 | |
---|
61 | } // testCreateDemoData() |
---|
62 | |
---|
63 | void testDemoDataCreationDisabled() { |
---|
64 | |
---|
65 | def taskCount |
---|
66 | |
---|
67 | // No demo tasks yet. |
---|
68 | taskCount = Task.count() |
---|
69 | assert taskCount == 0 |
---|
70 | |
---|
71 | appConfigService.set("demoDataCreationDisabled") |
---|
72 | |
---|
73 | // False since demo data creation has disabled. |
---|
74 | assertFalse createDataService.createDemoData() |
---|
75 | |
---|
76 | // Still no demo tasks. |
---|
77 | taskCount = Task.count() |
---|
78 | assert taskCount == 0 |
---|
79 | |
---|
80 | } // testDemoDataCreationDisabled() |
---|
81 | |
---|
82 | void testCreateDemoDataWithNoBaseData() { |
---|
83 | |
---|
84 | def taskCount |
---|
85 | |
---|
86 | // No demo tasks yet. |
---|
87 | taskCount = Task.count() |
---|
88 | assert taskCount == 0 |
---|
89 | |
---|
90 | // Base data has already been created in bootstrap so |
---|
91 | // simulate base data not created. |
---|
92 | assertTrue appConfigService.delete("baseDataCreated") |
---|
93 | |
---|
94 | // Returns false since demo data creation has not been recorded. |
---|
95 | assertFalse createDataService.createDemoData() |
---|
96 | |
---|
97 | // Still no demo tasks. |
---|
98 | taskCount = Task.count() |
---|
99 | assert taskCount == 0 |
---|
100 | |
---|
101 | } // testCreateDemoDataWithNoBaseData() |
---|
102 | |
---|
103 | } // end class |
---|