1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.FileInputStream;
|
---|
8 |
|
---|
9 | import org.junit.BeforeClass;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.JOSMFixture;
|
---|
12 | import org.openstreetmap.josm.TestUtils;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Unit tests of {@link GeoJSONWriter} class.
|
---|
20 | */
|
---|
21 | public class GeoJSONWriterTest {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Setup test.
|
---|
25 | */
|
---|
26 | @BeforeClass
|
---|
27 | public static void setUp() {
|
---|
28 | JOSMFixture.createUnitTestFixture().init();
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Unit test
|
---|
33 | */
|
---|
34 | @Test
|
---|
35 | public void testPoint() {
|
---|
36 | final Node node = new Node(new LatLon(12.3, 4.56));
|
---|
37 | node.put("name", "foo");
|
---|
38 | node.put("source", "code");
|
---|
39 | final DataSet ds = new DataSet();
|
---|
40 | ds.addPrimitive(node);
|
---|
41 | final OsmDataLayer layer = new OsmDataLayer(ds, "foo", null);
|
---|
42 | final GeoJSONWriter writer = new GeoJSONWriter(layer);
|
---|
43 | assertEquals(("" +
|
---|
44 | "{\n" +
|
---|
45 | " 'type':'FeatureCollection',\n" +
|
---|
46 | " 'generator':'JOSM',\n" +
|
---|
47 | " 'features':[\n" +
|
---|
48 | " {\n" +
|
---|
49 | " 'type':'Feature',\n" +
|
---|
50 | " 'properties':{\n" +
|
---|
51 | " 'name':'foo',\n" +
|
---|
52 | " 'source':'code'\n" +
|
---|
53 | " },\n" +
|
---|
54 | " 'geometry':{\n" +
|
---|
55 | " 'type':'Point',\n" +
|
---|
56 | " 'coordinates':[\n" +
|
---|
57 | " 4.56000000000,\n" +
|
---|
58 | " 12.30000000000\n" +
|
---|
59 | " ]\n" +
|
---|
60 | " }\n" +
|
---|
61 | " }\n" +
|
---|
62 | " ]\n" +
|
---|
63 | "}").replace("'", "\""), writer.write().trim());
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Unit test for multipolygon
|
---|
68 | * @throws Exception if an error occurs
|
---|
69 | */
|
---|
70 | @Test
|
---|
71 | public void testMultipolygon() throws Exception {
|
---|
72 | try (FileInputStream in = new FileInputStream(TestUtils.getTestDataRoot() + "multipolygon.osm")) {
|
---|
73 | DataSet ds = OsmReader.parseDataSet(in, null);
|
---|
74 | final OsmDataLayer layer = new OsmDataLayer(ds, "foo", null);
|
---|
75 | final GeoJSONWriter writer = new GeoJSONWriter(layer);
|
---|
76 | assertTrue(writer.write().contains("MultiPolygon"));
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Unit test for exporting invalid multipolygons, see #13827
|
---|
82 | * @throws Exception if an error occurs
|
---|
83 | */
|
---|
84 | @Test
|
---|
85 | public void testMultipolygonRobustness() throws Exception {
|
---|
86 | try (FileInputStream in = new FileInputStream("data_nodist/multipolygon.osm")) {
|
---|
87 | DataSet ds = OsmReader.parseDataSet(in, null);
|
---|
88 | final OsmDataLayer layer = new OsmDataLayer(ds, "foo", null);
|
---|
89 | final GeoJSONWriter writer = new GeoJSONWriter(layer);
|
---|
90 | assertTrue(writer.write().contains("MultiPolygon"));
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|