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.old;
|
11
|
|
12
|
|
13
|
import org.junit.Assert;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.BeforeClass;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.agent.Team;
|
22
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
23
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
24
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
25
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
* @date 16.06.2010
|
30
|
*
|
31
|
*/
|
32
|
public class BookSectionDefaultCacheStrategyTest {
|
33
|
@SuppressWarnings("unused")
|
34
|
private static final Logger logger = Logger.getLogger(BookSectionDefaultCacheStrategyTest.class);
|
35
|
|
36
|
private static IBookSection bookSection1;
|
37
|
private static IBook book1;
|
38
|
private static Team sectionTeam1;
|
39
|
private static Team bookTeam1;
|
40
|
private static BookSectionDefaultCacheStrategy defaultStrategy;
|
41
|
private static final String detail1 = "55";
|
42
|
|
43
|
/**
|
44
|
* @throws java.lang.Exception
|
45
|
*/
|
46
|
@BeforeClass
|
47
|
public static void setUpBeforeClass() throws Exception {
|
48
|
defaultStrategy = BookSectionDefaultCacheStrategy.NewInstance();
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @throws java.lang.Exception
|
53
|
*/
|
54
|
@Before
|
55
|
public void setUp() throws Exception {
|
56
|
bookSection1 = ReferenceFactory.newBookSection();
|
57
|
bookSection1.setCacheStrategy(defaultStrategy);
|
58
|
book1 = ReferenceFactory.newBook();
|
59
|
sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
|
60
|
bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
|
61
|
}
|
62
|
|
63
|
//**************************** TESTS ***********************************
|
64
|
|
65
|
|
66
|
@Test
|
67
|
public void testGetTitleCache(){
|
68
|
book1.setTitle("My book");
|
69
|
book1.setAuthorship(bookTeam1);
|
70
|
bookSection1.setTitle("My chapter");
|
71
|
bookSection1.setInBook(book1);
|
72
|
bookSection1.setAuthorship(sectionTeam1);
|
73
|
book1.setDatePublished(TimePeriod.NewInstance(1975));
|
74
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
|
75
|
book1.setDatePublished(null);
|
76
|
bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
|
77
|
bookSection1.setTitleCache(null, false);
|
78
|
book1.setTitleCache(null, false);
|
79
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
|
80
|
book1.setDatePublished(TimePeriod.NewInstance(1977));
|
81
|
bookSection1.setTitleCache(null, false);
|
82
|
book1.setTitleCache(null, false);
|
83
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
|
84
|
bookSection1.setTitleCache(null, false);
|
85
|
book1.setTitleCache(null, false);
|
86
|
book1.setSeriesPart("2");
|
87
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
|
88
|
|
89
|
bookSection1.setInBook(null);
|
90
|
bookSection1.setTitleCache(null, false);
|
91
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
|
92
|
|
93
|
}
|
94
|
|
95
|
@Ignore
|
96
|
@Test
|
97
|
//This test is just to show that there is still the title cache bug which is not
|
98
|
//set to null by setInBook(null) and others
|
99
|
public void testGetTitleCache2(){
|
100
|
book1.setTitle("My book");
|
101
|
book1.setAuthorship(bookTeam1);
|
102
|
bookSection1.setTitle("My chapter");
|
103
|
bookSection1.setInBook(book1);
|
104
|
bookSection1.setAuthorship(sectionTeam1);
|
105
|
book1.setDatePublished(TimePeriod.NewInstance(1975));
|
106
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
|
107
|
book1.setDatePublished(null);
|
108
|
bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
|
109
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
|
110
|
book1.setDatePublished(TimePeriod.NewInstance(1977));
|
111
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
|
112
|
|
113
|
|
114
|
bookSection1.setInBook(null);
|
115
|
Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
|
116
|
|
117
|
}
|
118
|
|
119
|
|
120
|
@Test
|
121
|
public void testGetNomenclaturalCitation(){
|
122
|
book1.setTitle("My book");
|
123
|
book1.setAuthorship(bookTeam1);
|
124
|
bookSection1.setTitle("My chapter");
|
125
|
bookSection1.setInBook(book1);
|
126
|
bookSection1.setAuthorship(sectionTeam1);
|
127
|
book1.setDatePublished(TimePeriod.NewInstance(1975));
|
128
|
//TODO still unclear which is correct
|
129
|
// Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
|
130
|
Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
|
131
|
|
132
|
book1.setSeriesPart("2");
|
133
|
Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
|
134
|
}
|
135
|
|
136
|
@Test
|
137
|
public void testRealExample(){
|
138
|
Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
|
139
|
IBook book = ReferenceFactory.newBook();
|
140
|
book.setTitle("Flora of the Kingdom of Saudi Arabia");
|
141
|
book.setAuthorship(bookTeam);
|
142
|
book.setVolume("2(3)");
|
143
|
book.setPlacePublished("Riyadh");
|
144
|
book.setPublisher("National Herbarium");
|
145
|
book.setDatePublished(TimePeriod.NewInstance(2000));
|
146
|
|
147
|
Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
|
148
|
IBookSection bookSection = ReferenceFactory.newBookSection();
|
149
|
bookSection.setTitle("73. Hedypnois - 87. Crepis");
|
150
|
bookSection.setInBook(book);
|
151
|
bookSection.setAuthorship(sectionTeam);
|
152
|
bookSection.setPages("222-251");
|
153
|
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());
|
154
|
|
155
|
}
|
156
|
|
157
|
}
|