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
.IArticle
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.IJournal
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
33 public class ArticleDefaultCacheStrategyTest
{
34 @SuppressWarnings("unused")
35 private static final Logger logger
= Logger
.getLogger(ArticleDefaultCacheStrategyTest
.class);
37 private static IArticle article1
;
38 private static IJournal journal1
;
39 private static Team team1
;
40 private static Team team2
;
41 private static ArticleDefaultCacheStrategy
<Reference
<?
>> defaultStrategy
;
42 private static final String detail1
= "55";
45 * @throws java.lang.Exception
48 public static void setUpBeforeClass() throws Exception
{
49 defaultStrategy
= ArticleDefaultCacheStrategy
.NewInstance();
53 * @throws java.lang.Exception
56 public void setUp() throws Exception
{
57 article1
= ReferenceFactory
.newArticle();
58 article1
.setCacheStrategy(defaultStrategy
);
59 journal1
= ReferenceFactory
.newJournal();
60 team1
= Team
.NewInstance();
61 team2
= Team
.NewInstance();
62 team1
.setTitleCache("Team1", true);
63 team1
.setNomenclaturalTitle("T.", true);
64 team2
.setTitleCache("Team2", true);
65 team2
.setNomenclaturalTitle("TT.", true);
68 //**************************** TESTS ***********************************
72 public void testGetTitleCache(){
73 journal1
.setTitle("My journal");
74 journal1
.setAuthorTeam(team2
);
75 article1
.setTitle("My article");
76 article1
.setInJournal(journal1
);
77 article1
.setAuthorTeam(team1
);
78 article1
.setDatePublished(TimePeriod
.NewInstance(1975));
79 Assert
.assertEquals("Team1, My article in My journal. 1975", article1
.getTitleCache());
81 article1
.setInJournal(null);
82 //TODO should not be needed here
83 article1
.setTitleCache(null);
84 Assert
.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy
.UNDEFINED_JOURNAL
+ ". 1975", article1
.getTitleCache());
89 //This test is just to show that there is still the title cache bug which is not
90 //set to null by setInJournal(null)
91 public void testGetTitleCache2(){
92 journal1
.setTitle("My journal");
93 journal1
.setAuthorTeam(team2
);
94 article1
.setTitle("My article");
95 article1
.setInJournal(journal1
);
96 article1
.setAuthorTeam(team1
);
97 article1
.setDatePublished(TimePeriod
.NewInstance(1975));
98 Assert
.assertEquals("Team1, My article in My journal. 1975", article1
.getTitleCache());
100 article1
.setInJournal(null);
101 Assert
.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy
.UNDEFINED_JOURNAL
+ ". 1975", article1
.getTitleCache());
105 public void testGetNomenclaturalCitation(){
106 journal1
.setTitle("My journal");
107 journal1
.setAuthorTeam(team2
);
108 article1
.setTitle("My article");
109 article1
.setInJournal(journal1
);
110 article1
.setAuthorTeam(team1
);
111 article1
.setDatePublished(TimePeriod
.NewInstance(1975));
112 Assert
.assertEquals("in My journal: 55. 1975", article1
.getNomenclaturalCitation(detail1
));
117 public void testGetNomRefTitleWithoutYearAndAuthor(){
118 journal1
.setTitle("My journal");
119 journal1
.setAuthorTeam(team2
);
120 article1
.setTitle("My article");
121 article1
.setInJournal(journal1
);
122 article1
.setAuthorTeam(team1
);
123 article1
.setVolume("34");
124 article1
.setSeries("ser. 2");
125 article1
.setDatePublished(TimePeriod
.NewInstance(1975));
126 Assert
.assertEquals("in My journal ser. 2, 34", defaultStrategy
.getNomRefTitleWithoutYearAndAuthor((Reference
<?
>)article1
));
130 public void testOldExistingBugs(){
131 journal1
.setTitle("Univ. Calif. Publ. Bot.");
132 journal1
.setAuthorTeam(null);
134 Team articleAuthor
= Team
.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
135 article1
.setTitle("");
136 article1
.setInJournal(journal1
);
137 article1
.setAuthorTeam(articleAuthor
);
138 article1
.setVolume("18");
139 article1
.setDatePublished(TimePeriod
.NewInstance(1943));
140 Assert
.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy
.getTitleCache((Reference
<?
>)article1
));