Project

General

Profile

Revision bcf6a056

IDbcf6a056708116c29aacd5d863ed1b8d21d87f2c
Parent 523a1fad
Child 85743e03

Added by Katja Luther almost 2 years ago

ref #7553: delete TypeDesignationSetManagerIT from vaadin

View differences:

src/test/java/eu/etaxonomy/cdm/vaadin/util/converter/TypeDesignationSetManagerIT.java
1
/**
2
* Copyright (C) 2017 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.vaadin.util.converter;
10

  
11
import static org.junit.Assert.assertEquals;
12
import static org.junit.Assert.assertNotNull;
13

  
14
import java.io.FileNotFoundException;
15
import java.util.ArrayList;
16
import java.util.Collection;
17
import java.util.Iterator;
18
import java.util.LinkedHashMap;
19
import java.util.List;
20
import java.util.Map;
21

  
22
import org.apache.log4j.Logger;
23
import org.junit.Before;
24
import org.junit.Test;
25

  
26
import eu.etaxonomy.cdm.CdmVaadinIntegrationTest;
27
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
28
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager;
29
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager.TypeDesignationWorkingSet;
30
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
31
import eu.etaxonomy.cdm.model.media.Media;
32
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
33
import eu.etaxonomy.cdm.model.name.Rank;
34
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
35
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
36
import eu.etaxonomy.cdm.model.name.TaxonName;
37
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
38
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
39
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
40
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
41
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
42
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
43
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
44
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
45
import eu.etaxonomy.cdm.model.reference.Reference;
46
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
47
import eu.etaxonomy.cdm.ref.TypedEntityReference;
48

  
49
/**
50
 * @author a.kohlbecker
51
 * @since Mar 10, 2017
52
 *
53
 */
