2 * Copyright (C) 2018 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
.api
.service
.dto
;
11 import java
.util
.List
;
13 import org
.junit
.Assert
;
14 import org
.junit
.Before
;
15 import org
.junit
.BeforeClass
;
16 import org
.junit
.Test
;
18 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonRelationshipsDTO
.TaxonRelation
;
19 import eu
.etaxonomy
.cdm
.format
.taxon
.TaxonRelationshipFormatter
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
23 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
.Direction
;
24 import eu
.etaxonomy
.cdm
.model
.common
.VerbatimTimePeriod
;
25 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
27 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
33 import eu
.etaxonomy
.cdm
.strategy
.cache
.TaggedText
;
34 import eu
.etaxonomy
.cdm
.strategy
.parser
.TimePeriodParser
;
41 public class TaxonRelationshipsDTOTest
{
42 private TaxonRelationship taxonRel
;
43 private Reference relSec
;
45 private Taxon fromTaxon
;
46 private TaxonName fromName
;
47 private Reference fromSec
;
49 private Taxon toTaxon
;
50 private TaxonName toName
;
51 private Reference toSec
;
53 private TaxonRelationshipFormatter formatter
;
54 private boolean reverse
;
57 private List
<Language
> languages
;
60 * @throws java.lang.Exception
63 public static void setUpBeforeClass() throws Exception
{
64 if (Language
.DEFAULT() == null){
65 new DefaultTermInitializer().initialize();
70 * @throws java.lang.Exception
73 public void setUp() throws Exception
{
74 fromName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
75 fromName
.setGenusOrUninomial("Abies");
76 fromName
.setSpecificEpithet("alba");
78 toName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
79 toName
.setGenusOrUninomial("Pinus");
80 toName
.setSpecificEpithet("pinova");
81 toNameAuthor
= Person
.NewInstance("Mill.", "Miller", "A.", "Andrew");
82 toName
.setCombinationAuthorship(toNameAuthor
);
84 fromSec
= ReferenceFactory
.newGeneric();
85 fromSec
.setTitle("From Sec");
86 String initials
= "J.M.";
87 fromSec
.setAuthorship(Person
.NewInstance(null, "Macfarlane", initials
, null));
88 fromSec
.setDatePublished(VerbatimTimePeriod
.NewVerbatimInstance(1918));
90 relSec
= ReferenceFactory
.newGeneric();
91 relSec
.setTitle("From rel reference");
92 initials
= null; //"M.R.";
93 relSec
.setAuthorship(Person
.NewInstance(null, "Cheek", initials
, null));
94 relSec
.setDatePublished(VerbatimTimePeriod
.NewVerbatimInstance(1919));
96 toSec
= ReferenceFactory
.newGeneric();
97 toSec
.setTitle("To Sec");
98 toSec
.setAuthorship(Person
.NewTitledInstance("ToSecAuthor"));
99 toSec
.setDatePublished(VerbatimTimePeriod
.NewVerbatimInstance(1928));
101 fromTaxon
= Taxon
.NewInstance(fromName
, fromSec
);
102 toTaxon
= Taxon
.NewInstance(toName
, toSec
);
104 TaxonRelationshipType type
= TaxonRelationshipType
.MISAPPLIED_NAME_FOR();
105 taxonRel
= fromTaxon
.addTaxonRelation(toTaxon
, type
, relSec
, "123");
108 formatter
= new TaxonRelationshipFormatter();
115 Reference sec2
= ReferenceFactory
.newGeneric();
116 sec2
.setAuthorship(Person
.NewInstance("Mue.", "Mueller", "I.", "Inger"));
117 sec2
.setDatePublished(TimePeriodParser
.parseStringVerbatim("1987"));
118 Taxon from2
= Taxon
.NewInstance(fromName
, sec2
);
119 TaxonRelationship rel2
= toTaxon
.addMisappliedName(from2
, sec2
, "333");
120 //same as rel1 except for sec
121 TaxonRelationship rel3
= toTaxon
.addMisappliedName(from2
, taxonRel
.getCitation(), taxonRel
.getCitationMicroReference());
123 TaxonRelationshipsDTO dto
= new TaxonRelationshipsDTO();
125 dto
.addRelation(taxonRel
, Direction
.relatedFrom
, languages
);
126 dto
.addRelation(rel2
, Direction
.relatedFrom
, languages
);
127 TaxonRelation relToDuplicate
= dto
.addRelation(rel3
, Direction
.relatedFrom
, languages
);
128 dto
.createMisapplicationString();
129 List
<List
<TaggedText
>> misapplications
= dto
.getMisapplications();
130 Assert
.assertEquals(2, misapplications
.size()); //1 deduplicated
131 List
<TaggedText
> deduplicated
= misapplications
.get(0);
132 Assert
.assertEquals(13, deduplicated
.size());
133 Assert
.assertSame(relToDuplicate
.getTaggedText().get(6), deduplicated
.get(8));
134 Assert
.assertEquals(11, misapplications
.get(1).size());