Project

General

Profile

Download (4.36 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 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

    
11
package eu.etaxonomy.cdm.strategy.parser;
12

    
13
import static org.junit.Assert.*;
14

    
15
import java.util.List;
16

    
17
import org.apache.log4j.Logger;
18
import org.junit.After;
19
import org.junit.AfterClass;
20
import org.junit.Before;
21
import org.junit.BeforeClass;
22
import org.junit.Test;
23

    
24
/**
25
 * @author a.mueller
26
 * @created 04.09.2009
27
 * @version 1.0
28
 */
29
public class ParserProblemTest {
30
	@SuppressWarnings("unused")
31
	private static final Logger logger = Logger.getLogger(ParserProblemTest.class);
32

    
33
	/**
34
	 * @throws java.lang.Exception
35
	 */
36
	@BeforeClass
37
	public static void setUpBeforeClass() throws Exception {
38
	}
39

    
40
	/**
41
	 * @throws java.lang.Exception
42
	 */
43
	@AfterClass
44
	public static void tearDownAfterClass() throws Exception {
45
	}
46

    
47
	/**
48
	 * @throws java.lang.Exception
49
	 */
50
	@Before
51
	public void setUp() throws Exception {
52
	}
53

    
54
	/**
55
	 * @throws java.lang.Exception
56
	 */
57
	@After
58
	public void tearDown() throws Exception {
59
	}
60

    
61
/****** TESTS ******************************************	
62
	
63

    
64
	/**
65
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem#warningList(int)}.
66
	 */
67
	@Test
68
	public void testWarningList() {
69
		List<ParserProblem> list = ParserProblem.warningList(5);
70
		assertEquals("list must include 2 warnings", 2, list.size());
71
		assertTrue("Warning list should include warning 0", list.contains(ParserProblem.CheckRank));
72
		assertTrue("Warning list should include warning 2", list.contains(ParserProblem.NameReferenceSeparation));
73
	}
74
	
75
	@Test
76
	public void testAddProblem(){
77
		int warning = ParserProblem.addProblem(0, ParserProblem.NameReferenceSeparation);
78
		int expected = (int)Math.pow(2, ParserProblem.NameReferenceSeparation.ordinal()) ;
79
		assertEquals("Unexpected value for addWarning", expected,warning);
80
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckDetailOrYear);
81
		expected = expected + (int)Math.pow(2, ParserProblem.CheckDetailOrYear.ordinal()) ;
82
		assertEquals("Unexpected value for addWarning", expected,warning);
83
	}
84
	
85
	@Test
86
	public void testRemoveProblem(){
87
		int warning = ParserProblem.addProblem(0, ParserProblem.NameReferenceSeparation);
88
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckRank);
89
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckDetailOrYear);
90
		assertEquals("Number of problems must be 3", 3, ParserProblem.warningList(warning).size());
91
		assertTrue("Check Rank must be a problem", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
92
		
93
		warning = ParserProblem.removeProblem(warning, ParserProblem.CheckRank);
94
		assertEquals("Number of problems must be 2", 2, ParserProblem.warningList(warning).size());
95
		assertFalse("Check Rank must not be a problem anymore", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
96
		
97
		warning = ParserProblem.removeProblem(warning, ParserProblem.CheckRank);
98
		assertEquals("Number of problems must be 2", 2, ParserProblem.warningList(warning).size());
99
		assertFalse("Check Rank must not be a problem anymore", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
100

    
101
		warning = ParserProblem.removeProblem(warning, null);
102
		assertEquals("Number of problems must be 2", 2, ParserProblem.warningList(warning).size());
103
		assertFalse("Check Rank must not be a problem anymore", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
104
	}
105
	
106
	@Test
107
	public void testAddProblems(){
108
		assertEquals("Unexpected value for addWarning", 23, ParserProblem.addProblems(21, 6));
109
	}
110
	
111
	@Test
112
	public void testIsError() {
113
		assertTrue("NameReferenceSeparation must be error", ParserProblem.NameReferenceSeparation.isError());
114
	}
115
	
116
	@Test
117
	public void testIsWarning() {
118
		assertTrue("CheckDetail must be warning", ParserProblem.CheckDetailOrYear.isWarning());
119
	}
120
	
121
	@Test
122
	public void testHasError() {
123
		int warning = ParserProblem.addProblem(0, ParserProblem.NameReferenceSeparation);
124
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckDetailOrYear);
125
		assertTrue("warning list with NameReferenceSeparation must have error", ParserProblem.hasError(warning));
126
	}
127

    
128
}
(3-3/4)