Project

General

Profile

Download (5.52 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.api.service.dto;
10

    
11
import java.util.List;
12

    
13
import org.junit.Assert;
14
import org.junit.Before;
15
import org.junit.Ignore;
16
import org.junit.Test;
17

    
18
import eu.etaxonomy.cdm.api.service.dto.TaxonRelationshipsDTO.TaxonRelationDTO;
19
import eu.etaxonomy.cdm.format.taxon.TaxonRelationshipFormatter;
20
import eu.etaxonomy.cdm.model.agent.Person;
21
import eu.etaxonomy.cdm.model.common.Language;
22
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
23
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
24
import eu.etaxonomy.cdm.model.name.Rank;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
31
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
32
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
33
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
34
import eu.etaxonomy.cdm.test.TermTestBase;
35

    
36
/**
37
 * @author a.mueller
38
 * @since 15.08.2018
39
 */
40
public class TaxonRelationshipsDTOTest extends TermTestBase {
41

    
42
    private TaxonRelationship taxonRel;
43
    private Reference relSec;
44

    
45
    private Taxon fromTaxon;
46
    private TaxonName fromName;
47
    private Reference fromSec;
48

    
49
    private Taxon toTaxon;
50
    private TaxonName toName;
51
    private Reference toSec;
52

    
53
    private TaxonRelationshipFormatter formatter;
54
    private boolean reverse;
55

    
56
    Person toNameAuthor;
57
    private List<Language> languages;
58

    
59
    @Before
60
    public void setUp() throws Exception {
61
        fromName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
62
        fromName.setGenusOrUninomial("Abies");
63
        fromName.setSpecificEpithet("alba");
64

    
65
        toName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
66
        toName.setGenusOrUninomial("Pinus");
67
        toName.setSpecificEpithet("pinova");
68
        toNameAuthor = Person.NewInstance("Mill.", "Miller", "A.", "Andrew");
69
        toName.setCombinationAuthorship(toNameAuthor);
70

    
71
        fromSec = ReferenceFactory.newGeneric();
72
        fromSec.setTitle("From Sec");
73
        String initials = "J.M.";
74
        fromSec.setAuthorship(Person.NewInstance(null, "Macfarlane", initials, null));
75
        fromSec.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1918));
76

    
77
        relSec = ReferenceFactory.newGeneric();
78
        relSec.setTitle("From rel reference");
79
        initials = null; //"M.R.";
80
        relSec.setAuthorship(Person.NewInstance(null, "Cheek", initials, null));
81
        relSec.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1919));
82

    
83
        toSec = ReferenceFactory.newGeneric();
84
        toSec.setTitle("To Sec");
85
        toSec.setAuthorship(Person.NewTitledInstance("ToSecAuthor"));
86
        toSec.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1928));
87

    
88
        fromTaxon = Taxon.NewInstance(fromName, fromSec);
89
        toTaxon = Taxon.NewInstance(toName, toSec);
90

    
91
        TaxonRelationshipType type = TaxonRelationshipType.MISAPPLIED_NAME_FOR();
92
        taxonRel = fromTaxon.addTaxonRelation(toTaxon, type, relSec, "123");
93
        reverse = false;
94

    
95
        formatter = new TaxonRelationshipFormatter();
96

    
97
        languages = null;
98
    }
99

    
100
    @Test
101
    @Ignore
102
    public void test() {
103
        //2
104
        Reference sec2 = ReferenceFactory.newGeneric();
105
        sec2.setAuthorship(Person.NewInstance("Mue.", "Mueller", "I.", "Inger"));
106
        sec2.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
107
        Taxon from2 = Taxon.NewInstance(fromName, sec2);
108
        TaxonRelationship rel2 = toTaxon.addMisappliedName(from2, sec2, "333");
109
        //3
110
        //same as rel1 except for sec
111
        TaxonRelationship rel3 = toTaxon.addMisappliedName(from2, taxonRel.getCitation(), taxonRel.getCitationMicroReference());
112

    
113
        Taxon taxon2 = Taxon.NewInstance(fromName, sec2);
114
        Taxon taxon2Dupl = Taxon.NewInstance(fromName, toSec);
115

    
116
        //4
117
        TaxonRelationship rel4 = toTaxon.addMisappliedName(taxon2, null, null);
118
        TaxonRelationship rel5 = toTaxon.addMisappliedName(taxon2Dupl, null, null);
119

    
120

    
121
        TaxonRelationshipsDTO dto = new TaxonRelationshipsDTO();
122

    
123
        dto.addRelation(taxonRel, Direction.relatedFrom, languages);
124
        dto.addRelation(rel2, Direction.relatedFrom, languages);
125
        TaxonRelationDTO relToDuplicate = dto.addRelation(rel3, Direction.relatedFrom, languages);
126
        dto.addRelation(rel4, Direction.relatedFrom, languages);
127
        TaxonRelationDTO duplicateWithoutRelSec2 = dto.addRelation(rel5, Direction.relatedFrom, languages);
128

    
129
        dto.createMisapplicationString();
130

    
131
        List<List<TaggedText>> misapplications = dto.getMisapplications();
132
        Assert.assertEquals("2 of 5 misapplications must be deduplicated", 3, misapplications.size());  //2/5 were deduplicated
133

    
134
        List<TaggedText> deduplicated = misapplications.get(0);
135
        Assert.assertEquals(13, deduplicated.size());
136
        Assert.assertSame(relToDuplicate.getTaggedText().get(6), deduplicated.get(8));
137

    
138
        Assert.assertEquals(11, misapplications.get(1).size());
139

    
140
        deduplicated = misapplications.get(2);
141
        Assert.assertEquals(9, deduplicated.size());
142
        Assert.assertSame(duplicateWithoutRelSec2.getTaggedText().get(6), deduplicated.get(8));
143
    }
144
}
    (1-1/1)