Project

General

Profile

Download (25.1 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 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.strategy.cache.reference;
11

    
12

    
13
import static org.junit.Assert.assertEquals;
14

    
15
import java.net.URI;
16

    
17
import org.apache.log4j.Logger;
18
import org.junit.Assert;
19
import org.junit.Before;
20
import org.junit.BeforeClass;
21
import org.junit.Ignore;
22
import org.junit.Test;
23

    
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.common.TimePeriod;
26
import eu.etaxonomy.cdm.model.reference.IArticle;
27
import eu.etaxonomy.cdm.model.reference.IBook;
28
import eu.etaxonomy.cdm.model.reference.IBookSection;
29
import eu.etaxonomy.cdm.model.reference.IGeneric;
30
import eu.etaxonomy.cdm.model.reference.IJournal;
31
import eu.etaxonomy.cdm.model.reference.IWebPage;
32
import eu.etaxonomy.cdm.model.reference.Reference;
33
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
34
import eu.etaxonomy.cdm.strategy.cache.reference.old.ArticleDefaultCacheStrategyTest;
35
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
36

    
37
/**
38
 * Copy of {@link ArticleDefaultCacheStrategyTest} to test the {@link NewDefaultReferenceCacheStrategy}.
39
 *
40
 * @author a.mueller
41
 * @date 25.05.2016
42
 *
43
 */
44
public class NewDefaultReferenceCacheStrategyTest {
45
	@SuppressWarnings("unused")
46
	private static final Logger logger = Logger.getLogger(NewDefaultReferenceCacheStrategyTest.class);
47

    
48
	//article
49
	private static IArticle article1;
50
	private static IJournal journal1;
51
	private static Team articleTeam1;
52
	private static Team articleTeam2;
53

    
54
	//book // book section
55
	private static IBook book1;
56
    private static Team bookTeam1;
57

    
58
    //book section
59
    private static IBookSection bookSection1;
60
    private static Team sectionTeam1;
61

    
62
    //CdDvd
63
    private static Reference cdDvd;
64
    private static String cdDvdTitle;
65

    
66
    //Generic
67
    private static IGeneric generic1;
68
    private static Team genericTeam1;
69

    
70
    //WebPage
71
    private static IWebPage webPage1;
72
    private static Team webPageTeam1;
73

    
74
	//common
75
	private static NewDefaultReferenceCacheStrategy defaultStrategy;
76
	private static final String detail1 = "55";
77

    
78
	/**
79
	 * @throws java.lang.Exception
80
	 */
81
	@BeforeClass
82
	public static void setUpBeforeClass() throws Exception {
83
		defaultStrategy = NewDefaultReferenceCacheStrategy.NewInstance();
84
	}
85

    
86
	/**
87
	 * @throws java.lang.Exception
88
	 */
89
	@Before
90
	public void setUp() throws Exception {
91
	    //article
92
		article1 = ReferenceFactory.newArticle();
93
		article1.setCacheStrategy(defaultStrategy);
94
		journal1 = ReferenceFactory.newJournal();
95
		journal1.setCacheStrategy(defaultStrategy);
96
		articleTeam1 = Team.NewInstance();
97
		articleTeam2 = Team.NewInstance();
98
		articleTeam1.setTitleCache("Team1", true);
99
		articleTeam1.setNomenclaturalTitle("T.", true);
100
		articleTeam2.setTitleCache("Team2", true);
101
		articleTeam2.setNomenclaturalTitle("TT.", true);
102

    
103
		//book / section
104
		book1 = ReferenceFactory.newBook();
105
		book1.setCacheStrategy(defaultStrategy);
106
        bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
107
        bookSection1 = ReferenceFactory.newBookSection();
108
        bookSection1.setCacheStrategy(defaultStrategy);
109
        sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
110

    
111
        //CdDvd
112
        cdDvd = ReferenceFactory.newCdDvd();
113
        cdDvdTitle = "A nice CD title";
114
        cdDvd.setTitle(cdDvdTitle);
115
        String publisher = "An ugly publisher";  //not yet implemented
116
        String place = "A beutiful place";  //not yet implemented
117
        TimePeriod publicationDate = TimePeriod.NewInstance(1999, 2001);
118
        cdDvd.setDatePublished(publicationDate);
119

    
120
        //Generic
121
        generic1 = ReferenceFactory.newGeneric();
122
        generic1.setCacheStrategy(defaultStrategy);
123
        genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
124

    
125
        //WebPage
126
        webPage1 = ReferenceFactory.newWebPage();
127
        webPage1.setCacheStrategy(defaultStrategy);
128
        webPageTeam1 = Team.NewTitledInstance("Authorteam, D.", "AT.");
129
	}
130

    
131
//**************************** TESTS ***********************************
132

    
133

    
134
	@Test
135
	public void testArticleGetTitleCache(){
136
		journal1.setTitle("My journal");
137
		journal1.setAuthorship(articleTeam2);
138
		article1.setTitle("My article");
139
		article1.setInJournal(journal1);
140
		article1.setAuthorship(articleTeam1);
141
		article1.setDatePublished(TimePeriod.NewInstance(1975));
142
		Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
143

    
144
		article1.setInJournal(null);
145
		//TODO should not be needed here
146
		article1.setTitleCache(null, false);
147
		Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
148
	}
149

    
150
	@Ignore
151
	@Test
152
	//This test is just to show that there is still the title cache bug which is not
153
	//set to null by setInJournal(null)
154
	public void testArticleGetTitleCache2(){
155
		journal1.setTitle("My journal");
156
		journal1.setAuthorship(articleTeam2);
157
		article1.setTitle("My article");
158
		article1.setInJournal(journal1);
159
		article1.setAuthorship(articleTeam1);
160
		article1.setDatePublished(TimePeriod.NewInstance(1975));
161
		Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
162

    
163
		article1.setInJournal(null);
164
		Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
165
	}
166

    
167
	@Test
168
	public void testArticleGetAbbrevTitleCache(){
169

    
170
		journal1.setTitle("My journal");
171
		journal1.setTitle("M. Journ.");
172
		journal1.setAuthorship(articleTeam2);
173
		article1.setTitle("My article");
174
		article1.setInJournal(journal1);
175
		article1.setAuthorship(articleTeam1);
176
		article1.setDatePublished(TimePeriod.NewInstance(1975));
177
		article1.setAbbrevTitle("M. Art.");
178
		Assert.assertEquals("T., M. Art. in M. Journ. 1975", article1.getAbbrevTitleCache());  //double dot may be removed in future #3645
179

    
180
		article1.setInJournal(null);
181
		//TODO should not be needed here
182
		article1.setTitleCache(null, false);
183
		Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
184
	}
185

    
186
	@Test
187
	public void testArticleGetNomenclaturalCitation(){
188
		journal1.setTitle("My journal");
189
		journal1.setTitle("M. J.");
190
		journal1.setAuthorship(articleTeam2);
191
		article1.setTitle("My article");
192
		article1.setInJournal(journal1);
193
		article1.setAuthorship(articleTeam1);
194
		article1.setDatePublished(TimePeriod.NewInstance(1975));
195
		Assert.assertEquals("in M. J.: 55. 1975", article1.getNomenclaturalCitation(detail1));
196

    
197
		article1.setVolume("22");
198
		Assert.assertEquals("in M. J. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
199
		article1.setSeriesPart("ser. 11");
200
		Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
201
	}
202

    
203
	/**
204
	 * After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
205
	 */
206
	@Test
207
	public void testArticleGetNomenclaturalCitationSerSectAbt(){
208
		article1.setInJournal(journal1);
209
		article1.setVolume("22");
210
		journal1.setAbbrevTitle("J. Pl. Eur.");
211
		journal1.setAuthorship(articleTeam2);
212
		article1.setDatePublished(TimePeriod.NewInstance(1975));
213
		//no ser, sect, abt
214
		Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
215
		//ser
216
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
217
		Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
218
		journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
219
		Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
220
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
221
		Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
222
		//sect
223
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
224
		Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
225
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
226
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
227
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
228
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
229
		//abt
230
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
231
		Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
232
		journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
233
		Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
234
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
235
		Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
236

    
237
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
238
		article1.setSeriesPart("1");
239
		Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
240
		article1.setSeriesPart("Series 2");
241
		Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
242
	}
243

    
244

    
245

    
246
	@Test
247
	public void testArticleGetTitleWithoutYearAndAuthor(){
248
		journal1.setTitle("My journal");
249
		journal1.setAuthorship(articleTeam2);
250
		article1.setTitle("My article");
251
		article1.setInJournal(journal1);
252
		article1.setAuthorship(articleTeam1);
253
		article1.setVolume("34");
254
		article1.setSeriesPart("ser. 2");
255
		article1.setDatePublished(TimePeriod.NewInstance(1975));
256
		//FIXME removed for new formatter
257
//		Assert.assertEquals("in My journal, ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference)article1, false));
258
	}
259

    
260
	@Test
261
	public void testArticleOldExistingBugs(){
262
		journal1.setTitle("Univ. Calif. Publ. Bot.");
263
		journal1.setAuthorship(null);
264

    
265
		Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
266
		article1.setTitle("");
267
		article1.setInJournal(journal1);
268
		article1.setAuthorship(articleAuthor);
269
		article1.setVolume("18");
270
		article1.setDatePublished(TimePeriod.NewInstance(1943));
271
		Assert.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy.getTitleCache((Reference)article1));
272
	}
273

    
274
// ******************* Book ****************************/
275

    
276
   @Test
277
    public void testBookGetTitleCache0(){
278
        book1.setTitle("My book");
279
        book1.setAuthorship(bookTeam1);
280
        book1.setDatePublished(TimePeriod.NewInstance(1975));
281
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
282

    
283
        book1.setTitleCache(null, false);
284
        book1.setEdition("ed. 3");
285
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3. 1975", book1.getTitleCache());
286

    
287
        TimePeriod newDatePublished = TimePeriodParser.parseString("1975 (after Aug.)");
288
        book1.setDatePublished(newDatePublished);
289
        book1.setTitleCache(null, false);
290
        //TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
291
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3", book1.getTitleCache());
292

    
293
    }
294

    
295

    
296
    @Test
297
    public void testBookGetTitleCache1(){
298
        //series
299
        IBook book1 = ReferenceFactory.newBook();
300
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
301
        book1.setSeriesPart("1");
302
        book1.setVolume("Fasc. 11");
303
        book1.setDatePublished(TimePeriodParser.parseString("1955"));
304
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
305
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
306
    }
307

    
308

    
309
    @Test
310
    public void testBookGetTitleCache2(){
311
        //series
312
        IBook book1 = ReferenceFactory.newBook();
313
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
314
        book1.setVolume("Fasc. 11");
315
        book1.setDatePublished(TimePeriodParser.parseString("1955"));
316
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
317
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
318
        book1.setSeriesPart("1");
319
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
320
    }
321

    
322
    @Test
323
    public void testBookGetNomenclaturalCitation(){
324
        book1.setTitle("My book");
325
        book1.setAuthorship(bookTeam1);
326
        book1.setDatePublished(TimePeriod.NewInstance(1975));
327
        Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
328
        book1.setAbbrevTitle("Analect. Bot.");
329
        Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
330
    }
331

    
332
// ***************************** Book Section ************************/
333

    
334
    @Test
335
    public void testBookSectionGetTitleCache(){
336
        book1.setTitle("My book");
337
        book1.setAuthorship(bookTeam1);
338
        bookSection1.setTitle("My chapter");
339
        bookSection1.setInBook(book1);
340
        bookSection1.setAuthorship(sectionTeam1);
341
        book1.setDatePublished(TimePeriod.NewInstance(1975));
342
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
343
        book1.setDatePublished(null);
344
        bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
345
        bookSection1.setTitleCache(null, false);
346
        book1.setTitleCache(null, false);
347
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
348
        book1.setDatePublished(TimePeriod.NewInstance(1977));
349
        bookSection1.setTitleCache(null, false);
350
        book1.setTitleCache(null, false);
351
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
352
        bookSection1.setTitleCache(null, false);
353
        book1.setTitleCache(null, false);
354
        book1.setSeriesPart("2");
355
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
356

    
357
        bookSection1.setInBook(null);
358
        bookSection1.setTitleCache(null, false);
359
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
360

    
361
    }
362

    
363
    @Ignore
364
    @Test
365
    //This test is just to show that there is still the title cache bug which is not
366
    //set to null by setInBook(null) and others
367
    public void testBookSectionGetTitleCache2(){
368
        book1.setTitle("My book");
369
        book1.setAuthorship(bookTeam1);
370
        bookSection1.setTitle("My chapter");
371
        bookSection1.setInBook(book1);
372
        bookSection1.setAuthorship(sectionTeam1);
373
        book1.setDatePublished(TimePeriod.NewInstance(1975));
374
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
375
        book1.setDatePublished(null);
376
        bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
377
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
378
        book1.setDatePublished(TimePeriod.NewInstance(1977));
379
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
380

    
381

    
382
        bookSection1.setInBook(null);
383
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
384

    
385
    }
386

    
387

    
388
    @Test
389
    public void testBookSectionGetNomenclaturalCitation(){
390
        book1.setTitle("My book");
391
        book1.setAuthorship(bookTeam1);
392
        bookSection1.setTitle("My chapter");
393
        bookSection1.setInBook(book1);
394
        bookSection1.setAuthorship(sectionTeam1);
395
        book1.setDatePublished(TimePeriod.NewInstance(1975));
396
        //TODO still unclear which is correct
397
//      Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
398
        Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
399

    
400
        book1.setSeriesPart("2");
401
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
402
    }
403

    
404
    @Test
405
    public void testBookSectionRealExample(){
406
        Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
407
        IBook book = ReferenceFactory.newBook();
408
        book.setTitle("Flora of the Kingdom of Saudi Arabia");
409
        book.setAuthorship(bookTeam);
410
        book.setVolume("2(3)");
411
        book.setPlacePublished("Riyadh");
412
        book.setPublisher("National Herbarium");
413
        book.setDatePublished(TimePeriod.NewInstance(2000));
414

    
415
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
416
        IBookSection bookSection = ReferenceFactory.newBookSection();
417
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
418
        bookSection.setInBook(book);
419
        bookSection.setAuthorship(sectionTeam);
420
        bookSection.setPages("222-251");
421
        Assert.assertEquals("Chaudhary S. A. - 73. Hedypnois - 87. Crepis in Chaudhary S. A.(ed.), Flora of the Kingdom of Saudi Arabia 2(3). 2000", bookSection.getTitleCache());
422

    
423
    }
424

    
425
    @Test
426
    public void testCdDvdGetTitleWithoutYearAndAuthor() {
427
        String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false);
428
        assertEquals(cdDvdTitle, result);
429
    }
430

    
431
    //TODO missing publicationPlace and publisher has to be discussed
432
    @Test
433
    public void testCdDvdGetTitleCache() {
434
        String result = defaultStrategy.getTitleCache(cdDvd);
435
        assertEquals(cdDvdTitle + ". 1999-2001", result);
436
    }
437

    
438
// *************************** GENERIC *****************************************/
439

    
440
    @Test
441
    public void testGenericGetTitleCache(){
442
        generic1.setTitle("auct.");
443
        Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
444
    }
445

    
446

    
447
    @Test
448
    public void testGenericGetInRef(){
449
        generic1.setTitle("auct.");
450
        IBook book1 = ReferenceFactory.newBook();
451
        book1.setTitle("My book title");
452
        book1.setAuthorship(genericTeam1);
453
        Reference inRef = (Reference)book1;
454
        generic1.setInReference(inRef);
455
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
456
        //TODO author still unclear
457
//      Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
458
        Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
459
    }
460

    
461
    @Test
462
    public void testGenericGetInRefWithoutInRef(){
463
        generic1.setTitle("My generic title");
464
        generic1.setAuthorship(genericTeam1);
465
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
466
        Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
467
    }
468

    
469
    @Test
470
    public void testGenericGetTitleCache2(){
471
        generic1.setTitle("Part Title");
472
        IBook book1 = ReferenceFactory.newBook();
473
        book1.setTitle("My book title");
474
        book1.setAuthorship(genericTeam1);
475
        Reference inRef = (Reference)book1;
476
        generic1.setInReference(inRef);
477
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
478
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
479
    }
480

    
481

    
482
    @Test
483
    public void testGenericGetAbbrevTitleCache(){
484
        generic1.setTitle("Part Title");
485
        generic1.setAbbrevTitle("Pt. Tit.");
486
        generic1.setDatePublished(TimePeriodParser.parseString("1987"));
487
        IBook book1 = ReferenceFactory.newBook();
488
        book1.setTitle("My book title");
489
        book1.setAbbrevTitle("My bk. tit.");
490
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
491
        Reference inRef = (Reference)book1;
492
        generic1.setInReference(inRef);
493
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
494
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
495
        Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
496
        Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
497
        //TODO author still unclear
498
//      Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
499
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
500
        generic1.setVolume("23");
501
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
502
        generic1.setSeriesPart("ser. 11");
503
        //TODO
504
//      Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
505

    
506

    
507
        //protected
508
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
509
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
510
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
511

    
512
        generic1.setDatePublished(null);
513
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
514
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
515
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
516

    
517
        generic1.setDatePublished(TimePeriodParser.parseString("1893"));
518
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
519

    
520
    }
521

    
522
    @Test
523
    public void testGenericGetTitleCacheWithoutInRef(){
524
        generic1.setTitle("My generic title");
525
        generic1.setAuthorship(genericTeam1);
526
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
527
        Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
528
    }
529

    
530
    @Test
531
    public void testGenericAuthorOnly(){
532
        generic1.setAuthorship(genericTeam1);
533
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
534
        Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
535
        Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
536
    }
537

    
538
    @Test
539
    public void testGenericYearAndAuthorOnly(){
540
        generic1.setAuthorship(genericTeam1);
541
        generic1.setDatePublished(TimePeriodParser.parseString("1792"));
542
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
543
        Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
544
        Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
545
    }
546

    
547
    @Test
548
    public void testGenericDoubleDotBeforeYear(){
549
        generic1.setAuthorship(genericTeam1);
550
        String detail = "sine no.";
551
        generic1.setAbbrevTitle("My title");
552
        generic1.setDatePublished(TimePeriodParser.parseString("1883-1884"));
553
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
554
        Assert.assertEquals("My title: sine no. 1883-1884", generic1.getNomenclaturalCitation(detail));
555
    }
556

    
557
// ********************************** WEB PAGE ********************************************/
558

    
559
    @Test
560
//    @Ignore //under development
561
    public void testWebPageGetTitleCache(){
562
        webPage1.setTitle("Flora of Israel Online");
563
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
564
        webPage1.setAuthorship(webPageTeam1);
565
        webPage1.setDatePublished(TimePeriodParser.parseString("[accessed in 2011]"));
566
        //taken from Berlin Model, may be modified in future
567
        Assert.assertEquals("Unexpected title cache.", "Authorteam, D. - Flora of Israel Online - http://flora.huji.ac.il [accessed in 2011]", webPage1.getTitleCache());
568
    }
569

    
570
//  @Test
571
//  //WebPages should usually not be used as nomencl.reference, therefore this is less important
572
//  public void testWebPageGetAbbrevTitleCache(){
573
//      webPage1.setTitle("auct.");
574
//      Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
575
//  }
576

    
577

    
578
}
(1-1/2)