Project

General

Profile

« Previous | Next » 

Revision 90046bc4

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib-model #5830

View differences:

cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/merge/DefaultMergeStrategyTest.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
35 35
import eu.etaxonomy.cdm.model.common.LSID;
36 36
import eu.etaxonomy.cdm.model.common.TimePeriod;
37 37
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
38
import eu.etaxonomy.cdm.model.location.Country;
38 39
import eu.etaxonomy.cdm.model.location.Point;
39 40
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
40
import eu.etaxonomy.cdm.model.location.Country;
41 41
import eu.etaxonomy.cdm.model.name.BotanicalName;
42 42
import eu.etaxonomy.cdm.model.name.NameRelationship;
43 43
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
......
59 59
	private static final Logger logger = Logger.getLogger(DefaultMergeStrategyTest.class);
60 60

  
61 61
	private DefaultMergeStrategy bookMergeStrategy;
62
	private Reference<?> book1;
62
	private Reference book1;
63 63
	private String editionString1 ="Ed.1";
64 64
	private String volumeString1 ="Vol.1";
65 65
	private Team team1;
66
	private Reference<?> printSeries1;
66
	private Reference printSeries1;
67 67
	private Annotation annotation1;
68 68
	private String title1 = "Title1";
69 69
	private TimePeriod datePublished1 = TimePeriod.NewInstance(2000);
70 70
	private int hasProblem1 = 1;
71 71
	private LSID lsid1;
72
	
73
	private Reference<?> book2;
72

  
73
	private Reference book2;
74 74
	private String editionString2 ="Ed.2";
75 75
	private String volumeString2 ="Vol.2";
76 76
	private Team team2;
77
	private Reference<?> printSeries2;
77
	private Reference printSeries2;
78 78
	private Annotation annotation2;
79 79
	private String annotationString2;
80 80
	private String title2 = "Title2";
......
82 82
	private TimePeriod datePublished2 = TimePeriod.NewInstance(2002);
83 83
	private int hasProblem2 = 1;
84 84
	private LSID lsid2;
85
	
86
	
87
	private Reference<?> book3;
88
	
85

  
86

  
87
	private Reference book3;
88

  
89 89
	/**
90 90
	 * @throws java.lang.Exception
91 91
	 */
......
117 117
		annotation1 = Annotation.NewInstance("Annotation1", null);
118 118
		annotationString2 = "Annotation2";
119 119
		annotation2 = Annotation.NewInstance(annotationString2, null);
120
		
120

  
121 121
		book1 = ReferenceFactory.newBook();
122 122
		book1.setAuthorship(team1);
123 123
		book1.setTitle(title1);
......
130 130
		lsid1 = new LSID("authority1", "namespace1", "object1", "revision1");
131 131
		book1.setLsid(lsid1);
132 132
		book1.setNomenclaturallyRelevant(false);
133
		
133

  
134 134
		book2 = ReferenceFactory.newBook();
135 135
		book2.setAuthorship(team2);
136 136
		book2.setTitle(title2);
......
144 144
		lsid2 = new LSID("authority2", "namespace2", "object2", "revision2");
145 145
		book2.setLsid(lsid2);
146 146
		book2.setNomenclaturallyRelevant(true);
147
		
147

  
148 148
	}
149 149

  
150 150
	/**
......
154 154
	public void tearDown() throws Exception {
155 155
	}
156 156

  
157
//********************* TEST *********************************************/	
158
	
157
//********************* TEST *********************************************/
158

  
159 159
	/**
160 160
	 * Test method for {@link eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy#NewInstance(java.lang.Class)}.
161 161
	 */
......
213 213
		} catch (Exception e) {
214 214
			//ok
215 215
		}
216
		
217
		
216

  
217

  
218 218
	}
219 219

  
220
	
220

  
221 221
	/**
222 222
	 * Test method for {@link eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy#invoke(eu.etaxonomy.cdm.strategy.merge.IMergable, eu.etaxonomy.cdm.strategy.merge.IMergable)}.
223
	 * @throws MergeException 
223
	 * @throws MergeException
224 224
	 */
225 225
	@Test
