1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2016 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.ext.geo;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.junit.Assert;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.BeforeClass;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
|
22
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
23
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
24
|
import eu.etaxonomy.cdm.model.common.TermType;
|
25
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
26
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
27
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
28
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
29
|
|
30
|
/**
|
31
|
* Tests for {@link FloraCubaCondensedDistributionComposer}
|
32
|
* @author a.mueller
|
33
|
* @date 07.04.2016
|
34
|
*
|
35
|
*/
|
36
|
public class FloraCubaCondensedDistributionComposerTest {
|
37
|
|
38
|
private static OrderedTermVocabulary<PresenceAbsenceTerm> statusVoc;
|
39
|
private static OrderedTermVocabulary<NamedArea> cubaAreasVocabualary;
|
40
|
private static NamedArea cuba;
|
41
|
private static NamedArea westernCuba;
|
42
|
private static NamedArea eastCuba;
|
43
|
private static NamedArea centralCuba;
|
44
|
private static NamedArea pinarDelRio;
|
45
|
private static NamedArea holguin;
|
46
|
private static NamedArea guantanamo;
|
47
|
|
48
|
private static NamedArea bahamas;
|
49
|
private static NamedArea oldWorld;
|
50
|
|
51
|
private static UUID uuidStatusOccasionallyCultivated = UUID.fromString("936c3f9a-6099-4322-9792-0a72c6c2ce25");
|
52
|
private static UUID uuidStatusNotNativButNaturalised = UUID.fromString("a1e26234-831e-4190-9fe3-011aca09ddba");
|
53
|
private static UUID uuidStatusDoubtfullyNativeError = UUID.fromString("71b72e24-c2b6-44a5-bdab-39f083bf0f06");
|
54
|
|
55
|
|
56
|
/**
|
57
|
* @throws java.lang.Exception
|
58
|
*/
|
59
|
@SuppressWarnings("unchecked")
|
60
|
@BeforeClass
|
61
|
public static void setUpBeforeClass() throws Exception {
|
62
|
DefaultTermInitializer initializer = new DefaultTermInitializer();
|
63
|
initializer.initialize();
|
64
|
|
65
|
defineSymbolsForExistingTerms();
|
66
|
statusVoc = OrderedTermVocabulary.NewInstance(TermType.PresenceAbsenceTerm);
|
67
|
statusVoc.addTerm(makeStatusTerm("occasionally cultivated","oc","(c)",false, uuidStatusOccasionallyCultivated));
|
68
|
statusVoc.addTerm(makeStatusTerm("not native but possibly naturalised","p","p", false,uuidStatusNotNativButNaturalised));
|
69
|
statusVoc.addTerm(makeStatusTerm("doubtfully native: reported in error","df","-d",false,uuidStatusDoubtfullyNativeError));
|
70
|
|
71
|
makeAreas();
|
72
|
}
|
73
|
|
74
|
|
75
|
/**
|
76
|
*
|
77
|
*/
|
78
|
private static void defineSymbolsForExistingTerms() {
|
79
|
PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA().setSymbol("\u25CF");
|
80
|
PresenceAbsenceTerm.NATIVE().setSymbol("");
|
81
|
PresenceAbsenceTerm.NATIVE_PRESENCE_QUESTIONABLE().setSymbol("?");
|
82
|
PresenceAbsenceTerm.PRESENT_DOUBTFULLY().setSymbol("?");
|
83
|
PresenceAbsenceTerm.NATIVE_DOUBTFULLY_NATIVE().setSymbol("d");
|
84
|
PresenceAbsenceTerm.NATIVE_REPORTED_IN_ERROR().setSymbol("-");
|
85
|
PresenceAbsenceTerm.REPORTED_IN_ERROR().setSymbol("-");
|
86
|
PresenceAbsenceTerm.INTRODUCED_ADVENTITIOUS().setSymbol("a");
|
87
|
PresenceAbsenceTerm.CULTIVATED().setSymbol("c");
|
88
|
PresenceAbsenceTerm.NATURALISED().setSymbol("n");
|
89
|
PresenceAbsenceTerm.CULTIVATED_PRESENCE_QUESTIONABLE().setSymbol("?c");
|
90
|
PresenceAbsenceTerm.CULTIVATED_REPORTED_IN_ERROR().setSymbol("-c");
|
91
|
PresenceAbsenceTerm.NATIVE().setSymbol("");
|
92
|
//Cuba specific
|
93
|
// statusSymbols.put(UUID.fromString("936c3f9a-6099-4322-9792-0a72c6c2ce25"), "(c)");
|
94
|
// //endemic, doubtfully present
|
95
|
// statusSymbols.put(UUID.fromString("5f954f08-267a-4928-b073-12328f74c187"), "?e");
|
96
|
// //non-native and doubtfully naturalised
|
97
|
// statusSymbols.put(UUID.fromString("a1e26234-831e-4190-9fe3-011aca09ddba"), "p");
|
98
|
// //rare casual
|
99
|
// statusSymbols.put(UUID.fromString("8914ce0d-7d31-4c88-8317-985f2b3a493b"), "(a)");
|
100
|
// //?non-native and doubtfully naturalised
|
101
|
// statusSymbols.put(UUID.fromString("9e0b413b-5a68-4e5b-91f2-227b4f832466"), "?p");
|
102
|
// //?adventive (casual) alien
|
103
|
// statusSymbols.put(UUID.fromString("c42ca644-1773-4230-a2ee-328a5d4a21ab"), "?a");
|
104
|
// //endemic, reported in error
|
105
|
// statusSymbols.put(UUID.fromString("679b215d-c231-4ee2-ae12-3ffc3dd528ad"), "-e");
|
106
|
// //naturalised, reported in error
|
107
|
// statusSymbols.put(UUID.fromString("8d918a37-3add-4e1c-a233-c37dbee209aa"), "-n");
|
108
|
// //non-native and doubtfully naturalised, reported in error
|
109
|
// statusSymbols.put(UUID.fromString("b9153d90-9e31-465a-a28c-79077a8ed4c2"), "-p");
|
110
|
// //adventive alien , reported in error
|
111
|
// statusSymbols.put(UUID.fromString("9b910b7b-43e3-4260-961c-6063b11cb7dc"), "-a");
|
112
|
// //doubtfully native: reported in error
|
113
|
// statusSymbols.put(UUID.fromString("71b72e24-c2b6-44a5-bdab-39f083bf0f06"), "-d");
|
114
|
}
|
115
|
|
116
|
|
117
|
/**
|
118
|
* @throws java.lang.Exception
|
119
|
*/
|
120
|
@Before
|
121
|
public void setUp() throws Exception {
|
122
|
|
123
|
}
|
124
|
|
125
|
// ********************* TESTS ******************************/
|
126
|
|
127
|
/**
|
128
|
* Test method for {@link eu.etaxonomy.cdm.ext.geo.FloraCubaCondensedDistributionComposer#createCondensedDistribution(java.util.Collection, java.util.List)}.
|
129
|
*/
|
130
|
@Test
|
131
|
public void testCreateCondensedDistribution() {
|
132
|
FloraCubaCondensedDistributionComposer composer = new FloraCubaCondensedDistributionComposer();
|
133
|
composer.setAreaPreTag("");
|
134
|
composer.setAreaPostTag("");
|
135
|
|
136
|
Set<Distribution> filteredDistributions = new HashSet<Distribution>();
|
137
|
filteredDistributions.add(Distribution.NewInstance(cuba, PresenceAbsenceTerm.NATURALISED()));
|
138
|
filteredDistributions.add(Distribution.NewInstance(eastCuba, statusVoc.findTermByUuid(uuidStatusOccasionallyCultivated)));
|
139
|
filteredDistributions.add(Distribution.NewInstance(pinarDelRio, PresenceAbsenceTerm.CULTIVATED_REPORTED_IN_ERROR()));
|
140
|
filteredDistributions.add(Distribution.NewInstance(holguin, PresenceAbsenceTerm.NATURALISED()));
|
141
|
filteredDistributions.add(Distribution.NewInstance(bahamas, PresenceAbsenceTerm.NATIVE()));
|
142
|
filteredDistributions.add(Distribution.NewInstance(oldWorld, PresenceAbsenceTerm.NATIVE_PRESENCE_QUESTIONABLE()));
|
143
|
|
144
|
CondensedDistribution condensedDistribution = composer.createCondensedDistribution(filteredDistributions, null);
|
145
|
String condensedString = condensedDistribution.toString();
|
146
|
|
147
|
Assert.assertEquals("Condensed string for Cuba differs", "nCu((c)CuE(nHo)) "+composer.getInternalAreaSeparator() +"Bah ?VM ", condensedString);
|
148
|
|
149
|
|
150
|
//TODO work in progress
|
151
|
}
|
152
|
|
153
|
|
154
|
|
155
|
private static boolean makeAreas(){
|
156
|
|
157
|
//vocabulary
|
158
|
UUID cubaAreasVocabularyUuid = UUID.fromString("c81e3c7b-3c01-47d1-87cf-388de4b1908c");
|
159
|
String label = "Cuba Areas";
|
160
|
String abbrev = null;
|
161
|
cubaAreasVocabualary = OrderedTermVocabulary.NewInstance(TermType.NamedArea, label, label, abbrev, null);
|
162
|
cubaAreasVocabualary.setUuid(cubaAreasVocabularyUuid);
|
163
|
|
164
|
//Cuba
|
165
|
label = "Cuba";
|
166
|
abbrev = "Cu";
|
167
|
UUID uuid = UUID.fromString("d0144a6e-0e17-4a1d-bce5-d464a2aa7229");
|
168
|
cuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
169
|
|
170
|
//Western Cuba
|
171
|
label = "Western Cuba";
|
172
|
abbrev = "CuW";
|
173
|
uuid = UUID.randomUUID();
|
174
|
westernCuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
175
|
cuba.addIncludes(westernCuba);
|
176
|
|
177
|
//Central Cuba
|
178
|
label = "Central Cuba";
|
179
|
abbrev = "CuC";
|
180
|
uuid = UUID.randomUUID();
|
181
|
centralCuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
182
|
cuba.addIncludes(centralCuba);
|
183
|
|
184
|
//East Cuba
|
185
|
label = "East Cuba";
|
186
|
abbrev = "CuE";
|
187
|
uuid = UUID.randomUUID();
|
188
|
eastCuba = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
189
|
cuba.addIncludes(eastCuba);
|
190
|
|
191
|
//Pinar del Río PR
|
192
|
label = "Pinar del Río";
|
193
|
abbrev = "PR*";
|
194
|
uuid = UUID.randomUUID();
|
195
|
pinarDelRio = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
196
|
westernCuba.addIncludes(pinarDelRio);
|
197
|
|
198
|
//Artemisa
|
199
|
label = "Artemisa";
|
200
|
abbrev = "Art";
|
201
|
uuid = UUID.randomUUID();
|
202
|
NamedArea area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
203
|
westernCuba.addIncludes(area);
|
204
|
|
205
|
//Ciudad de la Habana
|
206
|
label = "Ciudad de la Habana";
|
207
|
abbrev = "Hab*";
|
208
|
uuid = UUID.randomUUID();
|
209
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
210
|
westernCuba.addIncludes(area);
|
211
|
|
212
|
//Ciudad de la Habana
|
213
|
label = "Mayabeque";
|
214
|
abbrev = "May";
|
215
|
uuid = UUID.randomUUID();
|
216
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
217
|
westernCuba.addIncludes(area);
|
218
|
|
219
|
//Matanzas Mat
|
220
|
label = "Matanzas";
|
221
|
abbrev = "Mat";
|
222
|
uuid = UUID.randomUUID();
|
223
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
224
|
westernCuba.addIncludes(area);
|
225
|
|
226
|
//Isla de la Juventud IJ
|
227
|
label = "Isla de la Juventud";
|
228
|
abbrev = "IJ";
|
229
|
uuid = UUID.randomUUID();
|
230
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
231
|
westernCuba.addIncludes(area);
|
232
|
|
233
|
//Provinces - Central
|
234
|
//Villa Clara VC
|
235
|
label = "Villa Clara";
|
236
|
abbrev = "VC";
|
237
|
uuid = UUID.randomUUID();
|
238
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
239
|
centralCuba.addIncludes(area);
|
240
|
|
241
|
//Cienfuegos Ci VC
|
242
|
label = "Cienfuegos";
|
243
|
abbrev = "Ci";
|
244
|
uuid = UUID.randomUUID();
|
245
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
246
|
centralCuba.addIncludes(area);
|
247
|
|
248
|
//Sancti Spiritus SS
|
249
|
label = "Sancti Spíritus";
|
250
|
abbrev = "SS";
|
251
|
uuid = UUID.randomUUID();
|
252
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
253
|
centralCuba.addIncludes(area);
|
254
|
|
255
|
//Ciego de Ávila CA
|
256
|
label = "Ciego de Ávila";
|
257
|
abbrev = "CA";
|
258
|
uuid = UUID.randomUUID();
|
259
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
260
|
centralCuba.addIncludes(area);
|
261
|
|
262
|
//Camagüey Cam
|
263
|
label = "Camagüey";
|
264
|
abbrev = "Cam";
|
265
|
uuid = UUID.randomUUID();
|
266
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
267
|
centralCuba.addIncludes(area);
|
268
|
|
269
|
//Las Tunas LT
|
270
|
label = "Las Tunas";
|
271
|
abbrev = "LT";
|
272
|
uuid = UUID.randomUUID();
|
273
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
274
|
centralCuba.addIncludes(area);
|
275
|
|
276
|
//Provinces - East
|
277
|
//Granma Gr
|
278
|
label = "Granma";
|
279
|
abbrev = "Gr";
|
280
|
uuid = UUID.randomUUID();
|
281
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
282
|
eastCuba.addIncludes(area);
|
283
|
|
284
|
//Holguín Ho
|
285
|
label = "Holguín";
|
286
|
abbrev = "Ho";
|
287
|
uuid = UUID.randomUUID();
|
288
|
holguin = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
289
|
eastCuba.addIncludes(holguin);
|
290
|
|
291
|
//Santiago de Cuba SC
|
292
|
label = "Santiago de Cuba";
|
293
|
abbrev = "SC";
|
294
|
uuid = UUID.randomUUID();
|
295
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
296
|
eastCuba.addIncludes(area);
|
297
|
|
298
|
//Guantánamo Gu
|
299
|
label = "Guantánamo";
|
300
|
abbrev = "Gu";
|
301
|
uuid = UUID.randomUUID();
|
302
|
guantanamo = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
303
|
eastCuba.addIncludes(guantanamo);
|
304
|
|
305
|
//other Greater Antilles (Cuba, Española, Jamaica, Puerto Rico)
|
306
|
//Española Esp (=Haiti + Dominican Republic)
|
307
|
label = "Española";
|
308
|
abbrev = "Esp";
|
309
|
uuid = UUID.randomUUID();
|
310
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
311
|
|
312
|
//Jamaica Ja
|
313
|
label = "Jamaica";
|
314
|
abbrev = "Ja";
|
315
|
uuid = UUID.randomUUID();
|
316
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
317
|
|
318
|
//Puerto Rico PR
|
319
|
label = "Puerto Rico";
|
320
|
abbrev = "PRc";
|
321
|
uuid = UUID.randomUUID();
|
322
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
323
|
|
324
|
//Lesser Antilles Men
|
325
|
label = "Lesser Antilles";
|
326
|
abbrev = "Men";
|
327
|
uuid = UUID.randomUUID();
|
328
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
329
|
|
330
|
//Bahamas
|
331
|
label = "Bahamas";
|
332
|
abbrev = "Bah";
|
333
|
uuid = UUID.randomUUID();
|
334
|
bahamas = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
335
|
|
336
|
//Cayman Islands
|
337
|
label = "Cayman Islands"; //[Trinidad, Tobago, Curaçao, Margarita, ABC Isl. => S. America];
|
338
|
abbrev = "Cay";
|
339
|
uuid = UUID.randomUUID();
|
340
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
341
|
|
342
|
//World
|
343
|
//N America
|
344
|
label = "N America"; //(incl. Mexico)
|
345
|
abbrev = "AmN";
|
346
|
uuid = UUID.randomUUID();
|
347
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
348
|
|
349
|
//Central America
|
350
|
label = "Central America";
|
351
|
abbrev = "AmC";
|
352
|
uuid = UUID.randomUUID();
|
353
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
354
|
|
355
|
|
356
|
//S America
|
357
|
label = "S America";
|
358
|
abbrev = "AmS";
|
359
|
uuid = UUID.randomUUID();
|
360
|
area = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
361
|
|
362
|
//Old World
|
363
|
label = "Old World ";
|
364
|
abbrev = "VM";
|
365
|
uuid = UUID.randomUUID();
|
366
|
oldWorld = getNamedArea(uuid, label, abbrev, cubaAreasVocabualary);
|
367
|
|
368
|
return true;
|
369
|
}
|
370
|
|
371
|
private static NamedArea getNamedArea(UUID uuid, String label, String abbrev, TermVocabulary<NamedArea> vocabulary) {
|
372
|
NamedArea result = NamedArea.NewInstance(label, label, abbrev);
|
373
|
result.setUuid(uuid);
|
374
|
vocabulary.addTerm(result);
|
375
|
result.setIdInVocabulary(abbrev);
|
376
|
return result;
|
377
|
|
378
|
}
|
379
|
|
380
|
|
381
|
private static PresenceAbsenceTerm makeStatusTerm(String desc, String abbrev, String symbol, boolean absent, UUID uuid) {
|
382
|
PresenceAbsenceTerm result = PresenceAbsenceTerm.NewPresenceInstance(desc, desc, abbrev);
|
383
|
result.setAbsenceTerm(absent);
|
384
|
result.setUuid(uuid);
|
385
|
result.setSymbol(symbol);
|
386
|
return result;
|
387
|
}
|
388
|
|
389
|
|
390
|
}
|