Project

General

Profile

Download (3.99 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.junit.Assert;
14

    
15
import org.apache.log4j.Logger;
16
import org.junit.Before;
17
import org.junit.BeforeClass;
18
import org.junit.Test;
19

    
20
import eu.etaxonomy.cdm.model.agent.Team;
21
import eu.etaxonomy.cdm.model.common.TimePeriod;
22
import eu.etaxonomy.cdm.model.reference.IBook;
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 BookDefaultCacheStrategyTest {
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(BookDefaultCacheStrategyTest.class);
34
	
35
	private static IBook book1;
36
	private static Team bookTeam1;
37
	private static BookDefaultCacheStrategy 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 = BookDefaultCacheStrategy.NewInstance();
46
	}
47

    
48
	/**
49
	 * @throws java.lang.Exception
50
	 */
51
	@Before
52
	public void setUp() throws Exception {
53
		book1 = ReferenceFactory.newBook();
54
		bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
55
	}
56
	
57
//**************************** TESTS ***********************************
58

    
59
	
60
	@Test
61
	public void testGetTitleCache(){
62
		book1.setTitle("My book");
63
		book1.setAuthorship(bookTeam1);
64
		book1.setDatePublished(TimePeriod.NewInstance(1975));
65
		Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
66
		
67
		book1.setTitleCache(null, false);
68
		book1.setEdition("ed. 3");
69
		Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3. 1975", book1.getTitleCache());
70
		
71
		TimePeriod newDatePublished = TimePeriodParser.parseString("1975 (after Aug.)");
72
		book1.setDatePublished(newDatePublished);
73
		book1.setTitleCache(null, false);
74
		//TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
75
		Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3", book1.getTitleCache());
76

    
77
	}
78
	
79
	
80
	@Test
81
	public void testGetBookTitleCache(){
82
		//series
83
		IBook book1 = ReferenceFactory.newBook();
84
		book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
85
		book1.setSeriesPart("1");
86
		book1.setVolume("Fasc. 11");
87
		book1.setDatePublished(TimePeriodParser.parseString("1955"));
88
		Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
89
		Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
90
	}
91
	
92
	
93
	@Test
94
	public void testGetBookTitleCache2(){
95
		//series
96
		IBook book1 = ReferenceFactory.newBook();
97
		book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
98
		book1.setVolume("Fasc. 11");
99
		book1.setDatePublished(TimePeriodParser.parseString("1955"));
100
		Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
101
		Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
102
		book1.setSeriesPart("1");
103
		Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
104
	}
105
	
106

    
107
	
108
	@Test
109
	public void testGetNomenclaturalCitation(){
110
		book1.setTitle("My book");
111
		book1.setAuthorship(bookTeam1);
112
		book1.setDatePublished(TimePeriod.NewInstance(1975));
113
		Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
114
		book1.setAbbrevTitle("Analect. Bot.");
115
		Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
116
	}
117
	
118
}
(2-2/6)