1 | package gscf |
---|
2 | |
---|
3 | import grails.test.* |
---|
4 | import dbnp.data.* |
---|
5 | |
---|
6 | /** |
---|
7 | * OntologyTests Test |
---|
8 | * |
---|
9 | * Test ontology/term functionality on domain model level |
---|
10 | * |
---|
11 | * @author keesvb |
---|
12 | * @since 20100510 |
---|
13 | * @package dbnp.studycapturing |
---|
14 | * |
---|
15 | * Revision information: |
---|
16 | * $Rev$ |
---|
17 | * $Author$ |
---|
18 | * $Date$ |
---|
19 | */ |
---|
20 | class OntologyTests extends GrailsUnitTestCase { |
---|
21 | |
---|
22 | final String testOntologyName = "Test ontology" |
---|
23 | final String testOntologyDescription = "Test description" |
---|
24 | final String testOntologyUrl = "http://www.test.com" |
---|
25 | final String testOntologyVersionNumber = "1.0" |
---|
26 | final int testOntologyNcboId = 0 |
---|
27 | final int testOntologyNcboVersionedId = 0 |
---|
28 | final String testTermName = "Test term" |
---|
29 | final String testAccession = 'TEST01234$' |
---|
30 | |
---|
31 | protected void setUp() { |
---|
32 | super.setUp() |
---|
33 | } |
---|
34 | |
---|
35 | protected void tearDown() { |
---|
36 | super.tearDown() |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * Test creation and saving of ontologies and terms |
---|
41 | * and giveTerms and giveTermByName methods |
---|
42 | */ |
---|
43 | void testAll () { |
---|
44 | |
---|
45 | // === TEST Ontology |
---|
46 | |
---|
47 | def ontology = new Ontology( |
---|
48 | name: testOntologyName, |
---|
49 | description: testOntologyDescription, |
---|
50 | url: testOntologyUrl, |
---|
51 | versionNumber: testOntologyVersionNumber, |
---|
52 | ncboId: testOntologyNcboId, |
---|
53 | ncboVersionedId: testOntologyNcboVersionedId |
---|
54 | ); |
---|
55 | |
---|
56 | // Validate and save ontology |
---|
57 | assert ontology.validate() |
---|
58 | assert ontology.save(flush:true) |
---|
59 | |
---|
60 | // Try to retrieve the ontology and make sure it's the same |
---|
61 | def ontologyDB = Ontology.findByName(testOntologyName) |
---|
62 | assert ontologyDB |
---|
63 | assert ontologyDB.name.equals(testOntologyName) |
---|
64 | assert ontologyDB.description.equals(testOntologyDescription) |
---|
65 | assert ontologyDB.url.equals(testOntologyUrl) |
---|
66 | assert ontologyDB.versionNumber.equals(testOntologyVersionNumber) |
---|
67 | assert ontologyDB.ncboId.equals(testOntologyNcboId) |
---|
68 | assert ontologyDB.ncboVersionedId.equals(testOntologyNcboVersionedId) |
---|
69 | |
---|
70 | // Apparently, the saved ontology is not persisted between test methods :-( |
---|
71 | // Otherwise, we could separate these parts into different tests |
---|
72 | |
---|
73 | // === TEST Term and giveTermByName |
---|
74 | |
---|
75 | // Find created ontology |
---|
76 | def testOntology = Ontology.findByName(testOntologyName) |
---|
77 | assert testOntology |
---|
78 | |
---|
79 | // Create a new term |
---|
80 | def term = new Term( |
---|
81 | name: testTermName, |
---|
82 | accession: testAccession, |
---|
83 | ontology: testOntology |
---|
84 | ) |
---|
85 | |
---|
86 | assert term.validate() |
---|
87 | assert term.save(flush:true) |
---|
88 | |
---|
89 | // Try to retrieve the term from the ontology and make sure it's the same |
---|
90 | def termDB = testOntology.giveTermByName(testTermName) |
---|
91 | assert termDB.name.equals(testTermName) |
---|
92 | assert termDB.accession.equals(testAccession) |
---|
93 | assert termDB.ontology == testOntology |
---|
94 | |
---|
95 | // === TEST giveTerms |
---|
96 | |
---|
97 | def terms = testOntology.giveTerms() |
---|
98 | assert terms |
---|
99 | assert terms.size() == 1 |
---|
100 | assert terms.asList().first().name.equals(testTermName) |
---|
101 | |
---|
102 | } |
---|
103 | } |
---|