Project

General

Profile

Download (24.8 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.parser.TimePeriodParser;
35

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
127
//**************************** TESTS ***********************************
128

    
129

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

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

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

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

    
163
	@Test
164
	public void testArticleGetAbbrevTitleCache(){
165

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

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

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

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

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

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

    
240

    
241

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

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

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

    
270
// ******************* Book ****************************/
271

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

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

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

    
289
    }
290

    
291

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

    
304

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

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

    
328
// ***************************** Book Section ************************/
329

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

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

    
357
    }
358

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

    
377

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

    
381
    }
382

    
383

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

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

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

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

    
419
    }
420

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

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

    
434
// *************************** GENERIC *****************************************/
435

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

    
442

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

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

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

    
477

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

    
502

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

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

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

    
516
    }
517

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

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

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

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

    
553
// ********************************** WEB PAGE ********************************************/
554

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

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

    
573

    
574
}
(1-1/2)