1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.*
|
---|
5 |
|
---|
6 | import java.nio.charset.StandardCharsets
|
---|
7 |
|
---|
8 | import org.junit.Test
|
---|
9 | import org.openstreetmap.josm.data.osm.DataSet
|
---|
10 | import org.openstreetmap.josm.data.osm.Node
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType
|
---|
12 |
|
---|
13 | class ParseWithChangesetReaderTest {
|
---|
14 |
|
---|
15 | private DataSet getDataSet(String doc) {
|
---|
16 | InputStream is = new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8))
|
---|
17 | DataSet ds = new OsmReader().parseDataSet(is, null)
|
---|
18 | is.close()
|
---|
19 | return ds
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * A new node with a changeset id. Ignore it.
|
---|
24 | */
|
---|
25 | @Test
|
---|
26 | public void test_1() {
|
---|
27 | String doc = """\
|
---|
28 | <osm version="0.6">
|
---|
29 | <node id="-1" lat="0.0" lon="0.0" changeset="1">
|
---|
30 | <tag k="external-id" v="-1"/>
|
---|
31 | </node>
|
---|
32 | </osm>
|
---|
33 | """
|
---|
34 |
|
---|
35 | DataSet ds = getDataSet(doc)
|
---|
36 | Node n = ds.nodes.find {it.get("external-id") == "-1"}
|
---|
37 | assert n != null
|
---|
38 | assert n.changesetId == 0
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * A new node with an invalid changeset id. Ignore it.
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | public void test_11() {
|
---|
46 | String doc = """\
|
---|
47 | <osm version="0.6">
|
---|
48 | <node id="-1" lat="0.0" lon="0.0" changeset="0">
|
---|
49 | <tag k="external-id" v="-1"/>
|
---|
50 | </node>
|
---|
51 | </osm>
|
---|
52 | """
|
---|
53 |
|
---|
54 | DataSet ds = getDataSet(doc)
|
---|
55 | Node n = ds.nodes.find {it.get("external-id") == "-1"}
|
---|
56 | assert n != null
|
---|
57 | assert n.changesetId == 0
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * A new node with an invalid changeset id. Ignore it.
|
---|
62 | */
|
---|
63 | @Test
|
---|
64 | public void test_12() {
|
---|
65 | String doc = """\
|
---|
66 | <osm version="0.6">
|
---|
67 | <node id="-1" lat="0.0" lon="0.0" changeset="-1">
|
---|
68 | <tag k="external-id" v="-1"/>
|
---|
69 | </node>
|
---|
70 | </osm>
|
---|
71 | """
|
---|
72 |
|
---|
73 | DataSet ds = getDataSet(doc)
|
---|
74 | Node n = ds.nodes.find {it.get("external-id") == "-1"}
|
---|
75 | assert n != null
|
---|
76 | assert n.changesetId == 0
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * A new node with an invalid changeset id. Ignore it.
|
---|
81 | */
|
---|
82 | @Test
|
---|
83 | public void test_13() {
|
---|
84 | String doc = """\
|
---|
85 | <osm version="0.6">
|
---|
86 | <node id="-1" lat="0.0" lon="0.0" changeset="aaa">
|
---|
87 | <tag k="external-id" v="-1"/>
|
---|
88 | </node>
|
---|
89 | </osm>
|
---|
90 | """
|
---|
91 |
|
---|
92 | DataSet ds = getDataSet(doc)
|
---|
93 | Node n = ds.nodes.find {it.get("external-id") == "-1"}
|
---|
94 | assert n != null
|
---|
95 | assert n.changesetId == 0
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * A new node with a missing changeset id. That's fine. The changeset id
|
---|
100 | * is reset to 0.
|
---|
101 | */
|
---|
102 | @Test
|
---|
103 | public void test_14() {
|
---|
104 | String doc = """\
|
---|
105 | <osm version="0.6">
|
---|
106 | <node id="-1" lat="0.0" lon="0.0" >
|
---|
107 | <tag k="external-id" v="-1"/>
|
---|
108 | </node>
|
---|
109 | </osm>
|
---|
110 | """
|
---|
111 |
|
---|
112 | DataSet ds = getDataSet(doc)
|
---|
113 | Node n = ds.nodes.find {it.get("external-id") == "-1"}
|
---|
114 | assert n != null
|
---|
115 | assert n.changesetId == 0
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * An existing node with a missing changeset id. That's fine. The changeset id
|
---|
121 | * is reset to 0.
|
---|
122 | */
|
---|
123 | @Test
|
---|
124 | public void test_2() {
|
---|
125 | String doc = """\
|
---|
126 | <osm version="0.6">
|
---|
127 | <node id="1" lat="0.0" lon="0.0" version="1"/>
|
---|
128 | </osm>
|
---|
129 | """
|
---|
130 |
|
---|
131 | DataSet ds = getDataSet(doc)
|
---|
132 | Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE)
|
---|
133 | assert n != null
|
---|
134 | assert n.uniqueId == 1
|
---|
135 | assert n.changesetId == 0
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * An existing node with a valid changeset id id. That's fine. The changeset id
|
---|
140 | * is applied.
|
---|
141 | */
|
---|
142 | @Test
|
---|
143 | public void test_3() {
|
---|
144 | String doc = """\
|
---|
145 | <osm version="0.6">
|
---|
146 | <node id="1" lat="0.0" lon="0.0" version="1" changeset="4"/>
|
---|
147 | </osm>
|
---|
148 | """
|
---|
149 |
|
---|
150 | DataSet ds = getDataSet(doc)
|
---|
151 | Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE)
|
---|
152 | assert n != null
|
---|
153 | assert n.uniqueId == 1
|
---|
154 | assert n.changesetId == 4
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * An existing node with an invalid changeset id. That's a problem. An exception
|
---|
159 | * is thrown.
|
---|
160 | */
|
---|
161 | @Test
|
---|
162 | public void test_4() {
|
---|
163 | String doc = """\
|
---|
164 | <osm version="0.6">
|
---|
165 | <node id="1" lat="0.0" lon="0.0" version="1" changeset="-1"/>
|
---|
166 | </osm>
|
---|
167 | """
|
---|
168 |
|
---|
169 | final shouldFail = new GroovyTestCase().&shouldFail
|
---|
170 |
|
---|
171 | shouldFail(IllegalDataException) {
|
---|
172 | DataSet ds = getDataSet(doc)
|
---|
173 | }
|
---|
174 | }
|
---|
175 | /**
|
---|
176 | * An existing node with an invalid changeset id. That's a problem. An exception
|
---|
177 | * is thrown.
|
---|
178 | */
|
---|
179 | @Test
|
---|
180 | public void test_5() {
|
---|
181 | String doc = """\
|
---|
182 | <osm version="0.6">
|
---|
183 | <node id="1" lat="0.0" lon="0.0" version="1" changeset="0"/>
|
---|
184 | </osm>
|
---|
185 | """
|
---|
186 |
|
---|
187 | final shouldFail = new GroovyTestCase().&shouldFail
|
---|
188 |
|
---|
189 | shouldFail(IllegalDataException) {
|
---|
190 | DataSet ds = getDataSet(doc)
|
---|
191 | }
|
---|
192 | }
|
---|
193 | /**
|
---|
194 | * An existing node with an invalid changeset id. That's a problem. An exception
|
---|
195 | * is thrown.
|
---|
196 | */
|
---|
197 | @Test
|
---|
198 | public void test_6() {
|
---|
199 | String doc = """\
|
---|
200 | <osm version="0.6">
|
---|
201 | <node id="1" lat="0.0" lon="0.0" version="1" changeset="abc"/>
|
---|
202 | </osm>
|
---|
203 | """
|
---|
204 |
|
---|
205 | final shouldFail = new GroovyTestCase().&shouldFail
|
---|
206 |
|
---|
207 | shouldFail(IllegalDataException) {
|
---|
208 | DataSet ds = getDataSet(doc)
|
---|
209 | }
|
---|
210 | }
|
---|
211 | }
|
---|