Project

General

Profile

Download (3.14 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.model.location;
11

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

    
14
import java.lang.reflect.Field;
15
import java.lang.reflect.Method;
16
import java.util.Map;
17
import java.util.UUID;
18

    
19
import org.apache.log4j.Logger;
20
import org.junit.After;
21
import org.junit.AfterClass;
22
import org.junit.Assert;
23
import org.junit.Before;
24
import org.junit.BeforeClass;
25
import org.junit.Test;
26

    
27
import eu.etaxonomy.cdm.model.common.Language;
28

    
29
/**
30
 * @author a.mueller
31
 * @created 23.10.2008
32
 * @version 1.0
33
 */
34
public class TdwgAreaTest {
35
	private static final Logger logger = Logger.getLogger(TdwgAreaTest.class);
36

    
37
	/**
38
	 * @throws java.lang.Exception
39
	 */
40
	@BeforeClass
41
	public static void setUpBeforeClass() throws Exception {
42
	}
43

    
44
	/**
45
	 * @throws java.lang.Exception
46
	 */
47
	@AfterClass
48
	public static void tearDownAfterClass() throws Exception {
49
	}
50

    
51
	/**
52
	 * @throws java.lang.Exception
53
	 */
54
	@Before
55
	public void setUp() throws Exception {
56
	}
57

    
58
	/**
59
	 * @throws java.lang.Exception
60
	 */
61
	@After
62
	public void tearDown() throws Exception {
63
	}
64

    
65
	/**
66
	 * Test method for {@link eu.etaxonomy.cdm.model.location.TdwgArea#getAreaByTdwgAbbreviation(java.lang.String)}.
67
	 */
68
	@Test
69
	public void testGetAreaByTdwgAbbreviation() {
70
		Language.ENGLISH(); // to make sure Terms are already loaded
71
		NamedArea area = TdwgArea.getAreaByTdwgAbbreviation("GER");
72
		Assert.assertEquals("Germany", area.getLabel(Language.ENGLISH()));
73
		Assert.assertNull(TdwgArea.getAreaByTdwgAbbreviation("A1R"));
74
	}
75

    
76
	/**
77
	 * Test method for {@link eu.etaxonomy.cdm.model.location.TdwgArea#getAreaByTdwgLabel(java.lang.String)}.
78
	 */
79
	@Test
80
	public void testGetAreaByTdwgLabel() {
81
		Assert.assertEquals("Germany", TdwgArea.getAreaByTdwgLabel("Germany").getLabel(Language.ENGLISH()));
82
		Assert.assertNull(TdwgArea.getAreaByTdwgLabel("A1R"));
83
	}
84

    
85
	/**
86
	 * Test method for {@link eu.etaxonomy.cdm.model.location.TdwgArea#isTdwgAreaLabel(java.lang.String)}.
87
	 */
88
	@Test
89
	public void testIsTdwgAreaLabel() {
90
		Assert.assertTrue(TdwgArea.isTdwgAreaLabel("Germany"));
91
		Assert.assertFalse(TdwgArea.isTdwgAreaLabel("sf2fe"));
92
	}
93

    
94
	/**
95
	 * Test method for {@link eu.etaxonomy.cdm.model.location.TdwgArea#addTdwgArea(eu.etaxonomy.cdm.model.location.NamedArea)}.
96
	 */
97
	@Test
98
	public void testAddTdwgArea() {
99
		String testAreaLabel = "TestArea";
100
		Assert.assertFalse(TdwgArea.isTdwgAreaLabel(testAreaLabel));
101
		NamedArea area = NamedArea.NewInstance("", testAreaLabel, "");
102
		TdwgArea.addTdwgArea(area);
103
		Field labelMapField = null;
104
		try {
105
			labelMapField = TdwgArea.class.getDeclaredField("labelMap");
106
			labelMapField.setAccessible(true);
107
			Object obj = labelMapField.get(null);
108
			Map<String, UUID> map = (Map<String, UUID>)obj;
109
			Assert.assertEquals(area.getUuid(), map.get(testAreaLabel));
110
		} catch (Exception e) {
111
			// TODO Auto-generated catch block
112
			e.printStackTrace();
113
		}
114
	}
115
}
    (1-1/1)