-// $Id$\r
-/**\r
-* Copyright (C) 2009 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-package eu.etaxonomy.cdm.model.location;\r
-\r
-\r
-import java.text.ParseException;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.BeforeClass;\r
-import org.junit.Test;\r
-\r
-import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;\r
-import eu.etaxonomy.cdm.model.location.Point.Direction;\r
-import eu.etaxonomy.cdm.model.location.Point.Sexagesimal;\r
-\r
-/**\r
- * @author a.mueller\r
- * @date 04.06.2010\r
- *\r
- */\r
-public class PointTest {\r
- @SuppressWarnings("unused")\r
- private static final Logger logger = Logger.getLogger(PointTest.class);\r
-\r
- private Point point1;\r
- private Point point2;\r
- \r
- private Integer errorRadius;\r
- private Double longitude1;\r
- private Double latitude1;\r
- private Double longitude2;\r
- private Double latitude2;\r
- \r
- private ReferenceSystem referenceSystem;\r
- \r
- \r
- /**\r
- * @throws java.lang.Exception\r
- */\r
- @BeforeClass\r
- public static void setUpBeforeClass() throws Exception {\r
- if (ReferenceSystem.WGS84() == null){\r
- new DefaultTermInitializer().initialize();\r
- }\r
- }\r
-\r
- /**\r
- * @throws java.lang.Exception\r
- */\r
- @Before\r
- public void setUp() throws Exception {\r
- longitude1 = 23.123556;\r
- latitude1 = -13.975556;\r
- \r
- longitude2 = 28.48556;\r
- latitude2 = 12.656;\r
- \r
- errorRadius = 5;\r
- referenceSystem = ReferenceSystem.GOOGLE_EARTH();\r
- \r
- point1 = Point.NewInstance(longitude1, latitude1, referenceSystem, errorRadius);\r
- point2 = Point.NewInstance();\r
- \r
- \r
- \r
- }\r
-\r
-//********************** TESTS ***************************** \r
- \r
- @Test\r
- public void testNewInstance(){\r
- Assert.assertNotNull("ReferenceSystem must not be null", referenceSystem);\r
- Assert.assertNotNull("Point1 must not be null", point1);\r
- Assert.assertNotNull("Point2 must not be null", point2);\r
- Assert.assertEquals("", longitude1, point1.getLongitude());\r
-\r
- Assert.assertEquals("", latitude1, point1.getLatitude());\r
- Assert.assertEquals("", errorRadius, point1.getErrorRadius());\r
- Assert.assertEquals("", referenceSystem, point1.getReferenceSystem());\r
- \r
- Assert.assertNull("LongitudeSexagesimal should be null", point2.getLongitudeSexagesimal());\r
- Assert.assertNull("LatitudeSexagesimal should be null", point2.getLatitudeSexagesimal());\r
- }\r
-\r
- @Test\r
- public void testGetSetLongitude(){\r
- point2.setLongitude(5.888);\r
- Assert.assertEquals(Double.valueOf(5.888), point2.getLongitude());\r
- point2.setLongitude(null);\r
- Assert.assertEquals(null, point2.getLongitude());\r
- }\r
-\r
- @Test\r
- public void testGetSetLatitude(){\r
- point2.setLatitude(-34.987);\r
- Assert.assertEquals(Double.valueOf(-34.987), point2.getLatitude());\r
- point2.setLatitude(null);\r
- Assert.assertEquals(null, point2.getLatitude());\r
- }\r
- \r
- @Test\r
- public void testGetSetErrorRadius(){\r
- point2.setErrorRadius(7);\r
- Assert.assertEquals(Integer.valueOf(7), point2.getErrorRadius());\r
- point2.setErrorRadius(null);\r
- Assert.assertEquals(null, point2.getErrorRadius());\r
- }\r
- \r
- @Test\r
- public void testGetSetReferenceSystem(){\r
- ReferenceSystem newRefSystem = ReferenceSystem.NewInstance();\r
- point2.setReferenceSystem(newRefSystem);\r
- Assert.assertEquals(newRefSystem, point2.getReferenceSystem());\r
- point2.setReferenceSystem(null);\r
- Assert.assertEquals(null, point2.getReferenceSystem());\r
- }\r
- \r
- @Test\r
- public void testGetLongitudeSexagesimal(){\r
- Assert.assertEquals("23\u00B07'24.801\"E", point1.getLongitudeSexagesimal().toString(true, false));\r
- \r
- \r
- point2.setLongitudeSexagesimal(Sexagesimal.NewInstance(5, 22, null, Direction.WEST));\r
- Assert.assertEquals((Integer)22, point2.getLongitudeSexagesimal().minutes);\r
- Assert.assertEquals((Integer)0, point2.getLongitudeSexagesimal().seconds);\r
- \r
- Double latitudeDouble = -45.57389326; \r
- point1.setLatitudeSexagesimal(Sexagesimal.valueOf(latitudeDouble, true));\r
- //Not true because of rounding errors\r
-// Assert.assertEquals("latitudeDouble must be equal", latitudeDouble, point1.getLatitude());\r
- \r
- Sexagesimal sexagesimal1 = Sexagesimal.NewInstance(0, 0, 0, Direction.WEST);\r
- Sexagesimal sexagesimal2 = Sexagesimal.NewInstance(2, 2, 2, Direction.WEST);\r
- Assert.assertNotSame("", sexagesimal1, sexagesimal2);\r
- \r
- \r
- }\r
-\r
- @Test\r
- public void testParsing(){\r
- try {\r
- Assert.assertEquals("", longitude1, point1.getLongitude());\r
- Assert.assertTrue("", latitude1.equals(point1.getLatitude()));\r
- point1.setLatitudeByParsing("35\u00B034'20\"S");\r
- Assert.assertEquals("", longitude1, point1.getLongitude());\r
- Assert.assertFalse("", latitude1.equals(point1.getLatitude()));\r
- Assert.assertEquals("", Double.valueOf("-35.57222222222222"), point1.getLatitude());\r
- } catch (ParseException e) {\r
- Assert.fail("No parsing error should occur");\r
- }\r
- try {\r
- point1.setLongitudeByParsing("112\u00B034.34'N");\r
- Assert.assertEquals("", "112.57233", point1.getLongitude().toString().substring(0,9));\r
- } catch (ParseException e) {\r
- Assert.fail("No parsing error should occur");\r
- }\r
- try {\r
- point1.setLatitudeByParsing("112\u00B034.34'S");\r
- Assert.fail("Latitude can not be > 90");\r
- } catch (ParseException e) {\r
- Assert.assertTrue("Latitude can not be > 90", true);\r
- }\r
- try {\r
- point1.setLongitudeByParsing("45\u00B034.34'S");\r
- Assert.fail("Longitude can not be S");\r
- } catch (ParseException e) {\r
- Assert.assertTrue("Longitude can not be S", true);\r
- }\r
- //#2962 (rounding of tertiers)\r
- try {\r
- point1.setLatitudeByParsing("37\u00B07'44\"N");\r
- Assert.assertEquals("Result should be 37\u00B07'44\"N not 37\u00B07'44.999\"N", "37\u00B07'44\"N", point1.getLatitudeSexagesimal().toString());\r
- \r
- point1.setLatitudeByParsing("37\u00B07'45\"N");\r
- Assert.assertEquals("Result should be 37\u00B07'45\"N not 37\u00B07'45.\"N", "37\u00B07'45\"N", point1.getLatitudeSexagesimal().toString());\r
- \r
- } catch (ParseException e) {\r
- Assert.fail("No parsing error should occur");\r
- }\r
- \r
- \r
- \r
-\r
-\r
- \r
- \r
- \r
-// Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0);\r
-// Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude);\r
-//\r
-// conversionResults = coordinateConverter.tryConvert("35\u00B034.744");\r
-// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);\r
-// Assert.assertNull("Longitude must be undefined", conversionResults.isLongitude);\r
-//\r
-// conversionResults = coordinateConverter.tryConvert("95\u00B034.744");\r
-// Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude);\r
-//\r
-// \r
-// conversionResults = coordinateConverter.tryConvert("-35\u00B034'55.67S");\r
-// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);\r
-//\r
-// conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SN");\r
-// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);\r
-//\r
-// conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SW");\r
-// Assert.assertTrue("Western must be longitude", conversionResults.isLongitude);\r
-// \r
-// conversionResults = coordinateConverter.tryConvert("35D11M34.744S");\r
-// Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude);\r
-\r
- }\r
- \r
-\r
- @Test\r
- public void testDoubleParsing(){\r
- try {\r
- Assert.assertEquals("", longitude1, point1.getLongitude());\r
- Assert.assertTrue("", latitude1.equals(point1.getLatitude()));\r
- point1.setLatitudeByParsing("33.474");\r
- Assert.assertEquals("", longitude1, point1.getLongitude());\r
- Assert.assertFalse("", latitude1.equals(point1.getLatitude()));\r
- Assert.assertEquals("", Double.valueOf("33.474"), point1.getLatitude());\r
- point1.setLatitudeByParsing("-39,474");\r
- Assert.assertEquals("", Double.valueOf("-39.474"), point1.getLatitude());\r
- } catch (ParseException e) {\r
- Assert.fail("No parsing error should occur");\r
- }\r
- \r
- try {\r
- point1.setLongitudeByParsing("-120.4");\r
- Assert.assertEquals("", "-120.4", point1.getLongitude().toString());\r
- point1.setLongitudeByParsing("53,4");\r
- Assert.assertEquals("", "53.4", point1.getLongitude().toString());\r
- } catch (ParseException e) {\r
- Assert.fail("No parsing error should occur");\r
- }\r
- try {\r
- point1.setLatitudeByParsing("112.456");\r
- Assert.fail("Latitude can not be > 90");\r
- } catch (ParseException e) {\r
- Assert.assertTrue("Latitude can not be > 90", true);\r
- }\r
- \r
- try {\r
- point1.setLongitudeByParsing("191");\r
- Assert.fail("Longitude can be > 180°");\r
- } catch (ParseException e) {\r
- Assert.assertTrue("Longitude can not > 180°", true);\r
- }\r
- try {\r
- point1.setLatitudeByParsing("2\u00B039'38,5956\"S");\r
- } catch (ParseException e) {\r
- Assert.fail("String '2°39'38,5956\"S'should be parsable");\r
- }\r
-}\r
- \r
- /**\r
- * I don't exactly know what should happen here.\r
- * Please see http://dev.e-taxonomy.eu/trac/ticket/2267#comment:3 on why this test was created \r
- * \r
- * @throws ParseException\r
- */\r
- @Test\r
- public void testParsingHexagesimalAndDecimalMixed() throws ParseException{\r
- String example = "35\u00B034'55.67\"S";\r
- point1.setLatitudeByParsing(example);\r
- Assert.assertEquals(example, point1.getLatitudeSexagesimal().toString());\r
- }\r
- \r
- @Test\r
- public void testStaticParsing(){\r
- try{\r
- Point.parseLatitude("1");\r
- }catch (NullPointerException e){\r
- Assert.fail("No NullPointerException should occur");\r
- } catch (ParseException e) {\r
- Assert.fail("No parsing error should occur");\r
- }\r
- }\r
- \r
- \r
- \r
-}\r
+/**
+* Copyright (C) 2009 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.model.location;
+
+import java.text.ParseException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import eu.etaxonomy.cdm.model.location.Point.Direction;
+import eu.etaxonomy.cdm.model.location.Point.Sexagesimal;
+import eu.etaxonomy.cdm.test.unit.EntityTestBase;
+
+/**
+ * @author a.mueller
+ * @since 04.06.2010
+ */
+public class PointTest extends EntityTestBase {
+
+ @SuppressWarnings("unused")
+ private static final Logger logger = LogManager.getLogger();
+
+ private Point point1;
+ private Point point2;
+
+ private Integer errorRadius;
+ private Double longitude1;
+ private Double latitude1;
+ private Double longitude2;
+ private Double latitude2;
+
+ private ReferenceSystem referenceSystem;
+
+ @Before
+ public void setUp() throws Exception {
+ longitude1 = 23.123556;
+ latitude1 = -13.975556;
+
+ longitude2 = 28.48556;
+ latitude2 = 12.656;
+
+ errorRadius = 5;
+ referenceSystem = ReferenceSystem.GOOGLE_EARTH();
+
+ point1 = Point.NewInstance(longitude1, latitude1, referenceSystem, errorRadius);
+ point2 = Point.NewInstance();
+ }
+
+//********************** TESTS *****************************
+
+ @Test
+ public void testNewInstance(){
+ Assert.assertNotNull("ReferenceSystem must not be null", referenceSystem);
+ Assert.assertNotNull("Point1 must not be null", point1);
+ Assert.assertNotNull("Point2 must not be null", point2);
+ Assert.assertEquals("", longitude1, point1.getLongitude());
+
+ Assert.assertEquals("", latitude1, point1.getLatitude());
+ Assert.assertEquals("", errorRadius, point1.getErrorRadius());
+ Assert.assertEquals("", referenceSystem, point1.getReferenceSystem());
+
+ Assert.assertNull("LongitudeSexagesimal should be null", point2.getLongitudeSexagesimal());
+ Assert.assertNull("LatitudeSexagesimal should be null", point2.getLatitudeSexagesimal());
+ }
+
+ @Test
+ public void testGetSetLongitude(){
+ point2.setLongitude(5.888);
+ Assert.assertEquals(Double.valueOf(5.888), point2.getLongitude());
+ point2.setLongitude(null);
+ Assert.assertEquals(null, point2.getLongitude());
+ }
+
+ @Test
+ public void testGetSetLatitude(){
+ point2.setLatitude(-34.987);
+ Assert.assertEquals(Double.valueOf(-34.987), point2.getLatitude());
+ point2.setLatitude(null);
+ Assert.assertEquals(null, point2.getLatitude());
+ }
+
+ @Test
+ public void testGetSetErrorRadius(){
+ point2.setErrorRadius(7);
+ Assert.assertEquals(Integer.valueOf(7), point2.getErrorRadius());
+ point2.setErrorRadius(null);
+ Assert.assertEquals(null, point2.getErrorRadius());
+ }
+
+ @Test
+ public void testGetSetReferenceSystem(){
+ ReferenceSystem newRefSystem = ReferenceSystem.NewInstance();
+ point2.setReferenceSystem(newRefSystem);
+ Assert.assertEquals(newRefSystem, point2.getReferenceSystem());
+ point2.setReferenceSystem(null);
+ Assert.assertEquals(null, point2.getReferenceSystem());
+ }
+
+ @Test
+ public void testGetLongitudeSexagesimal(){
+ Assert.assertEquals("23\u00B07'24.801\"E", point1.getLongitudeSexagesimal().toString(true, false));
+
+
+ point2.setLongitudeSexagesimal(Sexagesimal.NewInstance(5, 22, null, Direction.WEST));
+ Assert.assertEquals((Integer)22, point2.getLongitudeSexagesimal().minutes);
+ Assert.assertEquals((Integer)0, point2.getLongitudeSexagesimal().seconds);
+
+ Double latitudeDouble = -45.57389326;
+ point1.setLatitudeSexagesimal(Sexagesimal.valueOf(latitudeDouble, true));
+ //Not true because of rounding errors
+// Assert.assertEquals("latitudeDouble must be equal", latitudeDouble, point1.getLatitude());
+
+ Sexagesimal sexagesimal1 = Sexagesimal.NewInstance(0, 0, 0, Direction.WEST);
+ Sexagesimal sexagesimal2 = Sexagesimal.NewInstance(2, 2, 2, Direction.WEST);
+ Assert.assertNotSame("", sexagesimal1, sexagesimal2);
+ }
+
+ @Test
+ public void testParsing(){
+ try {
+ Assert.assertEquals("", longitude1, point1.getLongitude());
+ Assert.assertTrue("", latitude1.equals(point1.getLatitude()));
+ point1.setLatitudeByParsing("35\u00B034'20\"S");
+ Assert.assertEquals("", longitude1, point1.getLongitude());
+ Assert.assertFalse("", latitude1.equals(point1.getLatitude()));
+ Assert.assertEquals("", Double.valueOf("-35.57222222222222"), point1.getLatitude());
+ } catch (ParseException e) {
+ Assert.fail("No parsing error should occur");
+ }
+ try {
+ point1.setLongitudeByParsing("112\u00B034.34'N");
+ Assert.assertEquals("", "112.57233", point1.getLongitude().toString().substring(0,9));
+ } catch (ParseException e) {
+ Assert.fail("No parsing error should occur");
+ }
+ try {
+ point1.setLatitudeByParsing("112\u00B034.34'S");
+ Assert.fail("Latitude can not be > 90");
+ } catch (ParseException e) {
+ Assert.assertTrue("Latitude can not be > 90", true);
+ }
+ try {
+ point1.setLongitudeByParsing("45\u00B034.34'S");
+ Assert.fail("Longitude can not be S");
+ } catch (ParseException e) {
+ Assert.assertTrue("Longitude can not be S", true);
+ }
+ //#2962 (rounding of tertiers)
+ try {
+ point1.setLatitudeByParsing("37\u00B07'44\"N");
+ Assert.assertEquals("Result should be 37\u00B07'44\"N not 37\u00B07'44.999\"N", "37\u00B07'44\"N", point1.getLatitudeSexagesimal().toString());
+
+ point1.setLatitudeByParsing("37\u00B07'45\"N");
+ Assert.assertEquals("Result should be 37\u00B07'45\"N not 37\u00B07'45.\"N", "37\u00B07'45\"N", point1.getLatitudeSexagesimal().toString());
+
+ } catch (ParseException e) {
+ Assert.fail("No parsing error should occur");
+ }
+
+
+// Assert.assertTrue("Southern must be negative", conversionResults.convertedCoord < 0);
+// Assert.assertFalse("Southern must be latitude", conversionResults.isLongitude);
+//
+// conversionResults = coordinateConverter.tryConvert("35\u00B034.744");
+// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
+// Assert.assertNull("Longitude must be undefined", conversionResults.isLongitude);
+//
+// conversionResults = coordinateConverter.tryConvert("95\u00B034.744");
+// Assert.assertTrue("Longitude must be defined", conversionResults.isLongitude);
+//
+//
+// conversionResults = coordinateConverter.tryConvert("-35\u00B034'55.67S");
+// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
+//
+// conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SN");
+// Assert.assertTrue(conversionResults.conversionComments, conversionResults.patternRecognised);
+//
+// conversionResults = coordinateConverter.tryConvert("35\u00B011'34.744SW");
+// Assert.assertTrue("Western must be longitude", conversionResults.isLongitude);
+//
+// conversionResults = coordinateConverter.tryConvert("35D11M34.744S");
+// Assert.assertNull("isLongitude must be undefined. S stands for second.", conversionResults.isLongitude);
+
+ }
+
+
+ @Test
+ public void testDoubleParsing(){
+ try {
+ Assert.assertEquals("", longitude1, point1.getLongitude());
+ Assert.assertTrue("", latitude1.equals(point1.getLatitude()));
+ point1.setLatitudeByParsing("33.474");
+ Assert.assertEquals("", longitude1, point1.getLongitude());
+ Assert.assertFalse("", latitude1.equals(point1.getLatitude()));
+ Assert.assertEquals("", Double.valueOf("33.474"), point1.getLatitude());
+ point1.setLatitudeByParsing("-39,474");
+ Assert.assertEquals("", Double.valueOf("-39.474"), point1.getLatitude());
+ } catch (ParseException e) {
+ Assert.fail("No parsing error should occur");
+ }
+
+ try {
+ point1.setLongitudeByParsing("-120.4");
+ Assert.assertEquals("", "-120.4", point1.getLongitude().toString());
+ point1.setLongitudeByParsing("53,4");
+ Assert.assertEquals("", "53.4", point1.getLongitude().toString());
+ } catch (ParseException e) {
+ Assert.fail("No parsing error should occur");
+ }
+ try {
+ point1.setLatitudeByParsing("112.456");
+ Assert.fail("Latitude can not be > 90");
+ } catch (ParseException e) {
+ Assert.assertTrue("Latitude can not be > 90", true);
+ }
+
+ try {
+ point1.setLongitudeByParsing("191");
+ Assert.fail("Longitude can be > 180°");
+ } catch (ParseException e) {
+ Assert.assertTrue("Longitude can not > 180°", true);
+ }
+ try {
+ point1.setLatitudeByParsing("2\u00B039'38,5956\"S");
+ } catch (ParseException e) {
+ Assert.fail("String '2°39'38,5956\"S'should be parsable");
+ }
+}
+
+ /**
+ * I don't exactly know what should happen here.
+ * Please see https://dev.e-taxonomy.eu/redmine/issues/2267#comment:3 on why this test was created
+ *
+ * @throws ParseException
+ */
+ @Test
+ public void testParsingHexagesimalAndDecimalMixed() throws ParseException{
+ String example = "35\u00B034'55.67\"S";
+ point1.setLatitudeByParsing(example);
+ Assert.assertEquals(example, point1.getLatitudeSexagesimal().toString());
+ }
+
+ @Test
+ public void testStaticParsing(){
+ try{
+ Point.parseLatitude("1");
+ }catch (NullPointerException e){
+ Assert.fail("No NullPointerException should occur");
+ } catch (ParseException e) {
+ Assert.fail("No parsing error should occur");
+ }
+ }
+}
\ No newline at end of file