Project

General

Profile

Revision 1e444ccf

ID1e444ccf037934a1689fd5f3b5ef49ed7fa413ff
Parent 90f19d04
Child 0b9d6dad

Added by Katja Luther about 2 years ago

ref #7553: move TypeDesignationSetmanagerTest to cdmlib

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TypeDesignationSetManagerTest.java
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;
10

  
11

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

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

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

  
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
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
49
/**
50
 * @author a.kohlbecker, k.luther
51
 * @since 03.09.2018
52
 *
53
 */
54
public class TypeDesignationSetManagerTest extends CdmTransactionalIntegrationTest{
55

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

  
64
        @Before
65
        public void init(){
66

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

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

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

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

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

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

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

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

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

  
140
        }
141

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

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

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

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

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

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

  
174
            Logger.getLogger(this.getClass()).debug(result);
175
            assertNotNull(result);
176
            assertEquals(
177
                    "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"
178
                    , result
179
                    );
180

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

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

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

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

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

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

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

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

  
224
        }
225

  
226
        @Test
227
        public void test_mediaType(){
228

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

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

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

  
242
                assertEquals("failed after repreating " + i + " times",
243
                        "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)."
244
                        , typeDesignationManager.print()
245
                        );
246
            }
247

  
248
        }
249

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

  
257
        }
258

  
259

  
260

  
261
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)