Merge branch 'develop' of ssh://dev.e-taxonomy.eu/var/git/cdmlib into develop
[cdmlib.git] / cdmlib-io / src / test / java / eu / etaxonomy / cdm / io / owl / in / StructureTreeOwlImportTest.java
index 73883ba4989f9209214029fbc7cf2e217361b5dc..8cf25ecc4f1ef2eab60f3b27b5f7117cb1aadec3 100644 (file)
@@ -20,6 +20,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -33,8 +34,14 @@ import eu.etaxonomy.cdm.api.service.IVocabularyService;
 import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
 import eu.etaxonomy.cdm.io.descriptive.owl.in.StructureTreeOwlImportConfigurator;
+import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
+import eu.etaxonomy.cdm.model.media.MediaUtils;
+import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
 import eu.etaxonomy.cdm.model.term.DefinedTerm;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
 import eu.etaxonomy.cdm.model.term.FeatureNode;
 import eu.etaxonomy.cdm.model.term.FeatureTree;
 import eu.etaxonomy.cdm.model.term.Representation;
@@ -89,6 +96,7 @@ public class StructureTreeOwlImportTest extends CdmTransactionalIntegrationTest
         List<FeatureTree> trees = featureTreeService.listByTitle(FeatureTree.class, treeLabel, MatchMode.EXACT, null, null, null, null, null);
         List<String> nodeProperties = new ArrayList<>();
         nodeProperties.add("term");
+        nodeProperties.add("term.media");
         FeatureTree tree = featureTreeService.loadWithNodes(trees.iterator().next().getUuid(), null, nodeProperties);
         assertNotNull("featureTree should not be null", tree);
 
@@ -122,9 +130,19 @@ public class StructureTreeOwlImportTest extends CdmTransactionalIntegrationTest
                 assertEquals("wrong symbol", "infloSymbol", inflorescence.getSymbol());
                 assertEquals("wrong symbol2", "infloSymbol2", inflorescence.getSymbol2());
 
-                String englishDescription = inflorescence.getDescription(Language.ENGLISH());
-                assertTrue("Description not found", CdmUtils.isNotBlank(englishDescription));
-                assertEquals("Description wrong", inflorescenceDescription, englishDescription);
+                Set<Media> mediaSet = inflorescence.getMedia();
+                assertEquals("wrong number of media", 1, mediaSet.size());
+                Media media = mediaSet.iterator().next();
+                MediaRepresentationPart part = MediaUtils.getFirstMediaRepresentationPart(media);
+                assertNotNull("media part not found", part);
+                assertEquals("incorrect URI", URI.create("https://upload.wikimedia.org/wikipedia/commons/8/82/Aloe_hereroensis_Auob_C15.JPG"), part.getUri());
+                assertEquals("incorrect title", "Aloe hereroensis", media.getTitle(Language.DEFAULT()).getText());
+
+                Representation englishRepresentation = inflorescence.getRepresentation(Language.ENGLISH());
+                assertTrue("Description not found", CdmUtils.isNotBlank(englishRepresentation.getDescription()));
+                assertEquals("Description wrong", inflorescenceDescription, englishRepresentation.getDescription());
+                assertEquals("wrong plural", "inflorescences", englishRepresentation.getPlural());
+                assertEquals("wrong label abbrev", "inflo", englishRepresentation.getAbbreviatedLabel());
 
                 // german representation
                 assertEquals("wrong number of representations", 2, inflorescence.getRepresentations().size());
@@ -179,6 +197,16 @@ public class StructureTreeOwlImportTest extends CdmTransactionalIntegrationTest
         assertEquals("Wrong vocabulary label", vocLabel, termVoc.getTitleCache());
         assertEquals(82, termVoc.getTerms().size());
 
+        Set<DefinedTermBase> terms = termVoc.getTerms();
+        for (DefinedTermBase definedTermBase : terms) {
+            List<String> termProperties = new ArrayList<>();
+            termProperties.add("sources");
+            definedTermBase = termService.load(definedTermBase.getUuid(), termProperties);
+            Set<IdentifiableSource> sources = definedTermBase.getSources();
+            assertTrue("Import source is missing for term: "+definedTermBase, !sources.isEmpty());
+            assertTrue("import source type not found", sources.stream().anyMatch(source->OriginalSourceType.Import.getKey().equals(source.getType().getKey())));
+        }
+
     }
     @Override
     public void createTestDataSet() throws FileNotFoundException {}