3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.strategy
.cache
.reference
;
13 import org
.junit
.Assert
;
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
;
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
;
32 public class BookSectionDefaultCacheStrategyTest
{
33 @SuppressWarnings("unused")
34 private static final Logger logger
= Logger
.getLogger(BookSectionDefaultCacheStrategyTest
.class);
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";
44 * @throws java.lang.Exception
47 public static void setUpBeforeClass() throws Exception
{
48 defaultStrategy
= BookSectionDefaultCacheStrategy
.NewInstance();
52 * @throws java.lang.Exception
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.");
63 //**************************** TESTS ***********************************
67 public void testGetTitleCache(){
68 book1
.setTitle("My book");
69 book1
.setAuthorTeam(bookTeam1
);
70 bookSection1
.setTitle("My chapter");
71 bookSection1
.setInBook(book1
);
72 bookSection1
.setAuthorTeam(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);
78 book1
.setTitleCache(null);
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);
82 book1
.setTitleCache(null);
83 Assert
.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1
.getTitleCache());
85 bookSection1
.setInBook(null);
86 bookSection1
.setTitleCache(null);
87 Assert
.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1
.getTitleCache());
93 //This test is just to show that there is still the title cache bug which is not
94 //set to null by setInBook(null) and otheres
95 public void testGetTitleCache2(){
96 book1
.setTitle("My book");
97 book1
.setAuthorTeam(bookTeam1
);
98 bookSection1
.setTitle("My chapter");
99 bookSection1
.setInBook(book1
);
100 bookSection1
.setAuthorTeam(sectionTeam1
);
101 book1
.setDatePublished(TimePeriod
.NewInstance(1975));
102 Assert
.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1
.getTitleCache());
103 book1
.setDatePublished(null);
104 bookSection1
.setDatePublished(TimePeriod
.NewInstance(1976));
105 Assert
.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1
.getTitleCache());
106 book1
.setDatePublished(TimePeriod
.NewInstance(1977));
107 Assert
.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1
.getTitleCache());
109 bookSection1
.setInBook(null);
110 Assert
.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1
.getTitleCache());
116 public void testGetNomenclaturalCitation(){
117 book1
.setTitle("My book");
118 book1
.setAuthorTeam(bookTeam1
);
119 bookSection1
.setTitle("My chapter");
120 bookSection1
.setInBook(book1
);
121 bookSection1
.setAuthorTeam(sectionTeam1
);
122 book1
.setDatePublished(TimePeriod
.NewInstance(1975));
123 Assert
.assertEquals("in Book Author, My book: 55. 1975", bookSection1
.getNomenclaturalCitation(detail1
));
127 public void testRealExample(){
128 Team bookTeam
= Team
.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
129 IBook book
= ReferenceFactory
.newBook();
130 book
.setTitle("Flora of the Kingdom of Saudi Arabia");
131 book
.setAuthorTeam(bookTeam
);
132 book
.setVolume("2(3)");
133 book
.setPlacePublished("Riyadh");
134 book
.setPublisher("National Herbarium");
135 book
.setDatePublished(TimePeriod
.NewInstance(2000));
137 Team sectionTeam
= Team
.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
138 IBookSection bookSection
= ReferenceFactory
.newBookSection();
139 bookSection
.setTitle("73. Hedypnois - 87. Crepis");
140 bookSection
.setInBook(book
);
141 bookSection
.setAuthorTeam(sectionTeam
);
142 bookSection
.setPages("222-251");
143 System
.out
.println(bookSection
.getTitleCache());
144 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());