Project

General

Profile

Download (6.98 KB) Statistics
| Branch: | Tag: | Revision:
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.apache.log4j.Logger;
14
import org.junit.Assert;
15
import org.junit.Before;
16
import org.junit.BeforeClass;
17
import org.junit.Test;
18

    
19
import eu.etaxonomy.cdm.model.agent.Team;
20
import eu.etaxonomy.cdm.model.reference.IBook;
21
import eu.etaxonomy.cdm.model.reference.IGeneric;
22
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
24
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
25

    
26
/**
27
 * @author a.mueller
28
 * @date 16.06.2010
29
 *
30
 */
31
public class GenericDefaultCacheStrategyTest {
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(GenericDefaultCacheStrategyTest.class);
34

    
35
	private static IGeneric generic1;
36
	private static Team team1;
37
	private static GenericDefaultCacheStrategy defaultStrategy;
38
	private static final String detail1 = "55";
39

    
40
	/**
41
	 * @throws java.lang.Exception
42
	 */
43
	@BeforeClass
44
	public static void setUpBeforeClass() throws Exception {
45
		defaultStrategy = GenericDefaultCacheStrategy.NewInstance();
46
	}
47

    
48
	/**
49
	 * @throws java.lang.Exception
50
	 */
51
	@Before
52
	public void setUp() throws Exception {
53
		generic1 = ReferenceFactory.newGeneric();
54
		generic1.setCacheStrategy(defaultStrategy);
55
		team1 = Team.NewTitledInstance("Authorteam", "AT.");
56
	}
57

    
58
//**************************** TESTS ***********************************
59

    
60

    
61
	@Test
62
	public void testGetTitleCache(){
63
		generic1.setTitle("auct.");
64
		Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
65
	}
66

    
67

    
68
	@Test
69
	public void testGetInRef(){
70
		generic1.setTitle("auct.");
71
		IBook book1 = ReferenceFactory.newBook();
72
		book1.setTitle("My book title");
73
		book1.setAuthorship(team1);
74
		Reference inRef = (Reference)book1;
75
		generic1.setInReference(inRef);
76
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
77
		//TODO author still unclear
78
//		Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
79
		Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
80
	}
81

    
82
	@Test
83
	public void testGetInRefWithoutInRef(){
84
		generic1.setTitle("My generic title");
85
		generic1.setAuthorship(team1);
86
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
87
		Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
88
	}
89

    
90
	@Test
91
	public void testGetTitleCache2(){
92
		generic1.setTitle("Part Title");
93
		IBook book1 = ReferenceFactory.newBook();
94
		book1.setTitle("My book title");
95
		book1.setAuthorship(team1);
96
		Reference inRef = (Reference)book1;
97
		generic1.setInReference(inRef);
98
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
99
		Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
100
	}
101

    
102

    
103
	@Test
104
	public void testGetAbbrevTitleCache(){
105
		generic1.setTitle("Part Title");
106
		generic1.setAbbrevTitle("Pt. Tit.");
107
		generic1.setDatePublished(TimePeriodParser.parseString("1987"));
108
		IBook book1 = ReferenceFactory.newBook();
109
		book1.setTitle("My book title");
110
		book1.setAbbrevTitle("My bk. tit.");
111
		book1.setAuthorship(team1);  //TODO handling not yet defined
112
		Reference inRef = (Reference)book1;
113
		generic1.setInReference(inRef);
114
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
115
		generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
116
		Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
117
		Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
118
		//TODO author still unclear
119
//		Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
120
		Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
121
		generic1.setVolume("23");
122
		Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
123
		generic1.setSeriesPart("ser. 11");
124
		//TODO
125
//		Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
126

    
127

    
128
		//protected
129
		generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
130
		Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
131
		Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
132

    
133
		generic1.setDatePublished(null);
134
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
135
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
136
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
137

    
138
		generic1.setDatePublished(TimePeriodParser.parseString("1893"));
139
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
140

    
141
	}
142

    
143
	@Test
144
	public void testGetTitleCacheWithoutInRef(){
145
		generic1.setTitle("My generic title");
146
		generic1.setAuthorship(team1);
147
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
148
		Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
149
	}
150

    
151
	@Test
152
	public void testAuthorOnly(){
153
		generic1.setAuthorship(team1);
154
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
155
		Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
156
		Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
157
	}
158

    
159
	@Test
160
	public void testYearAndAuthorOnly(){
161
		generic1.setAuthorship(team1);
162
		generic1.setDatePublished(TimePeriodParser.parseString("1792"));
163
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
164
		Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
165
		Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
166
	}
167

    
168
	@Test
169
	public void testDoubleDotBeforeYear(){
170
		generic1.setAuthorship(team1);
171
		String detail = "sine no.";
172
		generic1.setAbbrevTitle("My title");
173
		generic1.setDatePublished(TimePeriodParser.parseString("1883-1884"));
174
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
175
		Assert.assertEquals("My title: sine no. 1883-1884", generic1.getNomenclaturalCitation(detail));
176
	}
177

    
178

    
179

    
180
}
(5-5/6)