Project

General

Profile

Download (35.4 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.strategy.cache.reference;
10

    
11

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

    
14
import java.net.URI;
15

    
16
import org.apache.log4j.Logger;
17
import org.joda.time.DateTime;
18
import org.junit.Assert;
19
import org.junit.Before;
20
import org.junit.BeforeClass;
21
import org.junit.Test;
22

    
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.common.TimePeriod;
26
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
27
import eu.etaxonomy.cdm.model.reference.IArticle;
28
import eu.etaxonomy.cdm.model.reference.IBook;
29
import eu.etaxonomy.cdm.model.reference.IBookSection;
30
import eu.etaxonomy.cdm.model.reference.ICdDvd;
31
import eu.etaxonomy.cdm.model.reference.IDatabase;
32
import eu.etaxonomy.cdm.model.reference.IGeneric;
33
import eu.etaxonomy.cdm.model.reference.IJournal;
34
import eu.etaxonomy.cdm.model.reference.IWebPage;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
37
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
38
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
39

    
40
/**
41
 * Copy of {@link ArticleDefaultCacheStrategyTest} to test the {@link DefaultReferenceCacheStrategy}.
42
 *
43
 * @author a.mueller
44
 * @since 25.05.2016
45
 *
46
 */
47
public class DefaultReferenceCacheStrategyTest {
48
	@SuppressWarnings("unused")
49
	private static final Logger logger = Logger.getLogger(DefaultReferenceCacheStrategyTest.class);
50

    
51
	private static final String SEP = TimePeriod.SEP;
52

    
53
	//article
54
	private static IArticle article1;
55
	private static IJournal journal1;
56
	private static Team articleTeam1;
57
	private static Team articleTeam2;
58

    
59
	//book // book section
60
	private static IBook book1;
61
    private static Team bookTeam1;
62

    
63
    //book section
64
    private static IBookSection bookSection1;
65
    private static Team sectionTeam1;
66

    
67
    //CdDvd
68
    private static Reference cdDvd;
69
    private static String cdDvdTitle;
70

    
71
    //Generic
72
    private static IGeneric generic1;
73
    private static Team genericTeam1;
74

    
75
    //WebPage
76
    private static IWebPage webPage1;
77
    private static Team webPageTeam1;
78

    
79
	//common
80
	private static DefaultReferenceCacheStrategy defaultStrategy;
81
	private static final String detail1 = "55";
82

    
83
	/**
84
	 * @throws java.lang.Exception
85
	 */
86
	@BeforeClass
87
	public static void setUpBeforeClass() throws Exception {
88
		defaultStrategy = DefaultReferenceCacheStrategy.NewInstance();
89
	}
90

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

    
108
		//book / section
109
		book1 = ReferenceFactory.newBook();
110
		book1.setCacheStrategy(defaultStrategy);
111
        bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
112
        bookSection1 = ReferenceFactory.newBookSection();
113
        sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
114

    
115
        //CdDvd
116
        cdDvd = ReferenceFactory.newCdDvd();
117
        cdDvd.setCacheStrategy(defaultStrategy);
118
        cdDvdTitle = "A nice CD title";
119
        cdDvd.setTitle(cdDvdTitle);
120
        String publisher = "An ugly publisher";  //not yet implemented
121
        String place = "A beutiful place";  //not yet implemented
122
        VerbatimTimePeriod publicationDate = VerbatimTimePeriod.NewVerbatimInstance(1999, 2001);
123
        cdDvd.setDatePublished(publicationDate);
124

    
125
        //Generic
126
        generic1 = ReferenceFactory.newGeneric();
127
        generic1.setCacheStrategy(defaultStrategy);
128
        genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
129

    
130
        //WebPage
131
        webPage1 = ReferenceFactory.newWebPage();
132
        webPage1.setCacheStrategy(defaultStrategy);
133
        webPageTeam1 = Team.NewTitledInstance("Authorteam, D.", "AT.");
134
	}
135

    
136
//**************************** TESTS ***********************************
137

    
138

    
139
	@Test
140
	public void testArticleGetTitleCache(){
141
		journal1.setTitle("My journal");
142
		((Reference)journal1).setAuthorship(articleTeam2);  //incorrect use anyway
143
		article1.setTitle("My article");
144
		article1.setInJournal(journal1);
145
		article1.setAuthorship(articleTeam1);
146
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
147
		Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
148

    
149
		article1.setInJournal(null);
150
		//TODO should not be needed here
151
		article1.setTitleCache(null, false);
152
		Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
153
	}
154

    
155
	@Test
156
	//This test is just to show that setInJournal(null) now resets caches  #1815
157
	public void testArticleGetTitleCache2(){
158
		journal1.setTitle("My journal");
159
		((Reference)journal1).setAuthorship(articleTeam2);
160
		article1.setTitle("My article");
161
		article1.setInJournal(journal1);
162
		article1.setAuthorship(articleTeam1);
163
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
164
		Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
165

    
166
		article1.setInJournal(null);
167
		Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
168
	}
169

    
170
	//#6496
171
    @Test
172
    public void testArticleGetTitleCacheWithPages(){
173
        journal1.setTitle("My journal");
174
        ((Reference)journal1).setAuthorship(articleTeam2);
175
        article1.setTitle("My article");
176
        article1.setInJournal(journal1);
177
        article1.setAuthorship(articleTeam1);
178
        article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
179
        Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
180
        article1.setPages("12-22");
181
        Assert.assertEquals("Team1, My article in My journal: 12-22. 1975", article1.getTitleCache());
182

    
183
        article1.setVolume("7");
184
        Assert.assertEquals("Team1, My article in My journal 7: 12-22. 1975", article1.getTitleCache());
185

    
186
        article1.setSeriesPart("II");
187
        //TODO unclear if punctuation is correct
188
        Assert.assertEquals("Team1, My article in My journal, II, 7: 12-22. 1975", article1.getTitleCache());
189
   }
190

    
191
	@Test
192
	public void testArticleGetAbbrevTitleCache(){
193

    
194
		journal1.setTitle("My journal");
195
		journal1.setTitle("M. Journ.");
196
		((Reference)journal1).setAuthorship(articleTeam2);
197
		article1.setTitle("My article");
198
		article1.setInJournal(journal1);
199
		article1.setAuthorship(articleTeam1);
200
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
201
		article1.setAbbrevTitle("M. Art.");
202
		Assert.assertEquals("T., M. Art. in M. Journ. 1975", article1.getAbbrevTitleCache());  //double dot may be removed in future #3645
203

    
204
		article1.setInJournal(null);
205
		//TODO should not be needed here
206
		article1.setTitleCache(null, false);
207
		Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
208
	}
209

    
210
	@Test
211
	public void testArticleGetNomenclaturalCitation(){
212
		journal1.setTitle("My journal");
213
		journal1.setTitle("M. J.");
214
		((Reference)journal1).setAuthorship(articleTeam2);
215
		article1.setTitle("My article");
216
		article1.setInJournal(journal1);
217
		article1.setAuthorship(articleTeam1);
218
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
219
		Assert.assertEquals("in M. J.: 55. 1975", article1.getNomenclaturalCitation(detail1));
220

    
221
		article1.setVolume("22");
222
		Assert.assertEquals("in M. J. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
223
		article1.setSeriesPart("ser. 11");
224
		Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
225

    
226
		article1.setPages("33"); //#6496 don't show pages in nomencl. citation
227
        Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
228
	}
229

    
230
	/**
231
	 * After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
232
	 */
233
	@Test
234
	public void testArticleGetNomenclaturalCitationSerSectAbt(){
235
		article1.setInJournal(journal1);
236
		article1.setVolume("22");
237
		journal1.setAbbrevTitle("J. Pl. Eur.");
238
		((Reference)journal1).setAuthorship(articleTeam2);
239
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
240
		//no ser, sect, abt
241
		Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
242
		//ser
243
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
244
		Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
245
		journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
246
		Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
247
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
248
		Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
249
		//sect
250
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
251
		Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
252
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
253
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
254
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
255
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
256
		//abt
257
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
258
		Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
259
		journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
260
		Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
261
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
262
		Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
263

    
264
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
265
		article1.setSeriesPart("1");
266
		Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
267
		article1.setSeriesPart("Series 2");
268
		Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
269
	}
270

    
271

    
272

    
273
	@Test
274
	public void testArticleGetTitleWithoutYearAndAuthor(){
275
		journal1.setTitle("My journal");
276
		((Reference)journal1).setAuthorship(articleTeam2);
277
		article1.setTitle("My article");
278
		article1.setInJournal(journal1);
279
		article1.setAuthorship(articleTeam1);
280
		article1.setVolume("34");
281
		article1.setSeriesPart("ser. 2");
282
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
283
		//FIXME removed for new formatter
284
//		Assert.assertEquals("in My journal, ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference)article1, false));
285
	}
286

    
287
	@Test
288
	public void testArticleOldExistingBugs(){
289
		journal1.setTitle("Univ. Calif. Publ. Bot.");
290
		((Reference)journal1).setAuthorship(null);
291

    
292
		Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
293
		article1.setTitle("");
294
		article1.setInJournal(journal1);
295
		article1.setAuthorship(articleAuthor);
296
		article1.setVolume("18");
297
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1943));
298
		Assert.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy.getTitleCache((Reference)article1));
