Project

General

Profile

Download (6.94 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
		team1 = Team.NewTitledInstance("Authorteam", "AT.");
55
	}
56

    
57
//**************************** TESTS ***********************************
58

    
59

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

    
66

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

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

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

    
101

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

    
126

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

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

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

    
140
	}
141

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

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

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

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

    
177

    
178

    
179
}
(5-5/6)