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/match/DefaultMatchStrategyTest.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
*/
......
29 29
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
30 30
import eu.etaxonomy.cdm.model.common.LSID;
31 31
import eu.etaxonomy.cdm.model.common.TimePeriod;
32
import eu.etaxonomy.cdm.model.location.Country;
32 33
import eu.etaxonomy.cdm.model.location.Point;
33 34
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
34
import eu.etaxonomy.cdm.model.location.Country;
35 35
import eu.etaxonomy.cdm.model.name.BotanicalName;
36 36
import eu.etaxonomy.cdm.model.name.Rank;
37 37
import eu.etaxonomy.cdm.model.reference.IBook;
......
60 60
	private TimePeriod datePublished1 = TimePeriod.NewInstance(2000);
61 61
	private int hasProblem1 = 1;
62 62
	private LSID lsid1;
63
	
63

  
64 64
	private IBook book2;
65 65
	private String editionString2 ="Ed.2";
66 66
	private String volumeString2 ="Vol.2";
......
73 73
	private TimePeriod datePublished2 = TimePeriod.NewInstance(2002);
74 74
	private int hasProblem2 = 1;
75 75
	private LSID lsid2;
76
	
76

  
77 77
	private IBook book3;
78
	
78

  
79 79
	/**
80 80
	 * @throws java.lang.Exception
81 81
	 */
......
107 107
		annotation1 = Annotation.NewInstance("Annotation1", null);
108 108
		annotationString2 = "Annotation2";
109 109
		annotation2 = Annotation.NewInstance(annotationString2, null);
110
		
110

  
111 111
		book1 = ReferenceFactory.newBook();
112 112
		book1.setAuthorship(team1);
113 113
		book1.setTitle(title1);
......
119 119
		book1.setParsingProblem(hasProblem1);
120 120
		lsid1 = new LSID("authority1", "namespace1", "object1", "revision1");
121 121
		book1.setLsid(lsid1);
122
		((Reference<?>) book1).setNomenclaturallyRelevant(false);
123
		
122
		((Reference) book1).setNomenclaturallyRelevant(false);
123

  
124 124
		book2 = ReferenceFactory.newBook();
125 125
		book2.setAuthorship(team2);
126 126
		book2.setTitle(title2);
......
133 133
		book2.setParsingProblem(hasProblem2);
134 134
		lsid2 = new LSID("authority2", "namespace2", "object2", "revision2");
135 135
		book2.setLsid(lsid2);
136
		((Reference<?>) book2).setNomenclaturallyRelevant(true);
137
		
136
		((Reference) book2).setNomenclaturallyRelevant(true);
137

  
138 138
	}
139 139

  
140 140
	/**
......
144 144
	public void tearDown() throws Exception {
145 145
	}
146 146

  
147
//********************* TEST *********************************************/	
148
	
147
//********************* TEST *********************************************/
148

  
149 149
	/**
150 150
	 * Test method for {@link eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy#NewInstance(java.lang.Class)}.
151 151
	 */
