Project

General

Profile

Download (6.63 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.model.location;
11

    
12

    
13
import java.text.ParseException;
14

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

    
21
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
22
import eu.etaxonomy.cdm.model.location.Point.Direction;
23
import eu.etaxonomy.cdm.model.location.Point.Sexagesimal;
24
import eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.ConversionResults;
25

    
26
/**
27
 * @author a.mueller
28
 * @date 04.06.2010
29
 *
30
 */
31
public class PointTest {
32
	private static final Logger logger = Logger.getLogger(PointTest.class);
33

    
34
	private Point point1;
35
	private Point point2;
36
	
37
	private Integer errorRadius;
38
	private Double longitude1;
39
	private Double latitude1;
40
	private Double longitude2;
41
	private Double latitude2;
42
	
43
	private ReferenceSystem referenceSystem;
44
	
45
	
46
	/**
47
	 * @throws java.lang.Exception
48
	 */
49
	@BeforeClass
50
	public static void setUpBeforeClass() throws Exception {
51
		if (ReferenceSystem.WGS84() == null){
52
			new DefaultTermInitializer().initialize();
53
		}
54
	}
55

    
56
	/**
57
	 * @throws java.lang.Exception
58
	 */
59
	@Before
60
	public void setUp() throws Exception {
61
		longitude1 = 23.123556;
62
		latitude1 = -13.975556;
63
		
64
		longitude2 = 28.48556;
65
		latitude2 = 12.656;
66
		
67
		errorRadius = 5;
68
		referenceSystem = ReferenceSystem.GOOGLE_EARTH();
69
		
70
		point1 = Point.NewInstance(longitude1, latitude1, referenceSystem, errorRadius);
71
		point2 = Point.NewInstance();
72
		
73
		
74
		
75
	}
76

    
77
//********************** TESTS *****************************	
78
	
79
	@Test
80
	public void testNewInstance(){
81
		Assert.assertNotNull("ReferenceSystem must not be null", referenceSystem);
82
		Assert.assertNotNull("Point1 must not be null", point1);
83
		Assert.assertNotNull("Point2 must not be null", point2);
84
		Assert.assertEquals("", longitude1, point1.getLongitude());
85
		Assert.assertEquals("", latitude1, point1.getLatitude());
86
		Assert.assertEquals("", errorRadius, point1.getErrorRadius());
87
		Assert.assertEquals("", referenceSystem, point1.getReferenceSystem());
88
	}
89

    
90
	@Test
91
	public void testGetSetLongitude(){
92
		point2.setLongitude(5.888);
93
		Assert.assertEquals(Double.valueOf(5.888), point2.getLongitude());
94
		point2.setLongitude(null);
95
		Assert.assertEquals(null, point2.getLongitude());
96
	}
97

    
98
	@Test
99
	public void testGetSetLatitude(){
100
		point2.setLatitude(-34.987);
101
		Assert.assertEquals(Double.valueOf(-34.987), point2.getLatitude());
102
		point2.setLatitude(null);
103
		Assert.assertEquals(null, point2.getLatitude());
104
	}
105
	
106
	@Test
107
	public void testGetSetErrorRadius(){
108
		point2.setErrorRadius(7);
109
		Assert.assertEquals(Integer.valueOf(7), point2.getErrorRadius());
110
		point2.setErrorRadius(null);
111
		Assert.assertEquals(null, point2.getErrorRadius());
112
	}
113
	
114
	@Test
115
	public void testGetSetReferenceSystem(){
116
		ReferenceSystem newRefSystem = ReferenceSystem.NewInstance();
117
		point2.setReferenceSystem(newRefSystem);
118
		Assert.assertEquals(newRefSystem, point2.getReferenceSystem());
119
		point2.setReferenceSystem(null);
120
		Assert.assertEquals(null, point2.getReferenceSystem());
121
	}
122
	
123
	@Test
124
	public void testGetLongitudeSexagesimal(){
125
		Assert.assertEquals("23?7'25\"E", point1.getLongitudeSexagesimal().toString());
126
		
127
		point2.setLongitudeSexagesimal(Sexagesimal.NewInstance(5, 22, null, Direction.WEST));
128
		Assert.assertTrue(point2.getLongitudeSexagesimal().minutes == 22);
129
		Assert.assertTrue(point2.getLongitudeSexagesimal().seconds == 0);
130
		
131
		Double latitudeDouble = -45.57389326; 
132
		point1.setLatitudeSexagesimal(Sexagesimal.valueOf(latitudeDouble, true));
133
		//Not true because of rounding errors
134
//		Assert.assertEquals("latitudeDouble must be equal", latitudeDouble, point1.getLatitude());
135
		
136
		Sexagesimal sexagesimal1 = Sexagesimal.NewInstance(0, 0, 0, Direction.WEST);
137
		Sexagesimal sexagesimal2 = Sexagesimal.NewInstance(2, 2, 2, Direction.WEST);
138
		Assert.assertNotSame("", sexagesimal1, sexagesimal2);
139
	
140
	}
141

    
142
	@Test
143
	public void testParsing(){
144
		try {
145
			Assert.assertEquals("", longitude1, point1.getLongitude());
146
			Assert.assertTrue("", latitude1.equals(point1.getLatitude()));
147
			point1.setLatitudeByParsing("35?34'20\"S");
148
			Assert.assertEquals("", longitude1, point1.getLongitude());
149
			Assert.assertFalse("", latitude1.equals(point1.getLatitude()));
150
			Assert.assertEquals("", Double.valueOf("-35.57222222222222"), point1.getLatitude());
151
		} catch (ParseException e) {
152
			Assert.fail("No parsing error should occur");
153
		}
154
		try {
155
			point1.setLongitudeByParsing("112?34.34'N");
156
			Assert.assertEquals("", "112.57233", point1.getLongitude().toString().substring(0,9));
157
		} catch (ParseException e) {
158
			Assert.fail("No parsing error should occur");
159
		}
160
		try {
161
			point1.setLatitudeByParsing("112?34.34'S");
162
			Assert.fail("Latitude can not be > 90");
163
		} catch (ParseException e) {
164
			Assert.assertTrue("Latitude can not be > 90", true);
165
		}
166
		try {
167
			point1.setLongitudeByParsing("45?34.34'S");
168
			Assert.fail("Longitude can not be S");
169
		} catch (ParseException e) {
170
			Assert.assertTrue("Longitude can not be S", true);
171
		}
172

    
173
		
174
		
175
//		Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0);
176
//		Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude);
177
//
178
//		conversionResults = coordinateConverter.tryConvert("35?34.744");
179
//		Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
180
//		Assert.assertNull("Longitude must be undefined", conversionResults.isLongitude);
181
//
182
//		conversionResults = coordinateConverter.tryConvert("95?34.744");
183
//		Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude);
184
//
185
//		
186
//		conversionResults = coordinateConverter.tryConvert("-35?34'55.67S");
187
//		Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
188
//
189
//		conversionResults = coordinateConverter.tryConvert("35?11'34.744SN");
190
//		Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
191
//
192
//		conversionResults = coordinateConverter.tryConvert("35?11'34.744SW");
193
//		Assert.assertTrue("Western must be longitude", conversionResults.isLongitude);
194
//		
195
//		conversionResults = coordinateConverter.tryConvert("35D11M34.744S");
196
//		Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude);
197

    
198
	}
199
	
200
	
201
	
202
	
203
	
204
	
205
}
(1-1/2)