54
public class TypeDesignationSetManagerIT extends CdmVaadinIntegrationTest {
55

  
56

  
57
    private NameTypeDesignation ntd;
58
    private SpecimenTypeDesignation std_IT;
59
    private SpecimenTypeDesignation std_HT;
60
    private SpecimenTypeDesignation std_IT_2;
61
    private SpecimenTypeDesignation std_IT_3;
62
    private SpecimenTypeDesignation mtd_HT_published;
63
    private SpecimenTypeDesignation mtd_IT_unpublished;
64

  
65
    @Before
66
    public void init(){
67

  
68
        ntd = NameTypeDesignation.NewInstance();
69
        ntd.setId(1);
70
        TaxonName typeName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
71
        typeName.setTitleCache("Prionus L.", true);
72
        ntd.setTypeName(typeName);
73
        Reference citation = ReferenceFactory.newGeneric();
74
        citation.setTitleCache("Species Plantarum", true);
75
        ntd.setCitation(citation);
76

  
77
        FieldUnit fu_1 = FieldUnit.NewInstance();
78
        fu_1.setId(1);
79
        fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
80

  
81
        FieldUnit fu_2 = FieldUnit.NewInstance();
82
        fu_2.setId(2);
83
        fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
84

  
85
        std_HT = SpecimenTypeDesignation.NewInstance();
86
        std_HT.setId(1);
87
        DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
88
        specimen_HT.setTitleCache("OHA", true);
89
        createDerivationEvent(fu_1, specimen_HT);
90
        specimen_HT.getOriginals().add(fu_1);
91
        std_HT.setTypeSpecimen(specimen_HT);
92
        std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
93

  
94
        std_IT = SpecimenTypeDesignation.NewInstance();
95
        std_IT.setId(2);
96
        DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
97
        specimen_IT.setTitleCache("BER", true);
98
        createDerivationEvent(fu_1, specimen_IT);
99
        std_IT.setTypeSpecimen(specimen_IT);
100
        std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
101

  
102
        std_IT_2 = SpecimenTypeDesignation.NewInstance();
103
        std_IT_2.setId(3);
104
        DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
105
        specimen_IT_2.setTitleCache("KEW", true);
106
        createDerivationEvent(fu_1, specimen_IT_2);
107
        std_IT_2.setTypeSpecimen(specimen_IT_2);
108
        std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
109

  
110
        std_IT_3 = SpecimenTypeDesignation.NewInstance();
111
        std_IT_3.setId(4);
112
        DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
113
        specimen_IT_3.setTitleCache("M", true);
114
        createDerivationEvent(fu_2, specimen_IT_3);
115
        std_IT_3.setTypeSpecimen(specimen_IT_3);
116
        std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
117

  
118
        mtd_HT_published = SpecimenTypeDesignation.NewInstance();
119
        mtd_HT_published.setId(5);
120
        MediaSpecimen mediaSpecimen_published = (MediaSpecimen)DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
121
        Media media = Media.NewInstance();
122
        Reference ref = ReferenceFactory.newGeneric();
123
        ref.setTitleCache("A.K. & W.K (2008) Algae of the BGBM", true);
124
        media.addSource(IdentifiableSource.NewPrimaryMediaSourceInstance(ref, "p.33"));
125
        mediaSpecimen_published.setMediaSpecimen(media);
126
        createDerivationEvent(fu_1, mediaSpecimen_published);
127
        mtd_HT_published.setTypeSpecimen(mediaSpecimen_published);
128
        mtd_HT_published.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
129

  
130
        mtd_IT_unpublished = SpecimenTypeDesignation.NewInstance();
131
        mtd_IT_unpublished.setId(6);
132
        MediaSpecimen mediaSpecimen_unpublished = (MediaSpecimen)DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
133
        eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
134
        collection.setCode("B");
135
        mediaSpecimen_unpublished.setCollection(collection);
136
        mediaSpecimen_unpublished.setAccessionNumber("Slide A565656");
137
        createDerivationEvent(fu_1, mediaSpecimen_unpublished);
138
        mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
139
        mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
140

  
141
    }
142

  
143
    /**
144
     * @param fu_1
145
     * @param specimen_IT_2
146
     */
147
    protected void createDerivationEvent(FieldUnit fu_1, DerivedUnit specimen_IT_2) {
148
        DerivationEvent derivationEvent_3 = DerivationEvent.NewInstance();
149
        derivationEvent_3.addOriginal(fu_1);
150
        derivationEvent_3.addDerivative(specimen_IT_2);
151
    }
152

  
153
    @Test
154
    public void test1() throws RegistrationValidationException{
155

  
156
        List<TypeDesignationBase> tds = new ArrayList<>();
157
        tds.add(ntd);
158
        tds.add(std_IT);
159
        tds.add(std_HT);
160
        tds.add(std_IT_2);
161
        tds.add(std_IT_3);
162

  
163
        TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
164
        typifiedName.setTitleCache("Prionus coriatius L.", true);
165

  
166
        typifiedName.addTypeDesignation(ntd, false);
167
        typifiedName.addTypeDesignation(std_HT, false);
168
        typifiedName.addTypeDesignation(std_IT, false);
169
        typifiedName.addTypeDesignation(std_IT_2, false);
170
        typifiedName.addTypeDesignation(std_IT_3, false);
171

  
172
        TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(tds);
173
        String result = typeDesignationManager.print();
174

  
175
        Logger.getLogger(this.getClass()).debug(result);
176
        assertNotNull(result);
177
        assertEquals(
178
                "Prionus coriatius L. Type: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 Isotype, M; Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Isotypes: BER, KEW; NameType: Prionus L. Species Plantarum"
179
                , result
180
                );
181

  
182
        LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> orderedTypeDesignations =
183
                typeDesignationManager.getOrderdTypeDesignationWorkingSets();
184
        Iterator<TypeDesignationWorkingSet> byStatusMapIterator = orderedTypeDesignations.values().iterator();
185
        Map<TypeDesignationStatusBase<?>, Collection<TypedEntityReference>> byStatusMap_1 = byStatusMapIterator.next();
186
        Map<TypeDesignationStatusBase<?>, Collection<TypedEntityReference>> byStatusMap_2 = byStatusMapIterator.next();
187
        Iterator<TypeDesignationStatusBase<?>> keyIt_1 = byStatusMap_1.keySet().iterator();
188
        assertEquals("Isotype", keyIt_1.next().getLabel());
189
        Iterator<TypeDesignationStatusBase<?>> keyIt_2 = byStatusMap_2.keySet().iterator();
190
        assertEquals("Holotype", keyIt_2.next().getLabel());
191
        assertEquals("Isotype", keyIt_2.next().getLabel());
192
    }
193

  
194
    @Test
195
    public void test2() throws RegistrationValidationException{
196

  
197
        TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
198
        typifiedName.setTitleCache("Prionus coriatius L.", true);
199

  
200
        TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
201
        String result = typeDesignationManager.print();
202
        Logger.getLogger(this.getClass()).debug(result);
203
        assertNotNull(result);
204
        assertEquals(
205
                "Prionus coriatius L."
206
                , result
207
                );
208

  
209
        typifiedName.addTypeDesignation(ntd, false);
210
        typeDesignationManager.addTypeDesigations(null, ntd);
211

  
212
        assertEquals(
213
                "Prionus coriatius L. NameType: Prionus L. Species Plantarum"
214
                , typeDesignationManager.print()
215
                );
216

  
217
        typifiedName.addTypeDesignation(std_HT, false);
218
        typeDesignationManager.addTypeDesigations(null, std_HT);
219

  
220
        assertEquals(
221
                "Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; NameType: Prionus L. Species Plantarum"
222
                , typeDesignationManager.print()
223
                );
224

  
225
    }
226

  
227
    @Test
228
    public void test_mediaType(){
229

  
230
        for(int i = 0; i < 10; i++ ){
231

  
232
            init();
233
            // repeat 10 times to assure the order of typedesignations is fix in the representations
234
            TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
235
            typifiedName.setTitleCache("Prionus coriatius L.", true);
236
            typifiedName.addTypeDesignation(mtd_HT_published, false);
237
            typifiedName.addTypeDesignation(mtd_IT_unpublished, false);
238

  
239
            TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
240
            typeDesignationManager.addTypeDesigations(null, mtd_HT_published);
241
            typeDesignationManager.addTypeDesigations(null, mtd_IT_unpublished);
242

  
243
            assertEquals("failed after repreating " + i + " times",
244
                    "Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, [icon] p.33 in A.K. & W.K (2008) Algae of the BGBM; Isotype, [icon] (B Slide A565656)."
245
                    , typeDesignationManager.print()
246
                    );
247
        }
248

  
249
    }
250

  
251
    /**
252
     * {@inheritDoc}
253
     */
254
    @Override
255
    public void createTestDataSet() throws FileNotFoundException {
256
        // TODO Auto-generated method stub
257

  
258
    }
259
}
260

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)