......
199 199
	public void testInvokeCache() throws MatchException {
200 200
		matchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
201 201
		Assert.assertTrue("Same object should always match", matchStrategy.invoke(book1, book1));
202
		
202

  
203 203
		IBook bookClone = (IBook) book1.clone();
204 204
		Assert.assertTrue("Cloned book should match", matchStrategy.invoke(book1, bookClone));
205 205
		book1.setTitleCache("cache1",true);
206 206
		Assert.assertFalse("Cached book should not match", matchStrategy.invoke(book1, bookClone));
207
		
207

  
208 208
		bookClone.setTitleCache("cache1",true);
209 209
		Assert.assertTrue("Cached book with same cache should match", matchStrategy.invoke(book1, bookClone));
210
			
210

  
211 211
		bookClone.setTitleCache("cache2",true);
212 212
		Assert.assertFalse("Cached book with differings caches should not match", matchStrategy.invoke(book1, bookClone));
213 213
		bookClone.setTitleCache("cache1",true); //restore
214
		
214

  
215 215
		bookClone.setEdition(null);
216 216
		Assert.assertTrue("Cached book with a defined and a null edition should match", matchStrategy.invoke(book1, bookClone));
217 217

  
......
219 219
		BotanicalName botName1 = BotanicalName.NewInstance(Rank.GENUS());
220 220
		BotanicalName botName2 = BotanicalName.NewInstance(Rank.GENUS());
221 221
		Assert.assertNotNull("Rank should not be null", botName1.getRank());
222
		
222

  
223 223
		botName1.setGenusOrUninomial("Genus1");
224 224
		botName2.setGenusOrUninomial("Genus1");
225 225
		Assert.assertTrue("Names with equal genus should match", matchStrategy.invoke(botName1, botName2));
226
		
226

  
227 227
		botName1.setCombinationAuthorship(team1);
228 228
		botName2.setCombinationAuthorship(null);
229 229
		Assert.assertFalse("Names one having an author the other one not should not match", matchStrategy.invoke(botName1, botName2));
230
		
230

  
231 231
		botName1.setAuthorshipCache("authorCache1");
232 232
		botName2.setAuthorshipCache("authorCache1");
233 233
		Assert.assertTrue("Names with cached authors should match", matchStrategy.invoke(botName1, botName2));
234
		
234

  
235 235
	}
236
	
237
	
236

  
237

  
238 238
	@Test
239 239
	public void testInvokeReferences() throws MatchException {
240 240
		matchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
241 241
		Assert.assertTrue("Same object should always match", matchStrategy.invoke(book1, book1));
242
		
243
		IBook bookClone = (IBook) ((Reference<?>) book1).clone();
242

  
243
		IBook bookClone = (IBook) ((Reference) book1).clone();
244 244
		Assert.assertTrue("Cloned book should match", matchStrategy.invoke(book1, bookClone));
245 245
		bookClone.setTitle("Any title");
246 246
		Assert.assertFalse("Books with differing titles should not match", matchStrategy.invoke(book1, bookClone));
......
252 252
		Assert.assertFalse("Books with no title should not match", matchStrategy.invoke(book1, bookClone));
253 253
		book1.setTitle(originalTitle);
254 254
		bookClone.setTitle(originalTitle);
255
		
256
		
255

  
256

  
257 257
		bookClone.setInSeries(printSeries2);
258 258
		Assert.assertFalse("Cloned book with differing print series should not match", matchStrategy.invoke(book1, bookClone));
259
		IPrintSeries seriesClone = (IPrintSeries)((Reference<?>)printSeries1).clone();
259
		IPrintSeries seriesClone = (IPrintSeries)((Reference)printSeries1).clone();
260 260
		bookClone.setInSeries(seriesClone);
261 261
		Assert.assertTrue("Cloned book with cloned bookSeries should match", matchStrategy.invoke(book1, bookClone));
262 262
		seriesClone.setTitle("Another title");
263 263
		Assert.assertFalse("Cloned book should not match with differing series title", matchStrategy.invoke(book1, bookClone));
264 264
		bookClone.setInSeries(printSeries1);
265 265
		Assert.assertTrue("Original printSeries should match", matchStrategy.invoke(book1, bookClone));
266
		
266

  
267 267
		IBook bookTitle1 = ReferenceFactory.newBook();
268 268
		IBook bookTitle2 = ReferenceFactory.newBook();
269 269
		Assert.assertFalse("Books without title should not match", matchStrategy.invoke(bookTitle1, bookTitle2));
......
274 274
		bookTitle1.setTitle("");
275 275
		bookTitle2.setTitle("");
276 276
		Assert.assertFalse("Books with empty title should not match", matchStrategy.invoke(bookTitle1, bookTitle2));
277
		
277

  
278 278
		//Time period
279 279
		bookTitle1.setTitle(title);
280 280
		bookTitle2.setTitle(title);
......
296 296
		section2.setInBook(bookTitle1);
297 297
		section2.setTitle("SecTitle");
298 298
		section2.setPages("22-33");
299
		
300
		
299

  
300

  
301 301
		IMatchStrategy bookSectionMatchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
302 302
		Assert.assertTrue("Equal BookSections should match", bookSectionMatchStrategy.invoke(section1, section2));
303 303
		section2.setInBook(bookTitle2);
......
314 314
		bookTitle2.setInSeries(printSeries2);
315 315
		Assert.assertFalse("Books with not matching in series should not match", matchStrategy.invoke(bookTitle1, bookTitle2));
316 316
		Assert.assertFalse("Sections with differing print series should not match", bookSectionMatchStrategy.invoke(section1, section2));
317
		
317

  
318 318
		//Authorship
319 319
		Person person1 = Person.NewTitledInstance("person");
320 320
		Person person2 = Person.NewTitledInstance("person");
321
		
321

  
322 322
		person1.setPrefix("pre1");
323 323
		person2.setPrefix("pre2");
324
		book2= (IBook) ((Reference<?>) book1).clone();
325
		
324
		book2= (IBook) ((Reference) book1).clone();
325

  
326 326
		Assert.assertTrue("Equal books should match", matchStrategy.invoke(book1, book2));
327
		
327

  
328 328
		book1.setAuthorship(person1);
329 329
		book2.setAuthorship(person1);
330 330
		Assert.assertTrue("Books with same author should match", matchStrategy.invoke(book1, book2));
331
		
331

  
332 332
		book2.setAuthorship(person2);
333 333
		Assert.assertFalse("Books with different authors should not match", matchStrategy.invoke(book1, book2));
334
		
334

  
335 335
		person2.setPrefix("pre1");
336
		Assert.assertTrue("Books with matching authors should not match", matchStrategy.invoke(book1, book2));		
336
		Assert.assertTrue("Books with matching authors should not match", matchStrategy.invoke(book1, book2));
337 337
	}
