/*
 * algorithms  Copyright (C) 2015 Ratchet Robotics
 *  Licensed under the BSD license.
 */

import org.junit.Test;
import org.ratchetrobotics.algorithms.mapping.FieldMap;

import java.io.IOException;
import java.io.StringReader;

import static org.junit.Assert.assertNotNull;


public class FieldMapTest {
    @Test
    public void itShouldNotBarfOnValidInput() throws IOException {
        String someGeoJSON = "{ \"type\": \"FeatureCollection\",\n" +
                "  \"features\": [\n" +
                "    { \"type\": \"Feature\",\n" +
                "      \"geometry\": {\"type\": \"Point\", \"coordinates\": [102.0, 0.5]},\n" +
                "      \"properties\": {\"prop0\": \"value0\"}\n" +
                "      },\n" +
                "    { \"type\": \"Feature\",\n" +
                "      \"geometry\": {\n" +
                "        \"type\": \"LineString\",\n" +
                "        \"coordinates\": [\n" +
                "          [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]\n" +
                "          ]\n" +
                "        },\n" +
                "      \"properties\": {\n" +
                "        \"prop0\": \"value0\",\n" +
                "        }\n" +
                "     }\n" +
                "     ]\n" +
                "   }";
        FieldMap aFieldMap = new FieldMap(someGeoJSON);
        assertNotNull(aFieldMap.getFeatureCollection());
    }

    @Test
    public void itShouldNotBarfOnValidReader() throws IOException {
        String someGeoJSON = "{ \"type\": \"FeatureCollection\",\n" +
                "  \"features\": [\n" +
                "    { \"type\": \"Feature\",\n" +
                "      \"geometry\": {\"type\": \"Point\", \"coordinates\": [102.0, 0.5]},\n" +
                "      \"properties\": {\"prop0\": \"value0\"}\n" +
                "      },\n" +
                "    { \"type\": \"Feature\",\n" +
                "      \"geometry\": {\n" +
                "        \"type\": \"LineString\",\n" +
                "        \"coordinates\": [\n" +
                "          [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]\n" +
                "          ]\n" +
                "        },\n" +
                "      \"properties\": {\n" +
                "        \"prop0\": \"value0\",\n" +
                "        }\n" +
                "     }\n" +
                "     ]\n" +
                "   }";
        FieldMap aFieldMap = new FieldMap(new StringReader(someGeoJSON));
        assertNotNull(aFieldMap.getFeatureCollection());
    }

}

@@ -88,16 +88,205 @@
 e.%0A */%0A%0A
+import com.vividsolutions.jts.geom.Coordinate;%0Aimport com.vividsolutions.jts.geom.Geometry;%0Aimport com.vividsolutions.jts.geom.GeometryFactory;%0Aimport org.geotools.feature.FeatureIterator;%0A
 import o
@@ -415,16 +415,61 @@
 eader;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -2795,10 +2795,1086 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void aGeoJsonPointShouldBeTranslated() throws IOException %7B%0A        FieldMap aFieldMap = new FieldMap(%22%7B%5Cn%22 +%0A                %22  %5C%22type%5C%22: %5C%22FeatureCollection%5C%22,%5Cn%22 +%0A                %22  %5C%22features%5C%22: %5B%5Cn%22 +%0A                %22    %7B%5Cn%22 +%0A                %22      %5C%22type%5C%22: %5C%22Feature%5C%22,%5Cn%22 +%0A                %22      %5C%22geometry%5C%22: %7B%5Cn%22 +%0A                %22        %5C%22type%5C%22: %5C%22Point%5C%22,%5Cn%22 +%0A                %22        %5C%22coordinates%5C%22: %5B%5Cn%22 +%0A                %22          0.5,%5Cn%22 +%0A                %22          0.5%5Cn%22 +%0A                %22        %5D%5Cn%22 +%0A                %22      %7D,%5Cn%22 +%0A                %22      %5C%22properties%5C%22: %7B%7D%5Cn%22 +%0A                %22    %7D%5Cn%22 +%0A                %22  %5D%5Cn%22 +%0A                %22%7D%5Cn%22);%0A        FeatureIterator it = aFieldMap.getFeatureCollection().features();%0A        Geometry point = (Geometry) it.next().getDefaultGeometryProperty().getValue();%0A        GeometryFactory geometryFactory = new GeometryFactory();%0A        Geometry expectedPoint = geometryFactory.createPoint(new Coordinate(0.5, 0.5));%0A        assertEquals(point, expectedPoint);%0A    %7D%0A
 %7D%0A

Test that a point in GeoJSON becomes a JTS point