source: trunk/test/unit/dbnp/studycapturing/StudyTests.groovy @ 536

Last change on this file since 536 was 536, checked in by roberth, 12 years ago

Samples are now shown in the study overview page. Also some tests are added and the bootstrap is updated to show some sample fields with a template

  • Property svn:keywords set to Date Author Rev
File size: 2.0 KB
Line 
1package dbnp.studycapturing
2
3import grails.test.*
4import groovy.util.GroovyTestCase
5class StudyTests extends GrailsUnitTestCase {
6    protected void setUp() {
7        super.setUp()
8    }
9
10    protected void tearDown() {
11        super.tearDown()
12    }
13
14    protected void assertCollectionEquals( Collection set1, Collection set2 ) {
15        set1.each {
16            assert it in set2;
17        }
18        set2.each {
19            assert it in set1;
20        }
21
22    }
23
24    void testGetOrphanEvents() {
25        def events = [];
26        10.times {
27            events[ it ] = new Event(
28                id: it,
29                startTime: 3600,
30                endTime: 3800
31            )
32            println( 'Created event ' + it );
33        }
34        def evGroup1 = new EventGroup(
35            name: 'group1',
36            events: events[0..4]
37        )
38        def evGroup2 = new EventGroup(
39            name: 'group2',
40            events: events[3..6]
41        )
42
43        // No events should give no orphan events
44        def study1 = new Study( title: 'Studytitle 1', events: [], eventGroups: [] );
45        assert study1.getOrphanEvents().size() == 0;
46
47        // Not even with a group
48        study1.eventGroups = [ evGroup1 ];
49        assert study1.getOrphanEvents().size() == 0;
50
51        // Events 0..4 are part of evGroup1
52        study1.events = events[0..8];
53        println(  study1.getOrphanEvents().id )
54        println(  events[ 5..8].id )
55       
56        assertCollectionEquals( study1.getOrphanEvents(), events[ 5..8 ] );
57
58        // Remove the evGroup
59        study1.eventGroups = [];
60        assertCollectionEquals( study1.getOrphanEvents(), events[ 0..8 ] );
61
62        // Add multiple groups
63        study1.eventGroups = [ evGroup1, evGroup2 ];
64        assertCollectionEquals( study1.getOrphanEvents(), events[ 7..8 ] );
65
66        // Remove events again
67        study1.events = [];
68        assert study1.getOrphanEvents().size() == 0;
69    }
70}
Note: See TracBrowser for help on using the repository browser.