Project

General

Profile

Download (24.9 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
		journal1 = ReferenceFactory.newJournal();
94
		articleTeam1 = Team.NewInstance();
95
		articleTeam2 = Team.NewInstance();
96
		articleTeam1.setTitleCache("Team1", true);
97
		articleTeam1.setNomenclaturalTitle("T.", true);
98
		articleTeam2.setTitleCache("Team2", true);
99
		articleTeam2.setNomenclaturalTitle("TT.", true);
100

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

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

    
117
        //Generic
118
        generic1 = ReferenceFactory.newGeneric();
119
        generic1.setCacheStrategy(defaultStrategy);
120
        genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
121

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

    
128
//**************************** TESTS ***********************************
129

    
130

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

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

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

    
160
		article1.setInJournal(null);
161
		Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
162
	}
163

    
164
	@Test
165
	public void testArticleGetAbbrevTitleCache(){
166

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

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

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

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

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

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

    
241

    
242

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

    
257
	@Test
258
	public void testArticleOldExistingBugs(){
259
		journal1.setTitle("Univ. Calif. Publ. Bot.");
260
		journal1.setAuthorship(null);
261

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

    
271
// ******************* Book ****************************/
272

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

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

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

    
290
    }
291

    
292

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

    
305

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

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

    
329
// ***************************** Book Section ************************/
330

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

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

    
358
    }
359

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

    
378

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

    
382
    }
383

    
384

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

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

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

    
412
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
413
        IBookSection bookSection = ReferenceFactory.newBookSection();
414
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
415
        bookSection.setInBook(book);
416
        bookSection.setAuthorship(sectionTeam);
417
        bookSection.setPages("222-251");
418
        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());
419

    
420
    }
421

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

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

    
435
// *************************** GENERIC *****************************************/
436

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

    
443

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

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

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

    
478

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

    
503

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

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

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

    
517
    }
518

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

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

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

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

    
554
// ********************************** WEB PAGE ********************************************/
555

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

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

    
574

    
575
}
(1-1/2)