Ignore:
Timestamp:
Dec 9, 2010, 9:12:10 PM (9 years ago)
Author:
robert@…
Message:

Added an export and import functionality for templates, as described in ticket #76

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/dbnp/studycapturing/TemplateTests.groovy

    r959 r1257  
    22
    33import grails.test.*
     4import dbnp.authentication.*
    45
    56class TemplateTests extends GrailsUnitTestCase {
     
    2728                assert t2.inUse();
    2829                assert !t3.inUse();
     30    }
     31
     32    void testContentEquals() {
     33                // Basic checks
     34                Template t1 = new Template( entity: dbnp.studycapturing.Subject );
     35                Template t2 = new Template( entity: dbnp.studycapturing.Subject );
     36                Template t3 = new Template( entity: dbnp.studycapturing.Study );
     37
     38                mockDomain( Template, [t1, t2, t3] );
     39
     40                assert t1.contentEquals( t1 );
     41                assert t1.contentEquals( t2 );
     42                assert t2.contentEquals( t1 );
     43                assert !t3.contentEquals( t1 );
     44                assert !t2.contentEquals( t3 );
     45
     46                // Check whether other fields matter
     47                t1.name = "Test 1";
     48                t1.description = "Long description"
     49                t1.owner = new SecUser( username: "TestUser" )
     50                t2.name = "Test 2";
     51                t2.description = "Short description"
     52
     53                assert( t1.contentEquals( t2 ) );
     54
     55                // Check whether the fields matter
     56                TemplateField tf1 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'Weight', type: TemplateFieldType.LONG,  unit: 'kg', comment: 'Weight field' )
     57                TemplateField tf2 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'Weight', type: TemplateFieldType.LONG,  unit: 'kg', comment: 'Weight field 2' )
     58                TemplateField tf3 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'Length', type: TemplateFieldType.LONG,  unit: 'm', comment: 'Length field' )
     59                TemplateField tf4 = new TemplateField( entity: dbnp.studycapturing.Subject, name: 'BMI', type: TemplateFieldType.LONG,  unit: 'kg/m2', comment: 'BMI field', required: true )
     60
     61                mockDomain( TemplateField, [tf1, tf2, tf3, tf4] );
     62
     63                t1.addToFields( tf1 );
     64                t2.addToFields( tf1 );
     65
     66                // Same fields
     67                assert( t1.contentEquals( t2 ) );
     68
     69                t1.fields.clear();
     70                t1.addToFields( tf2 );
     71
     72                // Fields with equal properties
     73                assert( t1.contentEquals( t2 ) );
     74
     75                t1.fields.clear();
     76                t1.addToFields( tf3 );
     77
     78                // Fields with inequal properties
     79                assert( !t1.contentEquals( t2 ) );
     80
     81                t1.addToFields( tf1 );
     82                t2.addToFields( tf3 );
     83
     84                // Same fields in different order
     85                assert( t1.contentEquals( t2 ) );
     86
     87                t1.addToFields( tf4 )
     88
     89                // Different number of fields
     90                assert( !t1.contentEquals( t2 ) );
    2991
    3092    }
     93
    3194}
Note: See TracChangeset for help on using the changeset viewer.