226 226
	public void testInvokeReferences() throws MergeException {
......
237 237
			bookMergeStrategy.setMergeMode("parsingProblem", MergeMode.SECOND);
238 238
			bookMergeStrategy.setMergeMode("inReference", MergeMode.SECOND);
239 239
			bookMergeStrategy.setMergeMode("lsid", MergeMode.SECOND);
240
			
240

  
241 241
			bookMergeStrategy.invoke(book1, book2);
242 242
		} catch (MergeException e) {
243 243
			throw e;
......
246 246
		Assert.assertEquals("Title should stay the same", title1, book1.getTitle());
247 247
		Assert.assertEquals("Edition should become edition 2", editionString2, book1.getEdition());
248 248
		Assert.assertNull("Volume should be null", book1.getVolume());
249
		
249

  
250 250
		//Boolean
251 251
		Assert.assertEquals("Has problem must be hasProblem2", hasProblem2, book1.getParsingProblem());
252 252
		Assert.assertEquals("nomenclaturally relevant must have value true (AND semantics)", true, book1.isNomenclaturallyRelevant() );
253
		
254
		
253

  
254

  
255 255
		//CdmBase
256 256
		Assert.assertSame("Authorship must be the one of book2", team2, book1.getAuthorship());
257 257
		Assert.assertSame("In Series must be the one of book2", printSeries2, book1.getInReference());
258
		
258

  
259 259
		//Transient
260 260
		Assert.assertSame("Cache strategy is transient and shouldn't change therefore", cacheStrategy1, book1.getCacheStrategy());
261
		
262
		
261

  
262

  
263 263
		//UserType
264 264
		Assert.assertSame("Created must be created2", created2, book1.getCreated());
265 265
		//TODO updated should have the actual date if any value has changed
......
267 267
		Assert.assertSame("Created must be datePublsihed2", datePublished2, book1.getDatePublished());
268 268
		//TODO this may not be correct
269 269
		Assert.assertSame("LSID must be LSID2", lsid2, book1.getLsid());
270
		
270

  
271 271

  
272 272
		//TODO
273 273
		//	book1.setProblemEnds(end);
274 274
		//	book1.setProtectedTitleCache(protectedTitleCache);
275
		
275

  
276 276
		//annotations -> ADD_CLONE
277 277
		Assert.assertEquals("Annotations should contain annotations of both books", 2, book1.getAnnotations().size());
278 278
		boolean cloneExists = false;
279 279
		for (Annotation annotation : book1.getAnnotations()){
280 280
			if (annotation == this.annotation2){
281
				//Hibernate will not persist the exact same object. Probably this is a bug (the according row in the 
281
				//Hibernate will not persist the exact same object. Probably this is a bug (the according row in the
282 282
				//M:M table is not deleted and a unique constraints does not allow adding 2 rows with the same annotation_id
283
				//This test can be changed once this bug does not exist anymore 
283
				//This test can be changed once this bug does not exist anymore
284 284
				Assert.fail("Book1 should contain a clone of annotation2 but contains annotation2 itself");
285 285
			}else if (annotationString2.equals(annotation.getText())){
286 286
				cloneExists = true;
......
288 288
		}
289 289
		Assert.assertTrue("Book1 should contain a clone of annotation2", cloneExists);
290 290
	//	Assert.assertEquals("Annotations from book2 should be deleted", 0, book2.getAnnotations().size());
291
		
291

  
292 292
		//identifier
293 293
		Assert.assertSame("Identifier must never be changed", id, book1.getId());
294 294
		Assert.assertSame("Identifier must never be changed", uuid, book1.getUuid());
295
		
295

  
296 296
		//Test Thesis
297 297
		Institution school1 = Institution.NewInstance();
298 298
		Institution school2 = Institution.NewInstance();
299
		
300
		Reference<?> thesis1 = ReferenceFactory.newThesis();
299

  
300
		Reference thesis1 = ReferenceFactory.newThesis();
301 301
		thesis1.setSchool(school1);
302 302
		//Thesis thesis1 = Thesis.NewInstance(school1);
303
		Reference<?> thesis2 = ReferenceFactory.newThesis();
303
		Reference thesis2 = ReferenceFactory.newThesis();
304 304
		thesis2.setSchool(school2);
305 305
		DefaultMergeStrategy thesisStrategy = DefaultMergeStrategy.NewInstance(Reference.class);
306
		
306

  
307 307
		thesisStrategy.setMergeMode("school", MergeMode.SECOND);
308 308
		thesisStrategy.invoke(thesis1, thesis2);
309
		Assert.assertSame("school must be school2", school2, thesis1.getSchool());	
309
		Assert.assertSame("school must be school2", school2, thesis1.getSchool());
310 310
	}
311
	
312
	
311

  
312

  
313 313
	/**
314 314
	 * Test method for {@link eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy#invoke(eu.etaxonomy.cdm.strategy.merge.IMergable, eu.etaxonomy.cdm.strategy.merge.IMergable)}.
315
	 * @throws MergeException 
315
	 * @throws MergeException
316 316
	 */
317 317
	@Test
318 318
	//@Ignore
......
321 321
		BotanicalName botName1 = BotanicalName.NewInstance(Rank.SPECIES());
322 322
		BotanicalName botName2 = BotanicalName.NewInstance(Rank.SPECIES());
323 323
		BotanicalName botName3 = BotanicalName.NewInstance(Rank.SPECIES());
324
		
324

  
325 325
		botName1.setGenusOrUninomial("Genus1");
326 326
		botName1.setSpecificEpithet("species1");
327 327
		botName1.setAnamorphic(true);
328
		
328

  
329 329
		botName2.setGenusOrUninomial("Genus2");
330 330
		botName2.setSpecificEpithet("species2");
331 331
		botName2.setAnamorphic(false);
332
		
332

  
333 333
		//name relations
334 334
		botName2.addBasionym(botName3, book1, "p.22", null);
335 335
		DerivedUnit specimen1 = DerivedUnit.NewPreservedSpecimenInstance();
336 336
		botName2.addSpecimenTypeDesignation(specimen1, SpecimenTypeDesignationStatus.HOLOTYPE(), book2, "p.56", "originalNameString", false, true);
337
		
337

  
338 338
		//descriptions
339 339
		TaxonNameDescription description1 = TaxonNameDescription.NewInstance();
340 340
		botName1.addDescription(description1);
341 341
		TaxonNameDescription description2 = TaxonNameDescription.NewInstance();
342 342
		botName1.addDescription(description2);
343
		
343

  
344 344
		//authors
345 345
		Team team1 = Team.NewInstance();
346 346
		Team team2 = Team.NewInstance();
347 347
		Person person1 = Person.NewInstance();
348 348
		botName1.setCombinationAuthorship(team1);
349 349
		botName2.setCombinationAuthorship(team2);
350
		
350

  
351 351
		//taxa
352 352
		TaxonBase<?> taxon1= Taxon.NewInstance(botName1, book1);
353 353
		TaxonBase<?> taxon2= Taxon.NewInstance(botName2, book2);
354
		
354

  
355 355
		try {
356 356
			botNameMergeStrategy.setMergeMode("combinationAuthorship", MergeMode.SECOND);
357 357
			botNameMergeStrategy.setMergeMode("anamorphic", MergeMode.AND);
358
			
358

  
359 359
//			botNameMergeStrategy.invoke(botName1, botName2);
360 360
		} catch (MergeException e) {
361 361
			throw e;
......
364 364

  
365 365
		//Boolean
366 366
		Assert.assertEquals("Is anamorphic must be false", true && false, botName2.isAnamorphic());
367
		
367

  
368 368
		//NameRelations
369 369
		Set<NameRelationship> toRelations = botName2.getRelationsToThisName();
370 370
		Set<NameRelationship> basionymRelations = new HashSet<NameRelationship>();
......
376 376
		Assert.assertEquals("Number of basionyms must be 1", 1, basionymRelations.size());
377 377
		Assert.assertEquals("Basionym must have same reference", book1, basionymRelations.iterator().next().getCitation());
378 378
		//TODO merge relation if matches() = true
379
		
379

  
380 380
		//Types
381 381
		Assert.assertEquals("Number of specimen type designations must be 1", 1, botName2.getSpecimenTypeDesignations().size());
382 382
		//TODO add to all names etc.
383
		
383

  
384 384
		//Description
385 385
		Assert.assertEquals("Number of descriptions must be 2", 2, botName1.getDescriptions().size());
386
		
386

  
387 387
		//Authorships
388 388
		Assert.assertEquals("Combination author must be combination author 1", team1, botName1.getCombinationAuthorship());
389
		
389

  
390 390
		//Taxa
391 391
		Assert.assertEquals("TaxonName of taxon1 must be name1", botName1, taxon1.getName());
392 392
		Assert.assertEquals("TaxonName of taxon2 must be name2", botName2, taxon2.getName());
393
		
393

  
394 394
	}
395
	
395

  
396 396
	/**
397 397
	 * Test method for {@link eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy#invoke(eu.etaxonomy.cdm.strategy.merge.IMergable, eu.etaxonomy.cdm.strategy.merge.IMergable)}.
398
	 * @throws MergeException 
398
	 * @throws MergeException
399 399
	 */
400 400
	@Test
401 401
	public void testInvokeAgents() throws MergeException {
402 402
		IMergeStrategy teamMergeStrategy = DefaultMergeStrategy.NewInstance(Team.class);
403
		
403

  
404 404
		Team team1 = Team.NewInstance();
405 405
		Team team2 = Team.NewInstance();
406 406
		Team team3 = Team.NewInstance();
407
		
407

  
408 408
		Person person1 = Person.NewTitledInstance("person1");
409 409
		Person person2 = Person.NewTitledInstance("person2");
410 410
		Person person3 = Person.NewTitledInstance("person3");
411
		
411

  
412 412
		team1.setTitleCache("Team1", true);
413 413
		team1.setNomenclaturalTitle("T.1");
414 414
		String street1 = "Strasse1";
......
418 418
		team2.addAddress(street3, null, null, null, null, null, Point.NewInstance(1.1, 2.2, null, 4));
419 419
		String emailAddress1 = "Email1";
420 420
		team1.addEmailAddress(emailAddress1);
421
		
421

  
422 422
		team2.addTeamMember(person1);
423 423
		team2.addTeamMember(person2);
424 424
		String emailAddress2 = "Email2";
425 425
		team2.addEmailAddress(emailAddress2);
426
		
426

  
427 427
		team3.addTeamMember(person3);
428 428
		team3.addEmailAddress("emailAddress3");
429
		
429

  
430 430
		teamMergeStrategy.invoke(team2, team3);
431
		
431

  
432 432
		Assert.assertEquals("Team2 must have 3 persons as members",3, team2.getTeamMembers().size());
433 433
		Assert.assertTrue("Team2 must have person3 as new member", team2.getTeamMembers().contains(person3));
434 434
		Assert.assertSame("Team2 must have person3 as third member",person3, team2.getTeamMembers().get(2));
435
		
436
		//Contact 
435

  
436
		//Contact
437 437
		teamMergeStrategy.invoke(team2, team1);
438 438
		Contact team2Contact = team2.getContact();
439 439
		Assert.assertNotNull("team2Contact must not be null", team2Contact);
440 440
		Assert.assertNotNull("Addresses must not be null", team2Contact.getAddresses());
441 441
		Assert.assertEquals("Number of addresses must be 3", 3, team2Contact.getAddresses().size());
442 442
		Assert.assertEquals("Number of email addresses must be 4", 4, team2Contact.getEmailAddresses().size());
443
		
443

  
444 444
		boolean street1Exists = false;
445 445
		boolean street3Exists = false;
446 446
		boolean country1Exists = false;
......
458 458
		Assert.assertTrue("Street1 must be one of the streets in team2's addresses", street1Exists);
459 459
		Assert.assertTrue("Street3 must be one of the streets in team2's addressesss", street3Exists);
460 460
		Assert.assertTrue("Argentina must be one of the countries in team2's addresses", country1Exists);
461
		
461

  
462 462
		//Person
463 463
		Institution institution1 = Institution.NewInstance();
464 464
		institution1.setTitleCache("inst1", true);
465 465
		Institution institution2 = Institution.NewInstance();
466 466
		institution2.setTitleCache("inst2", true);
467
		
467

  
468 468
		TimePeriod period1 = TimePeriod.NewInstance(2002, 2004);
469 469
		TimePeriod period2 = TimePeriod.NewInstance(2004, 2006);
470
		
470

  
471 471
		person1.addInstitutionalMembership(institution1, period1, "departement1", "role1");
472 472
		person2.addInstitutionalMembership(institution2, period2, "departement2", "role2");
473 473

  
474 474
		IMergeStrategy personMergeStrategy = DefaultMergeStrategy.NewInstance(Person.class);
475 475
		personMergeStrategy.invoke(person1, person2);
476
		
476

  
477 477
		Assert.assertEquals("Number of institutional memberships must be 2", 2, person1.getInstitutionalMemberships().size());
478 478
		for (InstitutionalMembership institutionalMembership : person1.getInstitutionalMemberships()){
479 479
			Assert.assertSame("Person of institutional memebership must be person1", person1, institutionalMembership.getPerson());
480 480
		}
481
		
481

  
482 482
	}
483
	
483

  
484 484
}

Also available in: Unified diff