338
	
339
	
338

  
339

  
340 340
	/**
341 341
	 * Test method for {@link eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy#invoke(eu.etaxonomy.cdm.strategy.match.IMergable, eu.etaxonomy.cdm.strategy.match.IMergable)}.
342
	 * @throws MatchException 
342
	 * @throws MatchException
343 343
	 */
344 344
	@Test
345 345
	public void testInvokeTaxonNames() throws MatchException {
346 346
		matchStrategy = DefaultMatchStrategy.NewInstance(BotanicalName.class);
347
		
347

  
348 348
		BotanicalName botName1 = BotanicalName.NewInstance(Rank.SPECIES());
349 349
		BotanicalName botName2 = BotanicalName.NewInstance(Rank.SPECIES());
350 350
		BotanicalName botName3 = BotanicalName.NewInstance(Rank.SPECIES());
351
	
351

  
352 352
		Assert.assertFalse("Names without title should not match", matchStrategy.invoke(botName1, botName2));
353
		
353

  
354 354
		botName1.setGenusOrUninomial("Genus1");
355 355
		botName1.setSpecificEpithet("species1");
356
		
356

  
357 357
		botName2.setGenusOrUninomial("Genus1");
358 358
		botName2.setSpecificEpithet("species1");
359 359
		Assert.assertTrue("Similar names with titles set should match", matchStrategy.invoke(botName1, botName2));
360
		
361
		
360

  
361

  
362 362
		botName1.setAnamorphic(true);
363 363
		botName2.setAnamorphic(false);
364 364
		Assert.assertFalse("Similar names with differing boolean marker values should not match", matchStrategy.invoke(botName1, botName2));
365 365
		botName2.setAnamorphic(true);
366 366
		Assert.assertTrue("Similar names with same boolean marker values should match", matchStrategy.invoke(botName1, botName2));
367
		
368
		
369
		
367

  
368

  
369

  
370 370
//		//name relations
371 371
//		botName2.addBasionym(botName3, book1, "p.22", null);
372 372
//		Specimen specimen1 = Specimen.NewInstance();
373 373
//		botName2.addSpecimenTypeDesignation(specimen1, SpecimenTypeDesignationStatus.HOLOTYPE(), book2, "p.56", "originalNameString", false, true);
374
//		
374
//
375 375
//		//descriptions
376 376
//		TaxonNameDescription description1 = TaxonNameDescription.NewInstance();
377 377
//		botName1.addDescription(description1);
378 378
//		TaxonNameDescription description2 = TaxonNameDescription.NewInstance();
379 379
//		botName2.addDescription(description2);
380
		
380

  
381 381
		//authors
382 382
		Team team1 = Team.NewInstance();
383 383
		Team team2 = Team.NewInstance();
......
385 385
		botName2.setCombinationAuthorship(team2);
386 386
		Assert.assertTrue("Similar teams should match", DefaultMatchStrategy.NewInstance(Team.class).invoke(team1, team2));
387 387
		Assert.assertTrue("Similar names with matching authors should match", matchStrategy.invoke(botName1, botName2));
388
		
388

  
389 389
	}
