2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.owl
.in
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertTrue
;
16 import java
.io
.FileNotFoundException
;
18 import java
.net
.URISyntaxException
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Arrays
;
22 import java
.util
.List
;
24 import org
.junit
.Before
;
25 import org
.junit
.Test
;
26 import org
.unitils
.dbunit
.annotation
.DataSet
;
27 import org
.unitils
.spring
.annotation
.SpringBeanByName
;
28 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
33 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
34 import eu
.etaxonomy
.cdm
.io
.common
.CdmApplicationAwareDefaultImport
;
35 import eu
.etaxonomy
.cdm
.io
.descriptive
.owl
.in
.StructureTreeOwlImportConfigurator
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
37 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
38 import eu
.etaxonomy
.cdm
.model
.term
.FeatureNode
;
39 import eu
.etaxonomy
.cdm
.model
.term
.FeatureTree
;
40 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
41 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
42 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
43 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
44 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
52 public class StructureTreeOwlImportTest
extends CdmTransactionalIntegrationTest
{
55 private CdmApplicationAwareDefaultImport
<?
> defaultImport
;
58 private ITermService termService
;
61 private IFeatureTreeService featureTreeService
;
64 private IVocabularyService vocabularyService
;
71 public void testInit() {
72 assertNotNull("import should not be null", defaultImport
);
76 @DataSet(value
="/eu/etaxonomy/cdm/database/BlankDataSet.xml")
77 public void testImportStructureTree() throws URISyntaxException
{
78 URL url
= this.getClass().getResource("/eu/etaxonomy/cdm/io/owl/in/test_structures.owl");
79 URI uri
= url
.toURI();
81 StructureTreeOwlImportConfigurator configurator
= StructureTreeOwlImportConfigurator
.NewInstance(uri
);
83 boolean result
= defaultImport
.invoke(configurator
).isSuccess();
84 assertTrue("Return value for import.invoke should be true", result
);
86 this.endTransaction();
88 String treeLabel
= "test_structures";
89 List
<FeatureTree
> trees
= featureTreeService
.listByTitle(FeatureTree
.class, treeLabel
, MatchMode
.EXACT
, null, null, null, null, null);
90 List
<String
> nodeProperties
= new ArrayList
<>();
91 nodeProperties
.add("term");
92 FeatureTree tree
= featureTreeService
.loadWithNodes(trees
.iterator().next().getUuid(), null, nodeProperties
);
93 assertNotNull("featureTree should not be null", tree
);
95 assertEquals("Tree has wrong term type", TermType
.Structure
, tree
.getTermType());
96 assertEquals("Wrong number of distinct features", 4, tree
.getDistinctFeatures().size());
97 List rootChildren
= tree
.getRootChildren();
98 assertEquals("Wrong number of root children", 1, rootChildren
.size());
99 Object entirePlant
= rootChildren
.iterator().next();
100 assertTrue("Root is no feature node", entirePlant
instanceof FeatureNode
);
101 assertEquals("Root node has wrong term type", TermType
.Structure
, ((FeatureNode
)entirePlant
).getTermType());
102 FeatureNode
<DefinedTerm
> entirePlantNode
= (FeatureNode
<DefinedTerm
>) entirePlant
;
103 List
<FeatureNode
<DefinedTerm
>> childNodes
= entirePlantNode
.getChildNodes();
104 assertEquals("Wrong number of children", 2, childNodes
.size());
106 String inflorescenceLabel
= "inflorescence";
107 String inflorescenceDescription
= " the part of the plant that bears the flowers, including all its bracts branches and flowers but excluding unmodified leaves ";
108 List
<DefinedTerm
> records
= termService
.findByRepresentationText(inflorescenceDescription
, DefinedTerm
.class, null, null).getRecords();
109 assertEquals("wrong number of terms found for \"inflorescence\"", 1, records
.size());
110 DefinedTerm inflorescence
= records
.iterator().next();
111 assertEquals(inflorescenceLabel
, inflorescence
.getLabel(Language
.ENGLISH()));
113 for (FeatureNode
<DefinedTerm
> featureNode
: childNodes
) {
114 assertTrue("Child node not found. Found node with term: "+featureNode
.getTerm().getLabel(),
115 featureNode
.getTerm().getUuid().equals(inflorescence
.getUuid())
116 || featureNode
.getTerm().getLabel(Language
.ENGLISH()).equals("Flower"));
117 if(featureNode
.getTerm().getUuid().equals(inflorescence
.getUuid())){
118 assertEquals("Term mismatch", inflorescence
, featureNode
.getTerm());
119 inflorescence
= featureNode
.getTerm();
121 assertEquals("wrong id in vocabulary", "inflorescence", inflorescence
.getIdInVocabulary());
122 assertEquals("wrong symbol", "infloSymbol", inflorescence
.getSymbol());
123 assertEquals("wrong symbol2", "infloSymbol2", inflorescence
.getSymbol2());
125 Representation englishRepresentation
= inflorescence
.getRepresentation(Language
.ENGLISH());
126 assertTrue("Description not found", CdmUtils
.isNotBlank(englishRepresentation
.getDescription()));
127 assertEquals("Description wrong", inflorescenceDescription
, englishRepresentation
.getDescription());
128 assertEquals("wrong plural", "inflorescences", englishRepresentation
.getPlural());
129 assertEquals("wrong label abbrev", "inflo", englishRepresentation
.getAbbreviatedLabel());
131 // german representation
132 assertEquals("wrong number of representations", 2, inflorescence
.getRepresentations().size());
133 Representation germanRepresentation
= inflorescence
.getRepresentation(Language
.GERMAN());
134 assertNotNull("Representation is null for "+Language
.GERMAN(), germanRepresentation
);
135 assertEquals("wrong description", "Der Teil der Pflanze, der die Bluete traegt", germanRepresentation
.getDescription());
136 assertEquals("wrong label", "Infloreszenz", germanRepresentation
.getLabel());
139 assertNotNull("term is null", inflorescence
);
140 assertEquals("Wrong term type", TermType
.Structure
, inflorescence
.getTermType());
142 String vocLabel
= "03 Generative Structures";
143 List
<TermVocabulary
> vocs
= vocabularyService
.findByTitle(TermVocabulary
.class, vocLabel
, MatchMode
.EXACT
, null, null, null, null, Arrays
.asList("terms")).getRecords();
144 assertEquals("wrong number of vocabularies", 1, vocs
.size());
145 TermVocabulary termVoc
= vocs
.iterator().next();
146 assertEquals("Wrong vocabulary label", vocLabel
, termVoc
.getTitleCache());
147 assertEquals(3, termVoc
.getTerms().size());
148 assertTrue("Term not included in vocabulary", termVoc
.getTerms().contains(inflorescence
));
154 @DataSet(value
="/eu/etaxonomy/cdm/database/BlankDataSet.xml")
155 public void testImportPropertyTreeAndVocabulary() throws URISyntaxException
{
156 URL url
= this.getClass().getResource("/eu/etaxonomy/cdm/io/owl/in/properties.owl");
157 URI uri
= url
.toURI();
159 StructureTreeOwlImportConfigurator configurator
= StructureTreeOwlImportConfigurator
.NewInstance(uri
);
161 boolean result
= defaultImport
.invoke(configurator
).isSuccess();
162 assertTrue("Return value for import.invoke should be true", result
);
164 this.endTransaction();
166 String treeLabel
= "properties 1.0";
167 List
<FeatureTree
> trees
= featureTreeService
.listByTitle(FeatureTree
.class, treeLabel
, MatchMode
.EXACT
, null, null, null, null, null);
168 List
<String
> nodeProperties
= new ArrayList
<>();
169 nodeProperties
.add("term");
170 FeatureTree tree
= featureTreeService
.loadWithNodes(trees
.iterator().next().getUuid(), null, nodeProperties
);
171 assertNotNull("featureTree should not be null", tree
);
173 assertEquals("Tree has wrong term type", TermType
.Property
, tree
.getTermType());
174 assertEquals("Wrong number of distinct features", 12, tree
.getDistinctFeatures().size());
175 List rootChildren
= tree
.getRootChildren();
177 String vocLabel
= "Plant Glossary Properties";
178 List
<TermVocabulary
> vocs
= vocabularyService
.findByTitle(TermVocabulary
.class, vocLabel
, MatchMode
.EXACT
, null, null, null, null, Arrays
.asList("terms")).getRecords();
179 assertEquals("wrong number of vocabularies", 1, vocs
.size());
180 TermVocabulary termVoc
= vocs
.iterator().next();
181 assertEquals("Wrong vocabulary label", vocLabel
, termVoc
.getTitleCache());
182 assertEquals(82, termVoc
.getTerms().size());
186 public void createTestDataSet() throws FileNotFoundException
{}