299
	}
300

    
301
// ******************* Book ****************************/
302

    
303
   @Test
304
    public void testBookGetTitleCache0(){
305
        book1.setTitle("My book");
306
        book1.setAuthorship(bookTeam1);
307
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
308
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
309

    
310
        book1.setTitleCache(null, false);
311
        book1.setEdition("ed. 3");
312
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3. 1975", book1.getTitleCache());
313

    
314
        VerbatimTimePeriod newDatePublished = TimePeriodParser.parseStringVerbatim("1975 (after Aug.)");
315
        book1.setDatePublished(newDatePublished);
316
        book1.setTitleCache(null, false);
317
        //TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
318
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3", book1.getTitleCache());
319

    
320
        book1.setPages("1-405");
321
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3: 1-405", book1.getTitleCache());
322

    
323
    }
324

    
325
    //https://dev.e-taxonomy.eu/redmine/issues/8881
326
    @Test
327
    public void testInRefAuthor(){
328
        Person person1 = Person.NewInstance("Inauth.", "Inauthor", "A.B.", "Ala Bala");
329
        Person person2 = Person.NewInstance("Twoauth.", "Twoauthor", "C.", "Cla");
330
        Person person3 = Person.NewTitledInstance("Threeauth.");
331
        Team team = Team.NewInstance(person1, person2, person3);
332
        IBook book1 = ReferenceFactory.newBook();
333
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
334
        book1.setVolume("Fasc. 11");
335
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
336
        bookSection1.setTitle("My chapter");
337
        bookSection1.setInBook(book1);
338
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1956));
339

    
340
        book1.setAuthorship(person1);
