source: josm/trunk/test/unit/org/openstreetmap/josm/io/ParseWithChangesetReaderTest.groovy@ 6592

Last change on this file since 6592 was 2605, checked in by Gubaer, 15 years ago

Unit tests for r2604

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