2 * Copyright (C) 2017 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.
9 package eu
.etaxonomy
.cdm
.io
.owl
.out
;
12 import java
.io
.FileNotFoundException
;
13 import java
.util
.Collections
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.apache
.logging
.log4j
.LogManager
;
18 import org
.apache
.logging
.log4j
.Logger
;
19 import org
.junit
.Test
;
20 import org
.unitils
.dbunit
.annotation
.DataSet
;
21 import org
.unitils
.spring
.annotation
.SpringBeanByName
;
22 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITermTreeService
;
27 import eu
.etaxonomy
.cdm
.common
.URI
;
28 import eu
.etaxonomy
.cdm
.io
.common
.CdmApplicationAwareDefaultExport
;
29 import eu
.etaxonomy
.cdm
.io
.common
.ExportDataWrapper
;
30 import eu
.etaxonomy
.cdm
.io
.common
.ExportResult
;
31 import eu
.etaxonomy
.cdm
.io
.common
.IExportConfigurator
.TARGET
;
32 import eu
.etaxonomy
.cdm
.io
.descriptive
.owl
.out
.StructureTreeOwlExportConfigurator
;
33 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
34 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
35 import eu
.etaxonomy
.cdm
.model
.term
.TermNode
;
36 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
37 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
38 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
39 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
40 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
46 public class OwlExportTest
extends CdmTransactionalIntegrationTest
{
48 @SuppressWarnings("unused")
49 private static final Logger logger
= LogManager
.getLogger();
52 private CdmApplicationAwareDefaultExport
<StructureTreeOwlExportConfigurator
> defaultExport
;
55 private IClassificationService classificationService
;
58 private ITermTreeService termTreeService
;
61 private ITaxonNodeService taxonNodeService
;
65 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml")
66 public void testEmptyData(){
67 File destinationFolder
= null;
68 StructureTreeOwlExportConfigurator config
= StructureTreeOwlExportConfigurator
.NewInstance();
69 config
.setFeatureTreeUuids(createFeatureTree());
70 config
.setVocabularyUuids(Collections
.EMPTY_LIST
);
71 config
.setDestination(destinationFolder
);
72 config
.setTarget(TARGET
.EXPORT_DATA
);
73 ExportResult result
= defaultExport
.invoke(config
);
74 System
.out
.println(result
.createReport());
75 ExportDataWrapper
<?
> exportData
= result
.getExportData();
78 public List
<UUID
> createFeatureTree() {
79 TermTree
<Feature
> tree
= TermTree
.NewFeatureInstance();
80 TermVocabulary
<Feature
> voc
= TermVocabulary
.NewInstance(TermType
.Feature
, Feature
.class,
81 "voc description", "vocabulary", "voc", URI
.create("http://test.voc"));
83 Feature featureA
= Feature
.NewInstance("A", "A", "A");
84 voc
.addTerm(featureA
);
85 TermNode
<Feature
> nodeA
= tree
.getRoot().addChild(featureA
);
87 Feature featureA1
= Feature
.NewInstance("A1", "A1", "A1");
88 voc
.addTerm(featureA1
);
89 TermNode
<Feature
> nodeA1
= nodeA
.addChild(featureA1
);
91 Feature featureA2
= Feature
.NewInstance("A2", "A2", "A2");
92 voc
.addTerm(featureA2
);
93 TermNode
<Feature
> nodeA2
= nodeA
.addChild(featureA2
);
95 Feature featureB
= Feature
.NewInstance("B", "B", "B");
96 voc
.addTerm(featureB
);
97 TermNode
<Feature
> nodeB
= tree
.getRoot().addChild(featureB
);
99 Feature featureB1
= Feature
.NewInstance("B", "B1", "B1");
100 voc
.addTerm(featureB1
);
101 TermNode
<Feature
> nodeB1
= nodeB
.addChild(featureB1
);
103 Feature featureC
= Feature
.NewInstance("C", "C", "C");
104 voc
.addTerm(featureC
);
105 TermNode
<Feature
> nodeC
= tree
.getRoot().addChild(featureC
);
107 termTreeService
.save(tree
);
108 return Collections
.singletonList(tree
.getUuid());
112 public void createTestDataSet() throws FileNotFoundException
{
114 // writeDbUnitDataSetFile(new String[] {
116 // }, "testAttachDnaSampleToDerivedUnit");
117 // } catch (FileNotFoundException e) {
118 // e.printStackTrace();
123 private void setUuid(CdmBase cdmBase
, String uuidStr
) {
124 cdmBase
.setUuid(UUID
.fromString(uuidStr
));