341
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
342
        book1.setAuthorship(team);
343
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor & Threeauth., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
344
        team.setHasMoreMembers(true);
345
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor, Threeauth. & al., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
346
        book1.setAuthorship(Team.NewInstance(person1));
347
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
348

    
349
        //for the following the behavior is not yet finally discussed, may change in future
350
        book1.setAuthorship(team);
351
        team.setTitleCache("Teamcache", true);
352
        Assert.assertEquals("Unexpected nomencl. reference", "in Teamcache, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
353
        team.setTitleCache("Teamc.", true);
354
        Assert.assertEquals("Unexpected nomencl. reference", "in Teamc., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
355
        book1.setAuthorship(Team.NewInstance());
356
        Assert.assertEquals("Unexpected nomencl. reference", "in "+TeamDefaultCacheStrategy.EMPTY_TEAM+", Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
357
    }
358

    
359
    @Test
360
    public void testBookGetTitleCache1(){
361
        //series
362
        IBook book1 = ReferenceFactory.newBook();
363
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
364
        book1.setSeriesPart("1");
365
        book1.setVolume("Fasc. 11");
366
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
367
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
368
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
369
    }
370

    
371
    @Test
372
    public void testBookGetTitleCache2(){
373
        //series
374
        IBook book1 = ReferenceFactory.newBook();
375
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
376
        book1.setVolume("Fasc. 11");
377
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
378
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
379
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
380
        book1.setSeriesPart("1");
381
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
382
    }
383

    
384
    @Test
385
    public void testBookGetNomenclaturalCitation(){
386
        book1.setTitle("My book");
387
        book1.setAuthorship(bookTeam1);
388
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
389
        Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
390
        book1.setAbbrevTitle("Analect. Bot.");
391
        Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
392
    }
393

    
394
// ***************************** Book Section ************************/
395

    
396
    @Test
397
    public void testBookSectionGetTitleCache(){
398
        book1.setTitle("My book");
399
        book1.setAuthorship(bookTeam1);
400
        bookSection1.setTitle("My chapter");
401
        bookSection1.setInBook(book1);
402
        bookSection1.setAuthorship(sectionTeam1);
403
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
404
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
405
        book1.setDatePublished((VerbatimTimePeriod)null);
406
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
407
        bookSection1.setTitleCache(null, false);
408
        book1.setTitleCache(null, false);
409
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
410
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
411
        bookSection1.setTitleCache(null, false);
412
        book1.setTitleCache(null, false);
413
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
414
        bookSection1.setTitleCache(null, false);
415
        book1.setTitleCache(null, false);
416
        book1.setSeriesPart("2");
417
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
418

    
419
        //FIXME #6496
420
//        bookSection1.setPages("33-38");
421
//        bookSection1.setTitleCache(null);
422
//        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2: 33-38. 1976", bookSection1.getTitleCache());
423

    
424
        bookSection1.setInBook(null);
425
        bookSection1.setTitleCache(null, false);
426
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
427

    
428
    }
429

    
430
    @Test
431
    //This test is just to show that setInBook(null) now resets caches  #1815
432
    public void testBookSectionGetTitleCache2(){
433
        book1.setTitle("My book");
434
        book1.setAuthorship(bookTeam1);
435
        bookSection1.setTitle("My chapter");
436
        bookSection1.setInBook(book1);
437
        bookSection1.setAuthorship(sectionTeam1);
438
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
439
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
440
        book1.setDatePublished((VerbatimTimePeriod)null);
441
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
442
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
443
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
444
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
445

    
446

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

    
450
    }
451

    
452

    
453
    @Test
454
    public void testBookSectionGetNomenclaturalCitation(){
455
        book1.setTitle("My book");
456
        book1.setAuthorship(bookTeam1);
457
        bookSection1.setTitle("My chapter");
458
        bookSection1.setInBook(book1);
459
        bookSection1.setAuthorship(sectionTeam1);
460
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
461
        //TODO still unclear which is correct
462
//      Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
463
        Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
464

    
465
        book1.setSeriesPart("2");
466
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
467
        //#6496 don't show pages in nom.ref. citations
468
        bookSection1.setPages("35-39");
469
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
470

    
471
    }
472

    
473
    @Test
474
    public void testBookSectionRealExample(){
475
        Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
476
        IBook book = ReferenceFactory.newBook();
477
        book.setTitle("Flora of the Kingdom of Saudi Arabia");
478
        book.setAuthorship(bookTeam);
479
        book.setVolume("2(3)");
480
        book.setPlacePublished("Riyadh");
481
        book.setPublisher("National Herbarium");
482
        book.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2000));
483

    
484
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
485
        IBookSection bookSection = ReferenceFactory.newBookSection();
486
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
487
        bookSection.setInBook(book);
488
        bookSection.setAuthorship(sectionTeam);
489
        bookSection.setPages("222-251");
490
        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());