390
	
390

  
391 391
	/**
392 392
	 * Test method for {@link eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy#invoke(IMatchable, IMatchable), eu.etaxonomy.cdm.strategy.match.IMatchable)}.
393
	 * @throws MatchException 
393
	 * @throws MatchException
394 394
	 */
395 395
	@Test
396 396
	public void testInvokeAgents() throws MatchException {
397 397
		IMatchStrategy matchStrategy = DefaultMatchStrategy.NewInstance(Team.class);
398
		
398

  
399 399
		Team team1 = Team.NewInstance();
400 400
		Team team2 = Team.NewInstance();
401 401
		Team team3 = Team.NewInstance();
402
		
402

  
403 403
		Assert.assertTrue("Teams should match", matchStrategy.invoke(team1, team2));
404 404
		Assert.assertTrue("Teams should match", matchStrategy.invoke(team1, team3));
405
		
405

  
406 406
		String street1 = "Strasse1";
407 407
		team1.setContact(Contact.NewInstance(street1, "12345", "Berlin", Country.ARGENTINAARGENTINEREPUBLIC(),"pobox" , "Region", "a@b.de", "f12345", "+49-30-123456", URI.create("www.abc.de"), Point.NewInstance(2.4, 3.2, ReferenceSystem.WGS84(), 3)));
408 408
		team2.setContact(Contact.NewInstance("Street2", null, "London", null, null, null, null, "874599873", null, null, null));
409 409
		Assert.assertTrue("Contacts should be ignoredin default match strategy", matchStrategy.invoke(team1, team2));
410
		
410

  
411 411
		team1.setNomenclaturalTitle("nomTitle1");
412 412
		team2.setNomenclaturalTitle("nomTitle2");
413 413
		Assert.assertFalse("Agents with differing nomenclatural titles should not match", matchStrategy.invoke(team1, team2));
414 414
		//restore
415 415
		team2.setNomenclaturalTitle("nomTitle1");
416 416
		Assert.assertTrue("Agents with equal nomenclatural titles should match", matchStrategy.invoke(team1, team2));
417
		
418
		
417

  
418

  
419 419
		Person person1 = Person.NewTitledInstance("person1");
420 420
		person1.setProtectedTitleCache(true);
421 421
		Person person2 = Person.NewTitledInstance("person2");
......
426 426
		team1.addTeamMember(person1);
427 427
		team2.addTeamMember(person1);
428 428
		Assert.assertTrue("Teams with same team members should match", matchStrategy.invoke(team1, team2));
429
		
429

  
430 430
		team1.addTeamMember(person2);
431 431
		Assert.assertFalse("Teams with differing team members should not match", matchStrategy.invoke(team1, team2));
432 432
		team2.addTeamMember(person2);
......
441 441
		team2.removeTeamMember(person1);
442 442
		team2.addTeamMember(person1);
443 443
		Assert.assertFalse("Teams with matching members in wrong order should not match", matchStrategy.invoke(team1, team2));
444
	
444

  
445 445
	}
446
	
446

  
447 447
	@Test
448 448
	public void testInvokeTeamOrPersonBase(){
449
	
449

  
450 450
	}
451
	
451

  
452 452
}

Also available in: Unified diff