Project

General

Profile

« Previous | Next » 

Revision 2dd1849b

Added by Maxime Venin about 13 years ago

Set up of the objects for the tests

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/IdentificationKeyGeneratorTest.java
1 1
package eu.etaxonomy.cdm.api.service;
2 2

  
3
import static org.junit.Assert.*;
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5

  
6
import java.util.ArrayList;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Set;
4 10

  
5 11
import org.apache.log4j.Logger;
6 12
import org.junit.Before;
7 13
import org.junit.Test;
8 14

  
15
import eu.etaxonomy.cdm.model.agent.Person;
16
import eu.etaxonomy.cdm.model.description.CategoricalData;
17
import eu.etaxonomy.cdm.model.description.Feature;
18
import eu.etaxonomy.cdm.model.description.QuantitativeData;
19
import eu.etaxonomy.cdm.model.description.State;
20
import eu.etaxonomy.cdm.model.description.StateData;
21
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
22
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
23
import eu.etaxonomy.cdm.model.description.TaxonDescription;
24
import eu.etaxonomy.cdm.model.name.BotanicalName;
25
import eu.etaxonomy.cdm.model.name.NonViralName;
26
import eu.etaxonomy.cdm.model.name.Rank;
27
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29
import eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy;
30
import eu.etaxonomy.cdm.strategy.generate.IdentificationKeyGenerator;
31

  
32
/**
33
 * @author m.venin
34
 * @created 16.12.2010
35
 * @version 1.0
36
 */