491

    
492
    }
493

    
494
    @Test
495
    public void testCdDvdGetTitleWithoutYearAndAuthor() {
496
        String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false);
497
        assertEquals(cdDvdTitle, result);
498
    }
499

    
500
    //TODO missing publicationPlace and publisher has to be discussed
501
    @Test
502
    public void testCdDvdGetTitleCache() {
503
        String result = defaultStrategy.getTitleCache(cdDvd);
504
        assertEquals(cdDvdTitle + ". 1999"+SEP+"2001", result);
505
    }
506

    
507
// *************************** GENERIC *****************************************/
508

    
509
    @Test
510
    public void testGenericGetTitleCache(){
511
        generic1.setTitle("auct.");
512
        Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
513
    }
514

    
515
    @Test
516
    public void testGenericGetInRef(){
517
        generic1.setTitle("auct.");
518
        IBook book1 = ReferenceFactory.newBook();
519
        book1.setTitle("My book title");
520
        book1.setAuthorship(genericTeam1);
521
        Reference inRef = (Reference)book1;
522
        generic1.setInReference(inRef);
523
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
524
        //TODO author still unclear
525
//      Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
526
        Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
527
    }
528

    
529
    @Test
530
    public void testGenericGetInRefWithoutInRef(){
531
        generic1.setTitle("My generic title");
532
        generic1.setAuthorship(genericTeam1);
533
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
534
        Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
535
    }
