Project

General

Profile

Download (18.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 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.format.reference;
10

    
11
import org.junit.Assert;
12
import org.junit.Before;
13
import org.junit.Test;
14

    
15
import eu.etaxonomy.cdm.common.URI;
16
import eu.etaxonomy.cdm.model.agent.Person;
17
import eu.etaxonomy.cdm.model.agent.Team;
18
import eu.etaxonomy.cdm.model.common.TimePeriod;
19
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
20
import eu.etaxonomy.cdm.model.reference.IArticle;
21
import eu.etaxonomy.cdm.model.reference.IBook;
22
import eu.etaxonomy.cdm.model.reference.IBookSection;
23
import eu.etaxonomy.cdm.model.reference.ICdDvd;
24
import eu.etaxonomy.cdm.model.reference.IDatabase;
25
import eu.etaxonomy.cdm.model.reference.IJournal;
26
import eu.etaxonomy.cdm.model.reference.IWebPage;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
30
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
31

    
32
/**
33
 * @author a.mueller
34
 * @since 03.05.2021
35
 */
36
public class NomenclaturalSourceFormatterTest {
37

    
38
    private static final String SEP = TimePeriod.SEP;
39

    
40
    //article
41
    private static IArticle article1;
42
    private static IJournal journal1;
43
    private static Team articleTeam1;
44
    private static Team articleTeam2;
45

    
46
    //book // book section
47
    private static IBook book1;
48
    private static Team bookTeam1;
49

    
50
    //book section
51
    private static IBookSection bookSection1;
52
    private static Team sectionTeam1;
53

    
54
    //Generic
55
    private static Reference generic1;
56
    private static Team genericTeam1;
57

    
58
    //common
59
    private static NomenclaturalSourceFormatter formatter = NomenclaturalSourceFormatter.INSTANCE();
60
    private static final String detail1 = "55";
61

    
62
    @Before
63
    public void setUp() throws Exception {
64
        //article
65
        article1 = ReferenceFactory.newArticle();
66
        journal1 = ReferenceFactory.newJournal();
67
        articleTeam1 = Team.NewInstance();
68
        articleTeam2 = Team.NewInstance();
69
        articleTeam1.setTitleCache("Team1", true);
70
        articleTeam1.setNomenclaturalTitle("T.", true);
71
        articleTeam2.setTitleCache("Team2", true);
72
        articleTeam2.setNomenclaturalTitle("TT.", true);
73

    
74
        //book / section
75
        book1 = ReferenceFactory.newBook();
76
        bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
77
        bookSection1 = ReferenceFactory.newBookSection();
78
        sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
79

    
80
        //Generic
81
        generic1 = ReferenceFactory.newGeneric();
82
        genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
83
    }
84

    
85

    
86
    @Test
87
    public void testArticleGetNomenclaturalCitation(){
88
        journal1.setTitle("My journal");
89
        journal1.setTitle("M. J.");
90
        ((Reference)journal1).setAuthorship(articleTeam2);
91
        article1.setTitle("My article");
92
        article1.setInJournal(journal1);
93
        article1.setAuthorship(articleTeam1);
94
        article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
95
        Assert.assertEquals("in M. J.: 55. 1975", formatter.format((Reference)article1, detail1));
96

    
97
        article1.setVolume("22");
98
        Assert.assertEquals("in M. J. 22: 55. 1975", formatter.format((Reference)article1, detail1));
99
        article1.setSeriesPart("ser. 11");
100
        Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", formatter.format((Reference)article1, detail1));
101

    
102
        article1.setPages("33"); //#6496 don't show pages in nomencl. citation
103
        Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", formatter.format((Reference)article1, detail1));
104
    }
105

    
106
    /**
107
     * After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
108
     */
109
    @Test
110
    public void testArticleGetNomenclaturalCitationSerSectAbt(){
111
        article1.setInJournal(journal1);
112
        article1.setVolume("22");
113
        journal1.setAbbrevTitle("J. Pl. Eur.");
114
        ((Reference)journal1).setAuthorship(articleTeam2);
115
        article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
116
        //no ser, sect, abt
117
        Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", formatter.format((Reference)article1, detail1));
118
        //ser
119
        journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
120
        Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
121
        journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
122
        Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
123
        journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
124
        Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", formatter.format((Reference)article1, detail1));
125
        //sect
126
        journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
127
        Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
128
        journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
129
        Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
130
        journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
131
        Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", formatter.format((Reference)article1, detail1));
132
        //abt
133
        journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
134
        Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
135
        journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
136
        Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", formatter.format((Reference)article1, detail1));
137
        journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
138
        Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", formatter.format((Reference)article1, detail1));
139

    
140
        journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
141
        article1.setSeriesPart("1");
142
        Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", formatter.format((Reference)article1, detail1));
143
        article1.setSeriesPart("Series 2");
144
        Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", formatter.format((Reference)article1, detail1));
145
    }
146

    
147
    @Test
148
    public void testBookGetNomenclaturalCitation(){
149
        book1.setTitle("My book");
150
        book1.setAuthorship(bookTeam1);
151
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
152
        Assert.assertEquals("My book: 55. 1975", formatter.format((Reference)book1, detail1));
153
        book1.setAbbrevTitle("Analect. Bot.");
154
        Assert.assertEquals("Analect. Bot. 1975", formatter.format((Reference)book1, null));
155
    }
156

    
157

    
158
    //https://dev.e-taxonomy.eu/redmine/issues/8881
159
    @Test
160
    public void testInRefAuthor(){
161
        Person person1 = Person.NewInstance("Inauth.", "Inauthor", "A.B.", "Ala Bala");
162
        Person person2 = Person.NewInstance("Twoauth.", "Twoauthor", "C.", "Cla");
163
        Person person3 = Person.NewTitledInstance("Threeauth.");
164
        Team team = Team.NewInstance(person1, person2, person3);
165
        IBook book1 = ReferenceFactory.newBook();
166
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
167
        book1.setVolume("Fasc. 11");
168
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
169
        bookSection1.setTitle("My chapter");
170
        bookSection1.setInBook(book1);
171
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1956));
172

    
173
        book1.setAuthorship(person1);
174
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
175
        book1.setAuthorship(team);
176
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor & Threeauth., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
177
        team.setHasMoreMembers(true);
178
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor & al., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
179
        book1.setAuthorship(Team.NewInstance(person1));
180
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
181

    
182
        //for the following the behavior is not yet finally discussed, may change in future
183
        book1.setAuthorship(team);
184
        team.setTitleCache("Teamcache", true);
185
        Assert.assertEquals("Unexpected nomencl. reference", "in Teamcache, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
186
        team.setTitleCache("Teamc.", true);
187
        Assert.assertEquals("Unexpected nomencl. reference", "in Teamc., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
188
        book1.setAuthorship(Team.NewInstance());
189
        Assert.assertEquals("Unexpected nomencl. reference", "in "+TeamDefaultCacheStrategy.EMPTY_TEAM+", Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", formatter.format((Reference)bookSection1, "248"));
190
    }
191

    
192
    //#3532
193
    @Test
194
    public void testUnexpectedNomenclaturalReferences(){
195
        Reference reference;
196

    
197
        //database
198
        IDatabase database1 = ReferenceFactory.newDatabase();
199
        reference = (Reference)database1;
200

    
201
        database1.setTitle("My database");
202
        //maybe we should have a trailing dot here
203
        Assert.assertEquals("My database: 55", formatter.format(reference, detail1));
204
        database1.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
205
        Assert.assertEquals("My database: 55. 1998", formatter.format(reference, detail1));
206

    
207
        database1.setTitleCache("Your database", true);
208
        Assert.assertEquals("My database: 55. 1998", formatter.format(reference, detail1));
209

    
210
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
211
        reference.setAbbrevTitleCache("You. Db.", true);
212
        Assert.assertEquals("You. Db.: 55. 1998", formatter.format(reference, detail1));
213

    
214

    
215
        //CD/DVD
216
        ICdDvd cdDvd = ReferenceFactory.newCdDvd();
217
        reference= (Reference)cdDvd;
218
        cdDvd.setTitle("My Cd/Dvd");
219
        //maybe we should have a trailing dot here
220
        Assert.assertEquals("My Cd/Dvd: 55", formatter.format(reference, detail1));
221
        cdDvd.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
222
        Assert.assertEquals("My Cd/Dvd: 55. 1998", formatter.format(reference, detail1));
223

    
224
        cdDvd.setTitleCache("Your Cd/Dvd", true);
225
        Assert.assertEquals("My Cd/Dvd: 55. 1998", formatter.format(reference, detail1));
226

    
227
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
228
        reference.setAbbrevTitleCache("You. Cd.", true);
229
        Assert.assertEquals("You. Cd.: 55. 1998", formatter.format(reference, detail1));
230

    
231

    
232
        //WebSite
233
        IWebPage webPage = ReferenceFactory.newWebPage();
234
        reference= (Reference)webPage;
235
        webPage.setTitle("My WebPage");
236
        //maybe we should have a trailing dot here
237
        Assert.assertEquals("My WebPage: 55", formatter.format(reference, detail1));
238
        webPage.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
239
        Assert.assertEquals("My WebPage: 55. 1998", formatter.format(reference, detail1));
240

    
241
        webPage.setTitleCache("Your WebPage", true);
242
        Assert.assertEquals("My WebPage: 55. 1998", formatter.format(reference, detail1));
243

    
244
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
245
        reference.setAbbrevTitleCache("You. WP.", true);
246
        Assert.assertEquals("You. WP.: 55. 1998", formatter.format(reference, detail1));
247

    
248
        //uri
249
        webPage = ReferenceFactory.newWebPage();
250
        reference= (Reference)webPage;
251
        webPage.setUri(URI.create("http://www.abc.de"));
252
        Assert.assertEquals("http://www.abc.de: 55", formatter.format(reference, detail1));
253

    
254
        //TBC
255
    }
256

    
257
    @Test
258
    public void testBookSectionGetNomenclaturalCitation(){
259
        book1.setTitle("My book");
260
        book1.setAuthorship(bookTeam1);
261
        bookSection1.setTitle("My chapter");
262
        bookSection1.setInBook(book1);
263
        bookSection1.setAuthorship(sectionTeam1);
264
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
265
        //TODO still unclear which is correct
266
//      Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
267
        Assert.assertEquals("in TT., My book: 55. 1975", formatter.format((Reference)bookSection1, detail1));
268

    
269
        book1.setSeriesPart("2");
270
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", formatter.format((Reference)bookSection1, detail1));
271
        //#6496 don't show pages in nom.ref. citations
272
        bookSection1.setPages("35-39");
273
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", formatter.format((Reference)bookSection1, detail1));
274
    }
275

    
276
    @Test
277
    public void testGenericGetInRef(){
278
        generic1.setTitle("auct.");
279
        IBook book1 = ReferenceFactory.newBook();
280
        book1.setTitle("My book title");
281
        book1.setAuthorship(genericTeam1);
282
        Reference inRef = (Reference)book1;
283
        generic1.setInReference(inRef);
284
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
285
        //TODO author still unclear
286
//      Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
287
        Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", formatter.format(generic1, "2"));
288
    }
289

    
290
    @Test
291
    public void testGenericDoubleDotBeforeYear(){
292
        generic1.setAuthorship(genericTeam1);
293
        String detail = "sine no.";
294
        generic1.setAbbrevTitle("My title");
295
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
296
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
297
        Assert.assertEquals("My title: sine no. 1883"+SEP+"1884", formatter.format(generic1, detail));
298
    }
299

    
300

    
301
    @Test
302
    public void testGenericGetAbbrevTitleCache(){
303
        generic1.setTitle("Part Title");
304
        generic1.setAbbrevTitle("Pt. Tit.");
305
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
306
        IBook book1 = ReferenceFactory.newBook();
307
        book1.setTitle("My book title");
308
        book1.setAbbrevTitle("My bk. tit.");
309
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
310
        Reference inRef = (Reference)book1;
311
        generic1.setInReference(inRef);
312
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
313
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
314
        //TODO author still unclear
315
//      Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
316
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", formatter.format(generic1, "pp. 44"));
317
        generic1.setVolume("23");
318
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", formatter.format(generic1, "pp. 44"));
319
        generic1.setSeriesPart("ser. 11");
320
        //TODO
321
//      Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
322

    
323
        //protected
324
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);  //TODO still needed?
325

    
326
        generic1.setDatePublished((VerbatimTimePeriod)null);
327
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", formatter.format(generic1, null));
328
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", formatter.format(generic1, ""));
329
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", formatter.format(generic1, "pp. 44"));
330

    
331
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1893"));
332
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", formatter.format(generic1, "pp. 44"));
333
    }
334

    
335
    @Test
336
    public void testGenericGetInRefWithoutInRef(){
337
        generic1.setTitle("My generic title");
338
        generic1.setAuthorship(genericTeam1);
339
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
340
        Assert.assertEquals("Unexpected title cache.", "My generic title: 2", formatter.format(generic1, "2"));
341
    }
342

    
343
    @Test
344
    public void testBookGetTitleCache2(){
345
        //series
346
        IBook book1 = ReferenceFactory.newBook();
347
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
348
        book1.setVolume("Fasc. 11");
349
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
350
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", formatter.format((Reference)book1, "248"));
351
        book1.setSeriesPart("1");
352
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", formatter.format((Reference)book1, "248"));
353
    }
354

    
355
    //#4338
356
    @Test
357
    public void testGenericMissingVolume(){
358
        generic1.setTitle("My generic");
359
        generic1.setAuthorship(genericTeam1);
360
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
361
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
362
        Assert.assertEquals("My generic: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
363
        generic1.setVolume("7");
364
        Assert.assertEquals("My generic 7: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
365

    
366
        //inRef
367
        Reference generic2 = ReferenceFactory.newGeneric();
368
        generic2.setTitle("My InRef");
369
        Person person2 = Person.NewTitledInstance("InRefAuthor");
370
        generic2.setAuthorship(person2);
371
        generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
372
        generic1.setInReference(generic2);
373

    
374
        //only reference has a volume
375
        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
376

    
377
        //both have a volume
378
        generic2.setVolume("9");  //still unclear what should happen if you have such dirty data
379
//        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", formatter.format(generic1, detail1));
380

    
381
        //only inref has volume
382
        generic1.setVolume(null);
383
        Assert.assertEquals("in InRefAuthor, My InRef 9: 55. 1883"+SEP+"1884", formatter.format(generic1, detail1));
384
   }
385
}
(1-1/2)