root/trunk/test/unit/dbnp/studycapturing/TemplateTests.groovy @ 1433

Revision 1433, 2.9 KB (checked in by work@…, 3 years ago)

-fixed duplicate class 'RestControllerTests?'
-fixed imports for other tests, but probably several should move into gdt instead...

  • Property svn:keywords set to Rev Author Date
Line 
1package dbnp.studycapturing
2
3import grails.test.*
4import dbnp.authentication.*
5import nl.grails.plugins.gdt.*
6
7class TemplateTests extends GrailsUnitTestCase {
8    protected void setUp() {
9        super.setUp()
10    }
11
12    protected void tearDown() {
13        super.tearDown()
14    }
15
16    void testInUse() {
17                Template t1 = new Template( entity: dbnp.studycapturing.Subject );
18                Template t2 = new Template( entity: dbnp.studycapturing.Subject );
19                Template t3 = new Template( entity: dbnp.studycapturing.Subject );
20
21                Subject s1 = new Subject( template: t1 );
22                Subject s2 = new Subject( template: t1 );
23                Subject s3 = new Subject( template: t2 );
24
25                mockDomain(Template, [t1, t2, t3 ])
26                mockDomain(Subject, [ s1, s2, s3] )
27
28                assert t1.inUse();
29                assert t2.inUse();
30                assert !t3.inUse();
31    }
32
33    void testContentEquals() {
34                // Basic checks
35                Template t1 = new Template( entity: dbnp.studycapturing.Subject );
36                Template t2 = new Template( entity: dbnp.studycapturing.Subject );
37                Template t3 = new Template( entity: dbnp.studycapturing.Study );
38
39                mockDomain( Template, [t1, t2, t3] );
40
41                assert t1.contentEquals( t1 );
42                assert t1.contentEquals( t2 );
43                assert t2.contentEquals( t1 );
44                assert !t3.contentEquals( t1 );
45                assert !t2.contentEquals( t3 );
46
47                // Check whether other fields matter
48                t1.name = "Test 1";
49                t1.description = "Long description"
50                t1.owner = new SecUser( username: "TestUser" )
51                t2.name = "Test 2";
52                t2.description = "Short description"
53
54                assert( t1.contentEquals( t2 ) );
55
56                // Check whether the fields matter
57                TemplateField tf1 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'Weight', type: TemplateFieldType.LONG,  unit: 'kg', comment: 'Weight field' )
58                TemplateField tf2 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'Weight', type: TemplateFieldType.LONG,  unit: 'kg', comment: 'Weight field 2' )
59                TemplateField tf3 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'Length', type: TemplateFieldType.LONG,  unit: 'm', comment: 'Length field' )
60                TemplateField tf4 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'BMI', type: TemplateFieldType.LONG,  unit: 'kg/m2', comment: 'BMI field', required: true )
61
62                mockDomain( TemplateField, [tf1, tf2, tf3, tf4] );
63
64                t1.addToFields( tf1 );
65                t2.addToFields( tf1 );
66
67                // Same fields
68                assert( t1.contentEquals( t2 ) );
69
70                t1.fields.clear();
71                t1.addToFields( tf2 );
72
73                // Fields with equal properties
74                assert( t1.contentEquals( t2 ) );
75
76                t1.fields.clear();
77                t1.addToFields( tf3 );
78
79                // Fields with inequal properties
80                assert( !t1.contentEquals( t2 ) );
81
82                t1.addToFields( tf1 );
83                t2.addToFields( tf3 );
84
85                // Same fields in different order
86                assert( t1.contentEquals( t2 ) );
87
88                t1.addToFields( tf4 )
89
90                // Different number of fields
91                assert( !t1.contentEquals( t2 ) );
92
93    }
94
95}
Note: See TracBrowser for help on using the browser.