536

    
537
    @Test
538
    public void testGenericGetTitleCache2(){
539
        generic1.setTitle("Part Title");
540
        IBook book1 = ReferenceFactory.newBook();
541
        book1.setTitle("My book title");
542
        book1.setAuthorship(genericTeam1);
543
        Reference inRef = (Reference)book1;
544
        generic1.setInReference(inRef);
545
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
546
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
547
    }
548

    
549

    
550
    @Test
551
    public void testGenericGetAbbrevTitleCache(){
552
        generic1.setTitle("Part Title");
553
        generic1.setAbbrevTitle("Pt. Tit.");
554
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
555
        IBook book1 = ReferenceFactory.newBook();
556
        book1.setTitle("My book title");
557
        book1.setAbbrevTitle("My bk. tit.");
558
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
559
        Reference inRef = (Reference)book1;
560
        generic1.setInReference(inRef);
561
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
562
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
563
        Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
564
        Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
565
        //TODO author still unclear
566
//      Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
567
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
568
        generic1.setVolume("23");
569
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
570
        generic1.setSeriesPart("ser. 11");
571
        //TODO
572
//      Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
573

    
574

    
575
        //protected
576
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
577
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
578
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
579

    
580
        generic1.setDatePublished((VerbatimTimePeriod)null);
581
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
582
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
583
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
584

    
585
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1893"));
586
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
587

    
588
    }
589

    
590
    @Test
591
    public void testGenericGetTitleCacheWithoutInRef(){
592
        generic1.setTitle("My generic title");
593
        generic1.setAuthorship(genericTeam1);
594
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
595
        Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
596
    }
597

    
598
    @Test
599
    public void testGenericAuthorOnly(){
600
        generic1.setAuthorship(genericTeam1);
601
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
602
        Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
603
        Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
604
    }
605

    
606
    @Test
607
    public void testGenericYearAndAuthorOnly(){
608
        generic1.setAuthorship(genericTeam1);
609
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1792"));
610
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
611
        Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
612
        Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
613
    }
614

    
615
    @Test
