source: josm/trunk/test/unit/org/openstreetmap/josm/io/DiffResultProcessorTest.groovy@ 7938

Last change on this file since 7938 was 7938, checked in by bastiK, 9 years ago

add more subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assert.*
5
6import org.junit.Test
7import org.openstreetmap.josm.data.coor.LatLon
8import org.openstreetmap.josm.data.osm.Changeset
9import org.openstreetmap.josm.data.osm.Node
10import org.openstreetmap.josm.data.osm.OsmPrimitiveType
11import org.openstreetmap.josm.data.osm.Relation
12import org.openstreetmap.josm.data.osm.SimplePrimitiveId
13import org.openstreetmap.josm.data.osm.Way
14import org.openstreetmap.josm.gui.progress.NullProgressMonitor
15import org.openstreetmap.josm.tools.XmlParsingException
16
17class DiffResultProcessorTest {
18
19
20 @Test
21 public void testConstructor() {
22 Node n = new Node(1)
23 // these calls should not fail
24 //
25 def DiffResultProcessor processor = new DiffResultProcessor(null)
26 processor = new DiffResultProcessor([])
27 processor = new DiffResultProcessor([n])
28 }
29
30 @Test
31 public void testParse_NOK_Cases() {
32 def DiffResultProcessor processor = new DiffResultProcessor([])
33
34 final shouldFail = new GroovyTestCase().&shouldFail
35
36 shouldFail(IllegalArgumentException) {
37 processor.parse null, NullProgressMonitor.INSTANCE
38 }
39
40 shouldFail(XmlParsingException) {
41 processor.parse "", NullProgressMonitor.INSTANCE
42 }
43
44 shouldFail(XmlParsingException) {
45 processor.parse "<x></x>", NullProgressMonitor.INSTANCE
46 }
47 }
48
49 @Test
50 public void testParse_OK_Cases() {
51 def DiffResultProcessor processor = new DiffResultProcessor([])
52 String doc = """\
53 <diffResult version="0.6" generator="Test Data">
54 <node old_id="-1" new_id="1" new_version="1"/>
55 <way old_id="-2" new_id="2" new_version="1"/>
56 <relation old_id="-3" new_id="3" new_version="1"/>
57 </diffResult>
58 """
59
60 processor.parse doc, null
61 assert processor.@diffResults.size() == 3
62 SimplePrimitiveId id = new SimplePrimitiveId(-1, OsmPrimitiveType.NODE)
63 def entry = processor.@diffResults[id]
64 assert entry != null
65 assert entry.new_id == 1
66 assert entry.new_version == 1
67
68 id = new SimplePrimitiveId(-2, OsmPrimitiveType.WAY)
69 entry = processor.@diffResults[id]
70 assert entry != null
71 assert entry.new_id == 2
72 assert entry.new_version == 1
73
74 id = new SimplePrimitiveId(-3, OsmPrimitiveType.RELATION)
75 entry = processor.@diffResults[id]
76 assert entry != null
77 assert entry.new_id == 3
78 assert entry.new_version == 1
79 }
80
81 @Test
82 public void testPostProcess_Invocation_Variants() {
83 def DiffResultProcessor processor = new DiffResultProcessor([])
84 String doc = """\
85 <diffResult version="0.6" generator="Test Data">
86 <node old_id="-1" new_id="1" new_version="1"/>
87 <way old_id="-2" new_id="2" new_version="1"/>
88 <relation old_id="-3" new_id="3" new_version="1"/>
89 </diffResult>
90 """
91
92 processor.parse doc, null
93
94 // should all be ok
95 //
96 processor.postProcess null, null
97 processor.postProcess null, NullProgressMonitor.INSTANCE
98 processor.postProcess new Changeset(1), null
99 processor.postProcess new Changeset(1), NullProgressMonitor.INSTANCE
100 }
101
102 @Test
103 public void testPostProcess_OK() {
104
105 Node n = new Node()
106 Way w = new Way()
107 Relation r = new Relation()
108
109 String doc = """\
110 <diffResult version="0.6" generator="Test Data">
111 <node old_id="${n.uniqueId}" new_id="1" new_version="10"/>
112 <way old_id="${w.uniqueId}" new_id="2" new_version="11"/>
113 <relation old_id="${r.uniqueId}" new_id="3" new_version="12"/>
114 </diffResult>
115 """
116
117 def DiffResultProcessor processor = new DiffResultProcessor([n,w,r])
118 processor.parse doc, null
119 def processed = processor.postProcess(new Changeset(5), null)
120 assert processed.size() == 3
121 n = processed.find {it.uniqueId == 1}
122 assert n.changesetId == 5
123 assert n.version == 10
124
125 w = processed.find {it.uniqueId == 2}
126 assert w.changesetId == 5
127 assert w.version == 11
128
129 r = processed.find {it.uniqueId == 3}
130 assert r.changesetId == 5
131 assert r.version == 12
132 }
133
134 @Test
135 public void testPostProcess_ForCreatedElement() {
136
137 Node n = new Node()
138 String doc = """\
139 <diffResult version="0.6" generator="Test Data">
140 <node old_id="${n.uniqueId}" new_id="1" new_version="1"/>
141 </diffResult>
142 """
143
144 def DiffResultProcessor processor = new DiffResultProcessor([n])
145 processor.parse doc, null
146 def processed = processor.postProcess(new Changeset(5), null)
147 assert processed.size() == 1
148 n = processed.find {it.uniqueId == 1}
149 assert n.changesetId == 5
150 assert n.version == 1
151 }
152
153 @Test
154 public void testPostProcess_ForModifiedElement() {
155
156 Node n = new Node(1)
157 n.coor = new LatLon(1,1)
158 n.setOsmId 1, 2
159 n.modified = true
160 String doc = """\
161 <diffResult version="0.6" generator="Test Data">
162 <node old_id="${n.uniqueId}" new_id="${n.uniqueId}" new_version="3"/>
163 </diffResult>
164 """
165
166 def DiffResultProcessor processor = new DiffResultProcessor([n])
167 processor.parse doc, null
168 def processed = processor.postProcess(new Changeset(5), null)
169 assert processed.size() == 1
170 n = processed.find {it.uniqueId == 1}
171 assert n.changesetId == 5
172 assert n.version == 3
173 }
174
175 @Test
176 public void testPostProcess_ForDeletedElement() {
177
178 Node n = new Node(1)
179 n.coor = new LatLon(1,1)
180 n.setOsmId 1, 2
181 n.deleted = true
182 String doc = """\
183 <diffResult version="0.6" generator="Test Data">
184 <node old_id="${n.uniqueId}"/>
185 </diffResult>
186 """
187
188 def DiffResultProcessor processor = new DiffResultProcessor([n])
189 processor.parse doc, null
190 def processed = processor.postProcess(new Changeset(5), null)
191 assert processed.size() == 1
192 n = processed.find {it.uniqueId == 1}
193 assert n.changesetId == 5
194 assert n.version == 2
195 }
196}
Note: See TracBrowser for help on using the repository browser.