Revision a5d7d5a5
Added by Andreas Müller about 8 years ago
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/location/CoordinateConverterTest.java | ||
---|---|---|
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.parser.location; |
|
11 |
|
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.junit.Assert; |
|
14 |
import org.junit.Before; |
|
15 |
import org.junit.BeforeClass; |
|
16 |
import org.junit.Test; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter; |
|
19 |
import eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.ConversionResults; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author a.mueller |
|
23 |
* @date 07.06.2010 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class CoordinateConverterTest { |
|
27 |
private static final Logger logger = Logger.getLogger(CoordinateConverterTest.class); |
|
28 |
|
|
29 |
private CoordinateConverter coordinateConverter; |
|
30 |
|
|
31 |
/** |
|
32 |
* @throws java.lang.Exception |
|
33 |
*/ |
|
34 |
@BeforeClass |
|
35 |
public static void setUpBeforeClass() throws Exception { |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* @throws java.lang.Exception |
|
40 |
*/ |
|
41 |
@Before |
|
42 |
public void setUp() throws Exception { |
|
43 |
coordinateConverter = new CoordinateConverter(); |
|
44 |
} |
|
45 |
|
|
46 |
// ************************ TESTS ********************************************** / |
|
47 |
|
|
48 |
/** |
|
49 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#CoordinateConverter()}. |
|
50 |
*/ |
|
51 |
@Test |
|
52 |
public void testCoordinateConverter() { |
|
53 |
Assert.assertNotNull("converter should not be null",coordinateConverter); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#tryConvert(java.lang.String)}. |
|
58 |
*/ |
|
59 |
@Test |
|
60 |
public void testTryConvert() { |
|
61 |
ConversionResults conversionResults = coordinateConverter.tryConvert("35\u00B034'20\"S"); |
|
62 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
63 |
Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0); |
|
64 |
Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude); |
|
65 |
|
|
66 |
conversionResults = coordinateConverter.tryConvert("35\u00BA34.744"); |
|
67 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
68 |
Assert.assertNull("Longitude must be undefined", conversionResults.isLongitude); |
|
69 |
|
|
70 |
conversionResults = coordinateConverter.tryConvert("95\u00B034.744"); |
|
71 |
Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude); |
|
72 |
|
|
73 |
|
|
74 |
conversionResults = coordinateConverter.tryConvert("-35\u00B034'55.67S"); |
|
75 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
76 |
|
|
77 |
conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SN"); |
|
78 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
79 |
|
|
80 |
conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SW"); |
|
81 |
Assert.assertTrue("Western must be longitude", conversionResults.isLongitude); |
|
82 |
|
|
83 |
conversionResults = coordinateConverter.tryConvert("35\u00B0 1'34.744SW"); |
|
84 |
Assert.assertTrue("Pattern with whitespace must be recognised", conversionResults.patternRecognised); |
|
85 |
Assert.assertTrue("Pattern with whitespace must be recognised", conversionResults.conversionSuccessful); |
|
86 |
|
|
87 |
conversionResults = coordinateConverter.tryConvert("35D11M34.744S"); |
|
88 |
Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude); |
|
89 |
|
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#addCustomPattern(eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.CustomPatternIn)}. |
|
95 |
*/ |
|
96 |
@Test |
|
97 |
public void testAddCustomPattern() { |
|
98 |
logger.warn("testAddCustomPattern not yet implemented"); // TODO |
|
99 |
} |
|
100 |
|
|
101 |
} |
|
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.parser.location; |
|
11 |
|
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.junit.Assert; |
|
14 |
import org.junit.Before; |
|
15 |
import org.junit.BeforeClass; |
|
16 |
import org.junit.Test; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.ConversionResults; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author a.mueller |
|
22 |
* @date 07.06.2010 |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class CoordinateConverterTest { |
|
26 |
private static final Logger logger = Logger.getLogger(CoordinateConverterTest.class); |
|
27 |
|
|
28 |
private CoordinateConverter coordinateConverter; |
|
29 |
|
|
30 |
/** |
|
31 |
* @throws java.lang.Exception |
|
32 |
*/ |
|
33 |
@BeforeClass |
|
34 |
public static void setUpBeforeClass() throws Exception { |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* @throws java.lang.Exception |
|
39 |
*/ |
|
40 |
@Before |
|
41 |
public void setUp() throws Exception { |
|
42 |
coordinateConverter = new CoordinateConverter(); |
|
43 |
} |
|
44 |
|
|
45 |
// ************************ TESTS ********************************************** / |
|
46 |
|
|
47 |
/** |
|
48 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#CoordinateConverter()}. |
|
49 |
*/ |
|
50 |
@Test |
|
51 |
public void testCoordinateConverter() { |
|
52 |
Assert.assertNotNull("converter should not be null",coordinateConverter); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#tryConvert(java.lang.String)}. |
|
57 |
*/ |
|
58 |
@Test |
|
59 |
public void testTryConvert() { |
|
60 |
ConversionResults conversionResults = coordinateConverter.tryConvert("35\u00B034'20\"S"); |
|
61 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
62 |
Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0); |
|
63 |
Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude); |
|
64 |
|
|
65 |
conversionResults = coordinateConverter.tryConvert("35\u00BA34.744"); |
|
66 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
67 |
Assert.assertNull("Longitude must be undefined", conversionResults.isLongitude); |
|
68 |
|
|
69 |
conversionResults = coordinateConverter.tryConvert("95\u00B034.744"); |
|
70 |
Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude); |
|
71 |
|
|
72 |
|
|
73 |
conversionResults = coordinateConverter.tryConvert("-35\u00B034'55.67S"); |
|
74 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
75 |
|
|
76 |
conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SN"); |
|
77 |
Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised); |
|
78 |
|
|
79 |
conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SW"); |
|
80 |
Assert.assertTrue("Western must be longitude", conversionResults.isLongitude); |
|
81 |
|
|
82 |
conversionResults = coordinateConverter.tryConvert("35\u00B0 1'34.744SW"); |
|
83 |
Assert.assertTrue("Pattern with whitespace must be recognised", conversionResults.patternRecognised); |
|
84 |
Assert.assertTrue("Pattern with whitespace must be recognised", conversionResults.conversionSuccessful); |
|
85 |
|
|
86 |
conversionResults = coordinateConverter.tryConvert("35D11M34.744S"); |
|
87 |
Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude); |
|
88 |
|
|
89 |
conversionResults = coordinateConverter.tryConvert("35\u00B0 1´34.744SW"); |
|
90 |
Assert.assertTrue("Pattern with acute accent must be recognised", conversionResults.patternRecognised); |
|
91 |
Assert.assertTrue("Pattern with acute accent must be recognised", conversionResults.conversionSuccessful); |
|
92 |
|
|
93 |
conversionResults = coordinateConverter.tryConvert("35\u00B01\u00B434\u00B4\u00B4W"); |
|
94 |
Assert.assertTrue("Pattern with acute accent for seconds must be recognised", conversionResults.patternRecognised); |
|
95 |
Assert.assertTrue("Pattern with acute accent for seconds must be recognised", conversionResults.conversionSuccessful); |
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Test method for {@link eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter#addCustomPattern(eu.etaxonomy.cdm.strategy.parser.location.CoordinateConverter.CustomPatternIn)}. |
|
101 |
*/ |
|
102 |
@Test |
|
103 |
public void testAddCustomPattern() { |
|
104 |
logger.warn("testAddCustomPattern not yet implemented"); // TODO |
|
105 |
} |
|
106 |
|
|
107 |
} |
Also available in: Unified diff
Allow parsing of accent acute for coordinates #5716