616
    public void testGenericDoubleDotBeforeYear(){
617
        generic1.setAuthorship(genericTeam1);
618
        String detail = "sine no.";
619
        generic1.setAbbrevTitle("My title");
620
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
621
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
622
        Assert.assertEquals("My title: sine no. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail));
623
    }
624

    
625
    //#4338
626
    @Test
627
    public void testGenericMissingVolume(){
628
        generic1.setTitle("My generic");
629
        generic1.setAuthorship(genericTeam1);
630
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
631
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
632
        Assert.assertEquals("My generic: 55. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail1));
633
        generic1.setVolume("7");
634
        Assert.assertEquals("My generic 7: 55. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail1));
635
        Assert.assertEquals("Authorteam, My generic 7. 1883"+SEP+"1884", generic1.getTitleCache());
636
        Assert.assertEquals("AT., My generic 7. 1883"+SEP+"1884", generic1.getAbbrevTitleCache());
637

    
638
        //inRef
639
        Reference generic2 = ReferenceFactory.newGeneric();
640
        generic2.setTitle("My InRef");
641
        Person person2 = Person.NewTitledInstance("InRefAuthor");
642
        generic2.setAuthorship(person2);
643
        generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
644
        generic1.setInReference(generic2);
645

    
646
        //only reference has a volume
647
        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail1));
648
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
649
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
650

    
651
        //both have a volume
652
        generic2.setVolume("9");  //still unclear what should happen if you have such dirty data
653
//        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
654
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
655
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
656

    
657
        //only inref has volume
658
        generic1.setVolume(null);
659
        Assert.assertEquals("in InRefAuthor, My InRef 9: 55. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail1));
660
        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 9. 1883"+SEP+"1884", generic1.getTitleCache());
661
        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 9. 1883"+SEP+"1884", generic1.getAbbrevTitleCache());
662
   }
663

    
664
    //#3532
665
    @Test
666
    public void testUnexpectedNomenclaturalReferences(){
667
        Reference reference;
668

    
669
        //database
670
        IDatabase database1 = ReferenceFactory.newDatabase();
671
        reference = (Reference)database1;
672

    
673
        database1.setTitle("My database");
674
        //maybe we should have a trailing dot here
675
        Assert.assertEquals("My database: 55", reference.getNomenclaturalCitation(detail1));
676
        database1.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
677
        Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
678

    
679
        database1.setTitleCache("Your database", true);
680
        Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
681

    
682
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
683
        reference.setAbbrevTitleCache("You. Db.", true);
684
        Assert.assertEquals("You. Db.: 55. 1998", reference.getNomenclaturalCitation(detail1));
685

    
686

    
687
        //CD/DVD
688
        ICdDvd cdDvd = ReferenceFactory.newCdDvd();
689
        reference= (Reference)cdDvd;
690
        cdDvd.setTitle("My Cd/Dvd");
691
        //maybe we should have a trailing dot here
692
        Assert.assertEquals("My Cd/Dvd: 55", reference.getNomenclaturalCitation(detail1));
693
        cdDvd.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
694
        Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
695

    
696
        cdDvd.setTitleCache("Your Cd/Dvd", true);
697
        Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
698

    
699
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
700
        reference.setAbbrevTitleCache("You. Cd.", true);
701
        Assert.assertEquals("You. Cd.: 55. 1998", reference.getNomenclaturalCitation(detail1));
702

    
703

    
704
        //WebSite
705
        IWebPage webPage = ReferenceFactory.newWebPage();
706
        reference= (Reference)webPage;
707
        webPage.setTitle("My WebPage");
708
        //maybe we should have a trailing dot here
709
        Assert.assertEquals("My WebPage: 55", reference.getNomenclaturalCitation(detail1));
710
        webPage.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
711
        Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
712

    
713
        webPage.setTitleCache("Your WebPage", true);
714
        Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
715

    
716
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
717
        reference.setAbbrevTitleCache("You. WP.", true);
718
        Assert.assertEquals("You. WP.: 55. 1998", reference.getNomenclaturalCitation(detail1));
719

    
720
        //uri
721
        webPage = ReferenceFactory.newWebPage();
722
        reference= (Reference)webPage;
723
        webPage.setUri(URI.create("http://www.abc.de"));
724
        Assert.assertEquals("http://www.abc.de: 55", reference.getNomenclaturalCitation(detail1));
725

    
726
        //TBC
727
   }
728

    
729
// ********************************** WEB PAGE ********************************************/
730

    
731
    @Test
732
    //still preliminary, may be modified in future
733
    public void testWebPageGetTitleCache(){
734
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
735
        Assert.assertEquals("Unexpected title cache.",
736
                "http://flora.huji.ac.il",
737
                webPage1.getTitleCache());
738

    
739
        webPage1.setTitle("Flora of Israel Online");
740
        webPage1.setAuthorship(webPageTeam1);
741
        webPage1.setAccessed(DateTime.parse("2001-01-05"));
742
        Assert.assertEquals("Unexpected title cache.",
743
                "Authorteam, D., Flora of Israel Online - http://flora.huji.ac.il [accessed 2001-01-05]",
744
                webPage1.getTitleCache());
745

    
746
    }
747

    
748
//  @Test
749
//  //WebPages should usually not be used as nomencl.reference, therefore this is less important
750
//  public void testWebPageGetAbbrevTitleCache(){
751
//      webPage1.setTitle("auct.");
752
//      Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
753
//  }
754

    
755

    
756
}
(1-1/2)