1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.ext.geo;
|
11
|
|
12
|
import static org.junit.Assert.assertTrue;
|
13
|
|
14
|
import java.awt.Color;
|
15
|
import java.io.FileNotFoundException;
|
16
|
import java.io.IOException;
|
17
|
import java.io.InputStream;
|
18
|
import java.io.InputStreamReader;
|
19
|
import java.net.HttpURLConnection;
|
20
|
import java.net.MalformedURLException;
|
21
|
import java.net.URI;
|
22
|
import java.net.URISyntaxException;
|
23
|
import java.net.URL;
|
24
|
import java.util.ArrayList;
|
25
|
import java.util.Collection;
|
26
|
import java.util.HashMap;
|
27
|
import java.util.HashSet;
|
28
|
import java.util.List;
|
29
|
import java.util.Map;
|
30
|
import java.util.Set;
|
31
|
import java.util.UUID;
|
32
|
|
33
|
import org.apache.commons.lang.StringUtils;
|
34
|
import org.apache.http.client.ClientProtocolException;
|
35
|
import org.apache.log4j.Logger;
|
36
|
import org.junit.Assert;
|
37
|
import org.junit.Before;
|
38
|
import org.junit.Test;
|
39
|
import org.unitils.dbunit.annotation.DataSet;
|
40
|
import org.unitils.spring.annotation.SpringBeanByType;
|
41
|
|
42
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
43
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
44
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
45
|
import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
|
46
|
import eu.etaxonomy.cdm.common.StreamUtils;
|
47
|
import eu.etaxonomy.cdm.common.UriUtils;
|
48
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
49
|
import eu.etaxonomy.cdm.model.common.Language;
|
50
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
51
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
52
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
53
|
import eu.etaxonomy.cdm.model.description.Feature;
|
54
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
55
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
56
|
import eu.etaxonomy.cdm.model.location.Country;
|
57
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
58
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
59
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
60
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
61
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
62
|
import eu.etaxonomy.cdm.model.term.TermType;
|
63
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
64
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
65
|
|
66
|
/**
|
67
|
* @author a.mueller
|
68
|
* @since 08.10.2008
|
69
|
*/
|
70
|
public class EditGeoServiceTest extends CdmTransactionalIntegrationTest {
|
71
|
private static final Logger logger = Logger.getLogger(EditGeoServiceTest.class);
|
72
|
|
73
|
private static final String EDIT_MAPSERVICE_URI_STING = "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php";
|
74
|
private static URI editMapServiceUri;
|
75
|
|
76
|
@SpringBeanByType
|
77
|
private ITermService termService;
|
78
|
|
79
|
@SpringBeanByType
|
80
|
private IVocabularyService vocabService;
|
81
|
|
82
|
@SpringBeanByType
|
83
|
private GeoServiceAreaAnnotatedMapping mapping;
|
84
|
|
85
|
@SpringBeanByType
|
86
|
private IEditGeoService editGeoService;
|
87
|
|
88
|
@SpringBeanByType
|
89
|
private ITaxonService taxonService ;
|
90
|
|
91
|
@Before
|
92
|
public void setUp() throws Exception {
|
93
|
System.setProperty("ONLY-A-TEST", "TRUE"); // allows EditGeoServiceUtilities to skip some line of code
|
94
|
editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING);
|
95
|
}
|
96
|
|
97
|
//******************************************** TESTS**************
|
98
|
|
99
|
@Test
|
100
|
public void testGetWebServiceUrlCountry() {
|
101
|
Set<Distribution> distributions = new HashSet<>();
|
102
|
Country germany = termService.findByIdInVocabulary("DEU", Country.uuidCountryVocabulary, Country.class);
|
103
|
// germany = (Country)termService.find(665);
|
104
|
// germany = (Country)termService.find(UUID.fromString("cbe7ce69-2952-4309-85dd-0d7d4a4830a1"));
|
105
|
|
106
|
// germany = Country.GERMANY();
|
107
|
|
108
|
distributions.add(Distribution.NewInstance(germany, PresenceAbsenceTerm.PRESENT()));
|
109
|
distributions.add(Distribution.NewInstance(termService.findByIdInVocabulary("DE", Country.uuidCountryVocabulary, Country.class), PresenceAbsenceTerm.INTRODUCED()));
|
110
|
Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();
|
111
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
|
112
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);
|
113
|
List<Language> languages = new ArrayList<Language>();
|
114
|
|
115
|
boolean subAreaPreference = false;
|
116
|
boolean statusOrderPreference = false;
|
117
|
|
118
|
|
119
|
Collection<Distribution> filteredDistributions = DescriptionUtility.filterDistributions(
|
120
|
distributions, null, true, statusOrderPreference, subAreaPreference);
|
121
|
|
122
|
String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(filteredDistributions,
|
123
|
mapping, null, null, languages );
|
124
|
logger.warn(result);
|
125
|
Assert.assertTrue("WebServiceUrl must contain country part for Germany", result.matches(".*ad=country_earth(%3A|:)gmi_cntry:.:DEU.*"));
|
126
|
}
|
127
|
|
128
|
@Test
|
129
|
public void testGetWebServiceUrlTdwg() throws MalformedURLException, IOException {
|
130
|
//String webServiceUrl = "http://www.test.de/webservice";
|
131
|
Set<Distribution> distributions = new HashSet<>();
|
132
|
distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("SPA"), PresenceAbsenceTerm.PRESENT()));
|
133
|
distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("GER"), PresenceAbsenceTerm.INTRODUCED()));
|
134
|
distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("14"), PresenceAbsenceTerm.CULTIVATED()));
|
135
|
distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("BGM"), PresenceAbsenceTerm.ABSENT()));
|
136
|
distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("FRA"), PresenceAbsenceTerm.ABSENT()));
|
137
|
distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("IND-AP"), PresenceAbsenceTerm.PRESENT()));
|
138
|
|
139
|
Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<>();
|
140
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
|
141
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);
|
142
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.CULTIVATED(), Color.YELLOW);
|
143
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.ABSENT(), Color.DARK_GRAY);
|
144
|
String backLayer ="";
|
145
|
presenceAbsenceColorMap = null;
|
146
|
String bbox="-20,0,120,70";
|
147
|
List<Language> languages = new ArrayList<>();
|
148
|
|
149
|
boolean subAreaPreference = false;
|
150
|
boolean statusOrderPreference = false;
|
151
|
String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(
|
152
|
distributions,
|
153
|
mapping,
|
154
|
null, // presenceAbsenceTermColors
|
155
|
null, // projectToLayer
|
156
|
languages );
|
157
|
//TODO Set semantics is not determined
|
158
|
//String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";
|
159
|
logger.debug(result);
|
160
|
assertTrue(result.matches(".*ad=tdwg[1-4].*"));
|
161
|
assertTrue(result.matches(".*tdwg2:[a-d]:14[\\|&].*") );
|
162
|
assertTrue(result.matches(".*[a-d]:FRA,BGM[\\|&].*") || result.matches(".*[a-d]:BGM,FRA[\\|&].*") );
|
163
|
assertTrue(result.matches(".*[a-d]:GER[\\|&].*") );
|
164
|
assertTrue(result.matches(".*[a-d]:SPA[\\|&].*") );
|
165
|
assertTrue(result.matches(".*tdwg4:[a-d]:INDAP[\\|&].*") );
|
166
|
//assertTrue(result.matches("0000ff"));
|
167
|
//TODO continue
|
168
|
|
169
|
// request map image from webservice
|
170
|
subTestWithEditMapService(result);
|
171
|
}
|
172
|
|
173
|
@Test
|
174
|
public void testGetWebServiceUrlCyprus() throws ClientProtocolException, IOException, URISyntaxException {
|
175
|
makeCyprusAreas();
|
176
|
Set<Distribution> distributions = new HashSet<Distribution>();
|
177
|
distributions.add(Distribution.NewInstance(divisions.get("1"), PresenceAbsenceTerm.PRESENT()));
|
178
|
distributions.add(Distribution.NewInstance(divisions.get("2"), PresenceAbsenceTerm.INTRODUCED()));
|
179
|
distributions.add(Distribution.NewInstance(divisions.get("3"), PresenceAbsenceTerm.CULTIVATED()));
|
180
|
distributions.add(Distribution.NewInstance(divisions.get("4"), PresenceAbsenceTerm.ABSENT()));
|
181
|
distributions.add(Distribution.NewInstance(divisions.get("5"), PresenceAbsenceTerm.ABSENT()));
|
182
|
distributions.add(Distribution.NewInstance(divisions.get("6"), PresenceAbsenceTerm.PRESENT()));
|
183
|
|
184
|
Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();
|
185
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
|
186
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);
|
187
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.CULTIVATED(), Color.YELLOW);
|
188
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.ABSENT(), Color.DARK_GRAY);
|
189
|
String backLayer ="";
|
190
|
presenceAbsenceColorMap = null;
|
191
|
String bbox="-20,0,120,70";
|
192
|
List<Language> languages = new ArrayList<Language>();
|
193
|
|
194
|
boolean subAreaPreference = false;
|
195
|
boolean statusOrderPreference = false;
|
196
|
String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(
|
197
|
distributions,
|
198
|
mapping,
|
199
|
null, null, languages );
|
200
|
//TODO Set semantics is not determined
|
201
|
//String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";
|
202
|
assertTrue(result.matches(".*ad=cyprusdivs%3Abdcode:.*"));
|
203
|
assertTrue(result.matches(".*[a-d]:5,4[\\|&].*") || result.matches(".*[a-d]:4,5[\\|&].*") );
|
204
|
assertTrue(result.matches(".*[a-d]:1,6[\\|&].*") || result.matches(".*[a-d]:6,1[\\|&].*") );
|
205
|
assertTrue(result.matches(".*[a-d]:2[\\|&].*") );
|
206
|
assertTrue(result.matches(".*[a-d]:3[\\|&].*") );
|
207
|
|
208
|
// request map image from webservice
|
209
|
subTestWithEditMapService(result);
|
210
|
}
|
211
|
|
212
|
private void subTestWithEditMapService(String queryString)throws MalformedURLException, IOException {
|
213
|
if(UriUtils.isServiceAvailable(editMapServiceUri)){
|
214
|
URL requestUrl = new URL(editMapServiceUri.toString() + "?img=false&bbox=-180,-90,180,90&ms=1000&" + queryString);
|
215
|
logger.debug("editMapServiceUri: " + requestUrl);
|
216
|
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
217
|
connection.connect();
|
218
|
// connection.setReadTimeout(10000); //timeout after 10 sec, does not seem to work
|
219
|
assertTrue(connection.getResponseCode() == 200);
|
220
|
InputStream contentStream = connection.getInputStream();
|
221
|
String content = StreamUtils.readToString(contentStream);
|
222
|
logger.debug("EditMapService response body:\n" + content);
|
223
|
assertTrue(content.startsWith("[{"));
|
224
|
assertTrue(content.endsWith("}]"));
|
225
|
assertTrue(content.matches(".*\"bbox\":.*"));
|
226
|
assertTrue(content.matches(".*\"legend\":.*"));
|
227
|
assertTrue(content.matches(".*\"layers\":.*"));
|
228
|
assertTrue(content.matches(".*\"sld\":.*"));
|
229
|
assertTrue(content.matches(".*\"geoserver\":.*"));
|
230
|
}
|
231
|
}
|
232
|
|
233
|
public static final UUID uuidCyprusDivisionsVocabulary = UUID.fromString("2119f610-1f93-4d87-af28-40aeefaca100");
|
234
|
private final Map<String, NamedArea> divisions = new HashMap<String, NamedArea>();
|
235
|
|
236
|
private boolean makeCyprusAreas() throws IOException {
|
237
|
//divisions
|
238
|
|
239
|
|
240
|
NamedAreaType areaType = NamedAreaType.NATURAL_AREA();
|
241
|
NamedAreaLevel areaLevel = NamedAreaLevel.NewInstance("Cyprus Division", "Cyprus Division", null);
|
242
|
|
243
|
termService.saveOrUpdate(areaLevel);
|
244
|
|
245
|
TermVocabulary<NamedArea> areaVocabulary = TermVocabulary.NewInstance(TermType.NamedArea,
|
246
|
NamedArea.class, "Cyprus devisions", "Cyprus divisions", null, null);
|
247
|
areaVocabulary.setUuid(uuidCyprusDivisionsVocabulary);
|
248
|
|
249
|
|
250
|
for(int i = 1; i <= 8; i++){
|
251
|
UUID divisionUuid = getNamedAreaUuid(String.valueOf(i));
|
252
|
NamedArea division = this.newNamedArea(
|
253
|
divisionUuid,
|
254
|
"Division " + i,
|
255
|
"Cyprus: Division " + i,
|
256
|
String.valueOf(i), // id in vocab
|
257
|
areaType,
|
258
|
areaLevel,
|
259
|
areaVocabulary);
|
260
|
divisions.put(String.valueOf(i), division);
|
261
|
}
|
262
|
|
263
|
vocabService.saveOrUpdate(areaVocabulary);
|
264
|
commitAndStartNewTransaction(null);
|
265
|
|
266
|
|
267
|
// import and map shapefile attributes from csv
|
268
|
InputStream is = getClass().getClassLoader().getResourceAsStream("eu/etaxonomy/cdm/ext/geo/cyprusdivs.csv");
|
269
|
List<String> idSearchFields = new ArrayList<String>();
|
270
|
idSearchFields.add("bdcode");
|
271
|
String wmsLayerName = "cyprusdivs";
|
272
|
editGeoService.mapShapeFileToNamedAreas(new InputStreamReader(is), idSearchFields, wmsLayerName, uuidCyprusDivisionsVocabulary, null);
|
273
|
|
274
|
divisions.clear();
|
275
|
Set<DefinedTermBase> terms = vocabService.load(uuidCyprusDivisionsVocabulary).getTerms();
|
276
|
for(DefinedTermBase dtb : terms){
|
277
|
divisions.put(dtb.getIdInVocabulary(), (NamedArea) dtb);
|
278
|
}
|
279
|
|
280
|
|
281
|
// indigenousStatus = (PresenceTerm)getTermService().find(CyprusTransformer.indigenousUuid);
|
282
|
// casualStatus = (PresenceTerm)getTermService().find(CyprusTransformer.casualUuid);
|
283
|
// nonInvasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.nonInvasiveUuid);
|
284
|
// invasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.invasiveUuid);
|
285
|
// questionableStatus = (PresenceTerm)getTermService().find(CyprusTransformer.questionableUuid);
|
286
|
|
287
|
return true;
|
288
|
|
289
|
|
290
|
}
|
291
|
|
292
|
public static final UUID uuidDivision1 = UUID.fromString("ab17eee9-1abb-4ce9-a9a2-563f840cdbfc");
|
293
|
public static final UUID uuidDivision2 = UUID.fromString("c3606165-efb7-4224-a168-63e009eb4aa5");
|
294
|
public static final UUID uuidDivision3 = UUID.fromString("750d4e07-e34b-491f-a7b7-09723afdc960");
|
295
|
public static final UUID uuidDivision4 = UUID.fromString("8a858922-e8e5-4791-ad53-906e50633ec7");
|
296
|
public static final UUID uuidDivision5 = UUID.fromString("16057133-d541-4ebd-81d4-cb92265ec54c");
|
297
|
public static final UUID uuidDivision6 = UUID.fromString("fbf21230-4a42-4f4c-9af8-5da52123c264");
|
298
|
public static final UUID uuidDivision7 = UUID.fromString("d31dd96a-36ea-4428-871c-d8552a9565ca");
|
299
|
public static final UUID uuidDivision8 = UUID.fromString("236ea447-c3ab-486d-9e06-cc5907861acc");
|
300
|
|
301
|
|
302
|
public UUID getNamedAreaUuid(String key) {
|
303
|
if (StringUtils.isBlank(key)){return null;
|
304
|
}else if (key.equalsIgnoreCase("1")){return uuidDivision1;
|
305
|
}else if (key.equalsIgnoreCase("2")){return uuidDivision2;
|
306
|
}else if (key.equalsIgnoreCase("3")){return uuidDivision3;
|
307
|
}else if (key.equalsIgnoreCase("4")){return uuidDivision4;
|
308
|
}else if (key.equalsIgnoreCase("5")){return uuidDivision5;
|
309
|
}else if (key.equalsIgnoreCase("6")){return uuidDivision6;
|
310
|
}else if (key.equalsIgnoreCase("7")){return uuidDivision7;
|
311
|
}else if (key.equalsIgnoreCase("8")){return uuidDivision8;
|
312
|
}else{
|
313
|
return null;
|
314
|
}
|
315
|
}
|
316
|
|
317
|
protected NamedArea newNamedArea(UUID uuid, String label, String text, String IdInVocabulary, NamedAreaType areaType, NamedAreaLevel level, TermVocabulary<NamedArea> voc){
|
318
|
NamedArea namedArea = NamedArea.NewInstance(text, label, null);
|
319
|
voc.addTerm(namedArea);
|
320
|
namedArea.setType(areaType);
|
321
|
namedArea.setLevel(level);
|
322
|
namedArea.setUuid(uuid);
|
323
|
namedArea.setIdInVocabulary(IdInVocabulary);
|
324
|
return namedArea;
|
325
|
}
|
326
|
|
327
|
@Test
|
328
|
public void testGetWebServiceUrlBangka() throws ClientProtocolException, IOException {
|
329
|
NamedArea areaBangka = NamedArea.NewInstance("Bangka", "Bangka", null);
|
330
|
TermVocabulary<NamedArea> voc = TermVocabulary.NewInstance(TermType.NamedArea,
|
331
|
NamedArea.class, "test Voc", "test voc", null, null);
|
332
|
voc.addTerm(areaBangka);
|
333
|
|
334
|
GeoServiceArea geoServiceArea = new GeoServiceArea();
|
335
|
String geoServiceLayer="vmap0_as_bnd_political_boundary_a";
|
336
|
String layerFieldName ="nam";
|
337
|
String areaValue = "PULAU BANGKA#SUMATERA SELATAN";
|
338
|
geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);
|
339
|
geoServiceArea.add(geoServiceLayer, layerFieldName, "BALI");
|
340
|
|
341
|
mapping.set(areaBangka, geoServiceArea);
|
342
|
Set<Distribution> distributions = new HashSet<Distribution>();
|
343
|
distributions.add(Distribution.NewInstance(areaBangka, PresenceAbsenceTerm.PRESENT()));
|
344
|
|
345
|
Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<>();
|
346
|
presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
|
347
|
|
348
|
presenceAbsenceColorMap = null;
|
349
|
List<Language> languages = new ArrayList<Language>();
|
350
|
|
351
|
boolean subAreaPreference = false;
|
352
|
boolean statusOrderPreference = false;
|
353
|
String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions,
|
354
|
mapping,
|
355
|
null, null, languages );
|
356
|
//TODO Set semantics is not determined
|
357
|
//String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";
|
358
|
|
359
|
logger.debug(result);
|
360
|
assertTrue(result.matches(".*ad=vmap0_as_bnd_political_boundary_a%3Anam:.*"));
|
361
|
assertTrue(result.matches(".*(PULAU\\+BANGKA%23SUMATERA\\+SELATAN).*") );
|
362
|
assertTrue(result.matches(".*(BALI).*") );
|
363
|
|
364
|
// request map image from webservice
|
365
|
subTestWithEditMapService(result);
|
366
|
}
|
367
|
|
368
|
@SuppressWarnings("deprecation")
|
369
|
// @Test
|
370
|
@DataSet( value="EditGeoServiceTest.getDistributionServiceRequestParameterString.xml")
|
371
|
// @DataSets({
|
372
|
// @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
373
|
// @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
|
374
|
// @DataSet( value="EditGeoServiceTest.getDistributionServiceRequestParameterString.xml")
|
375
|
// })
|
376
|
public void getDistributionServiceRequestParameterString(){
|
377
|
boolean subAreaPreference = false;
|
378
|
boolean statusOrderPreference = false;
|
379
|
Set<MarkerType> hideMarkedAreas = null;
|
380
|
Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = null;
|
381
|
List<Language> langs = null;
|
382
|
|
383
|
List<TaxonDescription> taxonDescriptions = new ArrayList<>();
|
384
|
TaxonDescription description1 = TaxonDescription.NewInstance();
|
385
|
taxonDescriptions.add(description1);
|
386
|
Distribution distribution1 = Distribution.NewInstance(Country.GERMANY(), null);
|
387
|
description1.addElement(distribution1);
|
388
|
Distribution distribution2 = Distribution.NewInstance(Country.FRANCEFRENCHREPUBLIC(), null);
|
389
|
distribution2.setFeature(Feature.COMMON_NAME());
|
390
|
description1.addElement(distribution2);
|
391
|
|
392
|
Taxon taxon = (Taxon)taxonService.find(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
|
393
|
TaxonDescription taxDesc = taxon.getDescriptions().iterator().next();
|
394
|
for (DescriptionElementBase deb : taxDesc.getElements()){
|
395
|
Distribution distribution = CdmBase.deproxy(deb, Distribution.class);
|
396
|
NamedArea area = distribution.getArea();
|
397
|
System.out.println(area.getTitleCache());
|
398
|
}
|
399
|
taxonDescriptions.addAll(taxon.getDescriptions());
|
400
|
|
401
|
String distributions = editGeoService.getDistributionServiceRequestParameterString(taxonDescriptions,
|
402
|
subAreaPreference, statusOrderPreference, hideMarkedAreas, presenceAbsenceTermColors, langs);
|
403
|
System.out.println(distributions);
|
404
|
Assert.assertTrue("Distribution string should contain the non-persited distribution Germany", distributions.contains("DEU"));
|
405
|
Assert.assertFalse("Distribution string should contain France as it has a non-distribution feature", distributions.contains("FRA"));
|
406
|
|
407
|
// CHE,POL
|
408
|
}
|
409
|
|
410
|
@Override
|
411
|
// @Test
|
412
|
public void createTestDataSet() throws FileNotFoundException {
|
413
|
|
414
|
List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
|
415
|
TaxonDescription description1 = TaxonDescription.NewInstance();
|
416
|
taxonDescriptions.add(description1);
|
417
|
Distribution distribution1 = Distribution.NewInstance(Country.POLANDPOLISHPEOPLESREPUBLIC(), null);
|
418
|
description1.addElement(distribution1);
|
419
|
Distribution distribution2 = Distribution.NewInstance(Country.SWITZERLANDSWISSCONFEDERATION(), null);
|
420
|
// distribution2.setFeature(Feature.COMMON_NAME());
|
421
|
description1.addElement(distribution2);
|
422
|
Taxon taxon = Taxon.NewInstance(null, null);
|
423
|
taxon.setTitleCache("Dummy taxon", true);
|
424
|
taxon.addDescription(description1);
|
425
|
taxon.setUuid(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
|
426
|
|
427
|
taxonService.save(taxon);
|
428
|
|
429
|
setComplete();
|
430
|
endTransaction();
|
431
|
|
432
|
writeDbUnitDataSetFile(new String[] {
|
433
|
"TAXONBASE",
|
434
|
"DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE",
|
435
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
436
|
},
|
437
|
"getDistributionServiceRequestParameterString", true );
|
438
|
}
|
439
|
}
|