37

  
9 38
public class IdentificationKeyGeneratorTest {
10 39
	private static final Logger logger = Logger.getLogger(IdentificationKeyGeneratorTest.class);
11 40
	
41
	private Feature feature1;
42
	private Feature feature2;
43
	private Feature feature3;
44
	private Feature feature4;
45
	
46
	private Taxon taxon1;
47
	private Taxon taxon2;
48
	private Taxon taxon3;
49
	private Taxon taxon4;
50
	private Taxon taxon5;
51
	private Taxon taxon6;
52
	private Taxon taxon7;
53
	private Taxon taxon8;
54
	
55
	private TaxonDescription taxond1;
56
	private TaxonDescription taxond2;
57
	private TaxonDescription taxond3;
58
	private TaxonDescription taxond4;
59
	private TaxonDescription taxond5;
60
	private TaxonDescription taxond6;
61
	private TaxonDescription taxond7;
62
	private TaxonDescription taxond8;
63
	
64
	private Set<TaxonDescription> taxa;
65
	private List<Feature> features;
66
	
67
	private IdentificationKeyGenerator generator;
68
	
12 69
	@Before
13 70
	public void setUp() throws Exception {
71
		feature1 = Feature.NewInstance("","Shape of the head","");
72
		feature2 = Feature.NewInstance("","Presence of wings","");
73
		feature3 = Feature.NewInstance("","Length of wings","");
74
		feature4 = Feature.NewInstance("","Colour","");
75
		
76
		NonViralName tn1 = NonViralName.NewInstance(null);
77
		NonViralName tn2 = NonViralName.NewInstance(null);
78
		NonViralName tn3 = NonViralName.NewInstance(null);
79
		NonViralName tn4 = NonViralName.NewInstance(null);
80
		NonViralName tn5 = NonViralName.NewInstance(null);
81
		NonViralName tn6 = NonViralName.NewInstance(null);
82
		NonViralName tn7 = NonViralName.NewInstance(null);
83
		NonViralName tn8 = NonViralName.NewInstance(null);
84
		
85
		taxon1 = Taxon.NewInstance(tn1, null);
86
		taxon2 = Taxon.NewInstance(tn2, null);
87
		taxon3 = Taxon.NewInstance(tn3, null);
88
		taxon4 = Taxon.NewInstance(tn4, null);
89
		taxon5 = Taxon.NewInstance(tn5, null);
90
		taxon6 = Taxon.NewInstance(tn6, null);
91
		taxon7 = Taxon.NewInstance(tn7, null);
92
		taxon8 = Taxon.NewInstance(tn8, null);
93
		
94
		taxond1 = TaxonDescription.NewInstance(taxon1);
95
		taxond2 = TaxonDescription.NewInstance(taxon2);
96
		taxond3 = TaxonDescription.NewInstance(taxon3);
97
		taxond4 = TaxonDescription.NewInstance(taxon4);
98
		taxond5 = TaxonDescription.NewInstance(taxon5);
99
		taxond6 = TaxonDescription.NewInstance(taxon6);
100
		taxond7 = TaxonDescription.NewInstance(taxon7);
101
		taxond8 = TaxonDescription.NewInstance(taxon8);
102
		
103
		CategoricalData catd11 = CategoricalData.NewInstance();
104
		catd11.setFeature(feature1);
105
		StateData sd11 = StateData.NewInstance();
106
		State s11 = State.NewInstance("","Triangular","");
107
		State s12 = State.NewInstance("","Circular","");
108
		sd11.setState(s11);
109
		catd11.addState(sd11);
110
		
111
		CategoricalData catd12 = CategoricalData.NewInstance();
112
		catd12.setFeature(feature1);
113
		StateData sd12 = StateData.NewInstance();
114
		sd12.setState(s11);
115
		catd12.addState(sd12);
116
		
117
		CategoricalData catd13 = CategoricalData.NewInstance();
118
		catd13.setFeature(feature1);
119
		StateData sd13 = StateData.NewInstance();
120
		sd13.setState(s11);
121
		catd13.addState(sd13);
122
		
123
		CategoricalData catd14 = CategoricalData.NewInstance();
124
		catd14.setFeature(feature1);
125
		StateData sd14 = StateData.NewInstance();
126
		sd14.setState(s11);
127
		catd14.addState(sd14);
128
		
129
		CategoricalData catd15 = CategoricalData.NewInstance();
130
		catd15.setFeature(feature1);
131
		StateData sd15 = StateData.NewInstance();
132
		sd15.setState(s12);
133
		catd15.addState(sd15);
134
		
135
		CategoricalData catd16 = CategoricalData.NewInstance();
136
		catd16.setFeature(feature1);
137
		StateData sd16 = StateData.NewInstance();
138
		sd16.setState(s12);
139
		catd16.addState(sd16);
140
		
141
		CategoricalData catd17 = CategoricalData.NewInstance();
142
		catd17.setFeature(feature1);
143
		StateData sd17 = StateData.NewInstance();
144
		sd17.setState(s12);
145
		catd17.addState(sd17);
146
		
147
		CategoricalData catd18 = CategoricalData.NewInstance();
148
		catd18.setFeature(feature1);
149
		StateData sd18 = StateData.NewInstance();
150
		sd18.setState(s12);
151
		catd18.addState(sd18);
152
		
153
		/*************************/
154
		
155
		CategoricalData catd21 = CategoricalData.NewInstance();
156
		catd21.setFeature(feature2);
157
		StateData sd21 = StateData.NewInstance();
158
		State s21 = State.NewInstance("","Yes","");
159
		State s22 = State.NewInstance("","No","");
160
		sd21.setState(s21);
161
		catd21.addState(sd21);
162
		
163
		CategoricalData catd22 = CategoricalData.NewInstance();
164
		catd22.setFeature(feature2);
165
		StateData sd22 = StateData.NewInstance();
166
		sd22.setState(s21);
167
		catd22.addState(sd22);
168
		
169
		CategoricalData catd23 = CategoricalData.NewInstance();
170
		catd23.setFeature(feature2);
171
		StateData sd23 = StateData.NewInstance();
172
		sd23.setState(s21);
173
		catd23.addState(sd23);
174
		
175
		CategoricalData catd24 = CategoricalData.NewInstance();
176
		catd24.setFeature(feature2);
177
		StateData sd24 = StateData.NewInstance();
178
		sd24.setState(s21);
179
		catd24.addState(sd24);
180
		
181
		CategoricalData catd25 = CategoricalData.NewInstance();
182
		catd25.setFeature(feature2);
183
		StateData sd25 = StateData.NewInstance();
184
		sd25.setState(s21);
185
		catd25.addState(sd25);
186
		
187
		CategoricalData catd26 = CategoricalData.NewInstance();
188
		catd26.setFeature(feature2);
189
		StateData sd26 = StateData.NewInstance();
190
		sd26.setState(s21);
191
		catd26.addState(sd26);
192
		
193
		CategoricalData catd27 = CategoricalData.NewInstance();
194
		catd27.setFeature(feature2);
195
		StateData sd27 = StateData.NewInstance();
196
		sd27.setState(s21);
197
		catd27.addState(sd27);
198
		
199
		CategoricalData catd28 = CategoricalData.NewInstance();
200
		catd28.setFeature(feature2);
201
		StateData sd28 = StateData.NewInstance();
202
		sd28.setState(s22);
203
		catd28.addState(sd28);
204
		
205
		/*************************/
206
		
207
		QuantitativeData qtd31 = QuantitativeData.NewInstance();
208
		StatisticalMeasurementValue smv311 = StatisticalMeasurementValue.NewInstance();
209
		smv311.setValue(0);
210
		StatisticalMeasure sm311 = StatisticalMeasure.MIN();
211
		smv311.setType(sm311);
212
		StatisticalMeasurementValue smv312 = StatisticalMeasurementValue.NewInstance();
213
		smv312.setValue(3);
214
		StatisticalMeasure sm312 = StatisticalMeasure.MAX();
215
		smv312.setType(sm312);
216
		qtd31.addStatisticalValue(smv311);
217
		qtd31.addStatisticalValue(smv312);
218
		
219
		QuantitativeData qtd32 = QuantitativeData.NewInstance();
220
		StatisticalMeasurementValue smv321 = StatisticalMeasurementValue.NewInstance();
221
		smv321.setValue(0);
222
		StatisticalMeasure sm321 = StatisticalMeasure.MIN();
223
		smv321.setType(sm321);
224
		StatisticalMeasurementValue smv322 = StatisticalMeasurementValue.NewInstance();
225
		smv322.setValue(3);
226
		StatisticalMeasure sm322 = StatisticalMeasure.MAX();
227
		smv322.setType(sm322);
228
		qtd32.addStatisticalValue(smv321);
229
		qtd32.addStatisticalValue(smv322);
230
		
231
		QuantitativeData qtd33 = QuantitativeData.NewInstance();
232
		StatisticalMeasurementValue smv331 = StatisticalMeasurementValue.NewInstance();
233
		smv331.setValue(6);
234
		StatisticalMeasure sm331 = StatisticalMeasure.MIN();
235
		smv331.setType(sm331);
236
		StatisticalMeasurementValue smv332 = StatisticalMeasurementValue.NewInstance();
237
		smv332.setValue(9);
238
		StatisticalMeasure sm332 = StatisticalMeasure.MAX();
239
		smv332.setType(sm332);
240
		qtd33.addStatisticalValue(smv331);
241
		qtd33.addStatisticalValue(smv332);
242
		
243
		QuantitativeData qtd34 = QuantitativeData.NewInstance();
244
		StatisticalMeasurementValue smv341 = StatisticalMeasurementValue.NewInstance();
245
		smv341.setValue(6);
246
		StatisticalMeasure sm341 = StatisticalMeasure.MIN();
247
		smv341.setType(sm341);
248
		StatisticalMeasurementValue smv342 = StatisticalMeasurementValue.NewInstance();
249
		smv342.setValue(9);
250
		StatisticalMeasure sm342 = StatisticalMeasure.MAX();
251
		smv342.setType(sm342);
252
		qtd34.addStatisticalValue(smv341);
253
		qtd34.addStatisticalValue(smv342);
254
		
255
		QuantitativeData qtd35 = QuantitativeData.NewInstance();
256
		StatisticalMeasurementValue smv351 = StatisticalMeasurementValue.NewInstance();
257
		smv351.setValue(0);
258
		StatisticalMeasure sm351 = StatisticalMeasure.MIN();
259
		smv351.setType(sm351);
260
		StatisticalMeasurementValue smv352 = StatisticalMeasurementValue.NewInstance();
261
		smv352.setValue(3);
262
		StatisticalMeasure sm352 = StatisticalMeasure.MAX();
263
		smv352.setType(sm352);
264
		qtd35.addStatisticalValue(smv351);
265
		qtd35.addStatisticalValue(smv352);
266
		
267
		QuantitativeData qtd36 = QuantitativeData.NewInstance();
268
		StatisticalMeasurementValue smv361 = StatisticalMeasurementValue.NewInstance();
269
		smv361.setValue(0);
270
		StatisticalMeasure sm361 = StatisticalMeasure.MIN();
271
		smv361.setType(sm361);
272
		StatisticalMeasurementValue smv362 = StatisticalMeasurementValue.NewInstance();
273
		smv362.setValue(3);
274
		StatisticalMeasure sm362 = StatisticalMeasure.MAX();
275
		smv362.setType(sm362);
276
		qtd36.addStatisticalValue(smv361);
277
		qtd36.addStatisticalValue(smv362);
278
		
279
		QuantitativeData qtd37 = QuantitativeData.NewInstance();
280
		StatisticalMeasurementValue smv371 = StatisticalMeasurementValue.NewInstance();
281
		smv371.setValue(6);
282
		StatisticalMeasure sm371 = StatisticalMeasure.MIN();
283
		smv371.setType(sm371);
284
		StatisticalMeasurementValue smv372 = StatisticalMeasurementValue.NewInstance();
285
		smv372.setValue(9);
286
		StatisticalMeasure sm372 = StatisticalMeasure.MAX();
287
		smv372.setType(sm372);
288
		qtd37.addStatisticalValue(smv371);
289
		qtd37.addStatisticalValue(smv372);
290
		
291
//		QuantitativeData qtd38 = QuantitativeData.NewInstance();
292
//		StatisticalMeasurementValue smv381 = StatisticalMeasurementValue.NewInstance();
293
//		smv381.setValue(6);
294
//		StatisticalMeasure sm381 = StatisticalMeasure.MIN();
295
//		smv381.setType(sm381);
296
//		StatisticalMeasurementValue smv382 = StatisticalMeasurementValue.NewInstance();
297
//		smv382.setValue(9);
298
//		StatisticalMeasure sm382 = StatisticalMeasure.MAX();
299
//		smv382.setType(sm382);
300
//		qtd38.addStatisticalValue(smv381);
301
//		qtd38.addStatisticalValue(smv382);
302
		
303
		/*************************/
304
		
305
		CategoricalData catd41 = CategoricalData.NewInstance();
306
		catd41.setFeature(feature4);
307
		StateData sd41 = StateData.NewInstance();
308
		State s41 = State.NewInstance("","Blue","");
309
		State s42 = State.NewInstance("","Yellow","");
310
		sd41.setState(s41);
311
		catd41.addState(sd41);
312
		
313
		CategoricalData catd42 = CategoricalData.NewInstance();
314
		catd42.setFeature(feature4);
315
		StateData sd42 = StateData.NewInstance();
316
		sd42.setState(s42);
317
		catd42.addState(sd42);
318
		
319
		CategoricalData catd43 = CategoricalData.NewInstance();
320
		catd43.setFeature(feature4);
321
		StateData sd43 = StateData.NewInstance();
322
		sd43.setState(s41);
323
		catd43.addState(sd43);
324
		
325
		CategoricalData catd44 = CategoricalData.NewInstance();
326
		catd44.setFeature(feature4);
327
		StateData sd44 = StateData.NewInstance();
328
		sd44.setState(s42);
329
		catd44.addState(sd44);
330
		
331
		CategoricalData catd45 = CategoricalData.NewInstance();
332
		catd45.setFeature(feature4);
333
		StateData sd45 = StateData.NewInstance();
334
		sd45.setState(s41);
335
		catd45.addState(sd45);
336
		
337
		CategoricalData catd46 = CategoricalData.NewInstance();
338
		catd46.setFeature(feature4);
339
		StateData sd46 = StateData.NewInstance();
340
		sd46.setState(s41);
341
		catd46.addState(sd46);
342
		
343
		CategoricalData catd47 = CategoricalData.NewInstance();
344
		catd47.setFeature(feature4);
345
		StateData sd47 = StateData.NewInstance();
346
		sd47.setState(s41);
347
		catd47.addState(sd47);
348
		
349
		CategoricalData catd48 = CategoricalData.NewInstance();
350
		catd48.setFeature(feature4);
351
		StateData sd48 = StateData.NewInstance();
352
		sd48.setState(s41);
353
		catd48.addState(sd48);
354
		
355
		/*************************/
356
		
357
		taxond1.addElement(catd11);
358
		taxond1.addElement(catd21);
359
		taxond1.addElement(qtd31);
360
		taxond1.addElement(catd41);
361
		
362
		taxond2.addElement(catd12);
363
		taxond2.addElement(catd22);
364
		taxond2.addElement(qtd32);
365
		taxond2.addElement(catd42);
366
		
367
		taxond3.addElement(catd13);
368
		taxond3.addElement(catd23);
369
		taxond3.addElement(qtd33);
370
		taxond3.addElement(catd43);
371
		
372
		taxond4.addElement(catd14);
373
		taxond4.addElement(catd24);
374
		taxond4.addElement(qtd34);
375
		taxond4.addElement(catd44);
376
		
377
		taxond5.addElement(catd15);
378
		taxond5.addElement(catd25);
379
		taxond5.addElement(qtd35);
380
		taxond5.addElement(catd45);
381
		
382
		taxond6.addElement(catd16);
383
		taxond6.addElement(catd26);
384
		taxond6.addElement(qtd36);
385
		taxond6.addElement(catd46);
386
		
387
		taxond7.addElement(catd17);
388
		taxond7.addElement(catd27);
389
		taxond7.addElement(qtd37);
390
		taxond7.addElement(catd47);
391
		
392
		taxond8.addElement(catd18);
393
		taxond8.addElement(catd28);
394
//		taxond8.addElement(qtd38); // This taxon has no wings
395
		taxond8.addElement(catd48);
396
		
397
		/*************************/
398
		
399
		features = new ArrayList<Feature>();
400
		features.add(feature1);
401
		features.add(feature2);
402
		features.add(feature3);
403
		features.add(feature4);
404
		
405
		taxa = new HashSet<TaxonDescription>();
406
		taxa.add(taxond1);
407
		taxa.add(taxond2);
408
		taxa.add(taxond3);
409
		taxa.add(taxond4);
410
		taxa.add(taxond5);
411
		taxa.add(taxond6);
412
		taxa.add(taxond7);
413
		taxa.add(taxond8);
414
		
14 415
	}
15 416
	
16 417
//*************************** TESTS *********************** /
......
18 419

  
19 420
	@Test
20 421
	public void testInvoke() {
21
		logger.warn("TestInvoke Not yet implemented");
422
		generator = new IdentificationKeyGenerator();
423
		generator.setFeatures(features);
424
		generator.setTaxa(taxa);
425
		assertNotNull("Key should exist.",generator.invoke());
22 426
	}
23 427

  
428
	@Test
429
	public void testInvokeMergeModeON() {
430
//		generator = new IdentificationKeyGenerator();
431
//		generator.setFeatures(features);
432
//		generator.setTaxa(taxa);
433
//		generator.mergeModeON();
434
//		generator.invoke();
435
//		assertNotNull("Key should exist (merge mode ON).",generator.invoke());;
436
	}
437
	
438
	@Test
439
	public void testInvokeWithDependencies() {
440
//		generator = new IdentificationKeyGenerator();
441
//		generator.setFeatures(features);
442
//		generator.setTaxa(taxa);
443
////		generator.setDependencies(tree);// TODO create a tree with dependencies to test this function
444
//		generator.invoke();
445
//		assertNotNull("Key should exist (dependencies are present).",generator.invoke());;
446
	}
447
	
24 448
}

Also available in: Unified diff