Changeset 7081 in josm for trunk/test/unit/org/openstreetmap/josm/io
- Timestamp:
- 2014-05-09T04:49:54+02:00 (12 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/io
- Files:
-
- 5 edited
-
DiffResultProcessorTest.groovy (modified) (14 diffs)
-
OsmChangeBuilderTest.groovy (modified) (11 diffs)
-
ParseWithChangesetReaderTest.groovy (modified) (13 diffs)
-
remotecontrol/RemoteControlTest.java (modified) (9 diffs)
-
session/SessionWriterTest.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/DiffResultProcessorTest.groovy
r2605 r7081 2 2 package org.openstreetmap.josm.io; 3 3 4 import static org.junit.Assert.* 4 5 5 import org.junit.Test 6 import org.openstreetmap.josm.data.osm.Node; 7 import org.openstreetmap.josm.data.osm.Way; 8 import org.openstreetmap.josm.data.osm.Relation; 9 import org.openstreetmap.josm.data.osm.Changeset; 6 import org.junit.Test 10 7 import org.openstreetmap.josm.data.coor.LatLon 11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 13 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 14 15 import static org.junit.Assert.*; 8 import org.openstreetmap.josm.data.osm.Changeset 9 import org.openstreetmap.josm.data.osm.Node 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType 11 import org.openstreetmap.josm.data.osm.Relation 12 import org.openstreetmap.josm.data.osm.SimplePrimitiveId 13 import org.openstreetmap.josm.data.osm.Way 14 import org.openstreetmap.josm.gui.progress.NullProgressMonitor 15 import org.openstreetmap.josm.tools.XmlParsingException 16 16 17 17 class DiffResultProcessorTest { 18 19 18 19 20 20 @Test 21 21 public void testConstructor() { 22 22 Node n = new Node(1) 23 // these calls should not fail 23 // these calls should not fail 24 24 // 25 25 def DiffResultProcessor processor = new DiffResultProcessor(null) … … 27 27 processor = new DiffResultProcessor([n]) 28 28 } 29 29 30 30 @Test 31 31 public void testParse_NOK_Cases() { 32 32 def DiffResultProcessor processor = new DiffResultProcessor([]) 33 33 34 34 final shouldFail = new GroovyTestCase().&shouldFail 35 35 36 36 shouldFail(IllegalArgumentException) { 37 37 processor.parse null, NullProgressMonitor.INSTANCE 38 38 } 39 40 shouldFail( OsmDataParsingException) {39 40 shouldFail(XmlParsingException) { 41 41 processor.parse "", NullProgressMonitor.INSTANCE 42 42 } 43 44 shouldFail( OsmDataParsingException) {43 44 shouldFail(XmlParsingException) { 45 45 processor.parse "<x></x>", NullProgressMonitor.INSTANCE 46 } 46 } 47 47 } 48 49 @Test 48 49 @Test 50 50 public void testParse_OK_Cases() { 51 51 def DiffResultProcessor processor = new DiffResultProcessor([]) … … 57 57 </diffResult> 58 58 """ 59 59 60 60 processor.parse doc, null 61 61 assert processor.@diffResults.size() == 3 … … 65 65 assert entry.new_id == 1 66 66 assert entry.new_version == 1 67 67 68 68 id = new SimplePrimitiveId(-2, OsmPrimitiveType.WAY) 69 69 entry = processor.@diffResults[id] … … 71 71 assert entry.new_id == 2 72 72 assert entry.new_version == 1 73 73 74 74 id = new SimplePrimitiveId(-3, OsmPrimitiveType.RELATION) 75 75 entry = processor.@diffResults[id] 76 76 assert entry != null 77 77 assert entry.new_id == 3 78 assert entry.new_version == 1 78 assert entry.new_version == 1 79 79 } 80 80 81 81 @Test 82 82 public void testPostProcess_Invocation_Variants() { … … 89 89 </diffResult> 90 90 """ 91 91 92 92 processor.parse doc, null 93 93 94 94 // should all be ok 95 95 // … … 99 99 processor.postProcess new Changeset(1), NullProgressMonitor.INSTANCE 100 100 } 101 101 102 102 @Test 103 103 public void testPostProcess_OK() { 104 104 105 105 Node n = new Node() 106 106 Way w = new Way() 107 107 Relation r = new Relation() 108 108 109 109 String doc = """\ 110 110 <diffResult version="0.6" generator="Test Data"> … … 114 114 </diffResult> 115 115 """ 116 116 117 117 def DiffResultProcessor processor = new DiffResultProcessor([n,w,r]) 118 118 processor.parse doc, null … … 122 122 assert n.changesetId == 5 123 123 assert n.version == 10 124 124 125 125 w = processed.find {it.uniqueId == 2} 126 126 assert w.changesetId == 5 127 127 assert w.version == 11 128 128 129 129 r = processed.find {it.uniqueId == 3} 130 130 assert r.changesetId == 5 131 assert r.version == 12 131 assert r.version == 12 132 132 } 133 133 134 134 @Test 135 135 public void testPostProcess_ForCreatedElement() { 136 137 Node n = new Node() 136 137 Node n = new Node() 138 138 String doc = """\ 139 139 <diffResult version="0.6" generator="Test Data"> … … 141 141 </diffResult> 142 142 """ 143 143 144 144 def DiffResultProcessor processor = new DiffResultProcessor([n]) 145 145 processor.parse doc, null … … 150 150 assert n.version == 1 151 151 } 152 152 153 153 @Test 154 154 public void testPostProcess_ForModifiedElement() { 155 155 156 156 Node n = new Node(1) 157 157 n.coor = new LatLon(1,1) … … 163 163 </diffResult> 164 164 """ 165 165 166 166 def DiffResultProcessor processor = new DiffResultProcessor([n]) 167 167 processor.parse doc, null … … 172 172 assert n.version == 3 173 173 } 174 174 175 175 @Test 176 176 public void testPostProcess_ForDeletedElement() { 177 177 178 178 Node n = new Node(1) 179 179 n.coor = new LatLon(1,1) … … 185 185 </diffResult> 186 186 """ 187 187 188 188 def DiffResultProcessor processor = new DiffResultProcessor([n]) 189 189 processor.parse doc, null -
trunk/test/unit/org/openstreetmap/josm/io/OsmChangeBuilderTest.groovy
r2690 r7081 1 1 package org.openstreetmap.josm.io; 2 2 3 import org.junit.Test 4 import org.openstreetmap.josm.data.coor.LatLon 5 import org.openstreetmap.josm.data.osm.Changeset 6 7 import static org.junit.Assert.*; 8 3 import static org.junit.Assert.* 4 5 import org.junit.Test 6 import org.openstreetmap.josm.data.coor.LatLon 7 import org.openstreetmap.josm.data.osm.Changeset 8 import org.openstreetmap.josm.data.osm.Node 9 9 10 class OsmChangeBuilderTest { 10 11 /** 12 * Test various constructor invocations 11 12 /** 13 * Test various constructor invocations 13 14 */ 14 15 @Test 15 16 public void testConstructor() { 16 17 def Changeset cs = new Changeset(1) 17 // should not fail 18 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 19 18 // should not fail 19 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 20 20 21 // should not fail either - null allowed 21 22 builder = new OsmChangeBuilder(null) 22 23 // should not fail 23 24 // should not fail 24 25 builder = new OsmChangeBuilder(cs, "0.5") 25 26 26 27 builder = new OsmChangeBuilder(cs, null) 27 28 builder = new OsmChangeBuilder(null, null) 29 } 30 28 29 builder = new OsmChangeBuilder(null, null) 30 } 31 31 32 /** 32 33 * Test the sequence of method calls. Should throw IllegalStateException if … … 35 36 @Test 36 37 public void testSequenceOfMethodCalls() { 37 def Changeset cs = new Changeset(1) 38 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 39 38 def Changeset cs = new Changeset(1) 39 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 40 40 41 final shouldFail = new GroovyTestCase().&shouldFail 41 42 // should be OK 42 43 // should be OK 43 44 builder.start() 44 45 Node n = new Node(new LatLon(0,0)) 45 46 builder.append n 46 47 builder.finish() 47 48 48 49 shouldFail(IllegalStateException) { 49 50 builder = new OsmChangeBuilder(cs) 50 51 builder.append n 51 52 } 52 53 53 54 shouldFail(IllegalStateException) { 54 55 builder = new OsmChangeBuilder(cs) 55 56 builder.append([n]) 56 57 } 57 58 58 59 shouldFail(IllegalStateException) { 59 60 builder = new OsmChangeBuilder(cs) 60 61 builder.finish() 61 62 } 62 63 63 64 shouldFail(IllegalStateException) { 64 65 builder = new OsmChangeBuilder(cs) 65 66 builder.start() 66 67 builder.start() 67 } 68 } 69 68 } 69 } 70 70 71 @Test 71 72 public void testDocumentWithNewNode() { 72 def Changeset cs = new Changeset(1) 73 def Changeset cs = new Changeset(1) 73 74 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 74 75 Node n = new Node(new LatLon(0,0)) 75 76 builder.start() 77 builder.append n 78 builder.finish() 79 76 77 builder.start() 78 builder.append n 79 builder.finish() 80 80 81 def doc = new XmlParser().parseText(builder.document) 81 82 assert doc.@version == "0.6" … … 85 86 def create = doc.create 86 87 assert create != null 87 88 88 89 assert create.size() == 1 89 90 def nodes = create[0].node … … 93 94 assert node.@lat != null 94 95 assert node.@lon != null 95 assert node.@changeset == cs.id.toString() 96 } 97 98 /** 99 * Test building a document with a modified node 96 assert node.@changeset == cs.id.toString() 97 } 98 99 /** 100 * Test building a document with a modified node 100 101 */ 101 102 @Test 102 103 public void testDocumentWithModifiedNode() { 103 def Changeset cs = new Changeset(1) 104 def Changeset cs = new Changeset(1) 104 105 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 105 106 Node n = new Node(1) … … 107 108 n.incomplete = false 108 109 n.modified = true 109 110 builder.start() 111 builder.append n 112 builder.finish() 113 110 111 builder.start() 112 builder.append n 113 builder.finish() 114 114 115 def doc = new XmlParser().parseText(builder.document) 115 116 assert doc.@version == "0.6" … … 119 120 def modify = doc.modify 120 121 assert modify != null 121 122 122 123 assert modify.size() == 1 123 124 def nodes = modify[0].node … … 127 128 assert node.@lat != null 128 129 assert node.@lon != null 129 assert node.@changeset == cs.id.toString() 130 } 131 132 /** 133 * Test building a document with a deleted node 130 assert node.@changeset == cs.id.toString() 131 } 132 133 /** 134 * Test building a document with a deleted node 134 135 */ 135 136 @Test 136 137 public void testDocumentWithDeletedNode() { 137 def Changeset cs = new Changeset(1) 138 def Changeset cs = new Changeset(1) 138 139 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 139 140 Node n = new Node(1) … … 141 142 n.incomplete = false 142 143 n.deleted = true 143 144 builder.start() 145 builder.append n 146 builder.finish() 147 144 145 builder.start() 146 builder.append n 147 builder.finish() 148 148 149 def doc = new XmlParser().parseText(builder.document) 149 150 assert doc.@version == "0.6" … … 153 154 def delete = doc.delete 154 155 assert delete != null 155 156 156 157 assert delete.size() == 1 157 158 def nodes = delete[0].node … … 159 160 def node = nodes[0] 160 161 assert node.@id == n.uniqueId.toString() 161 assert node.@lat != null162 assert node.@lon != null163 assert node.@changeset == cs.id.toString() 164 } 165 166 /** 167 * Test building a mixed document. 168 * 162 assert node.@lat == null 163 assert node.@lon == null 164 assert node.@changeset == cs.id.toString() 165 } 166 167 /** 168 * Test building a mixed document. 169 * 169 170 */ 170 171 @Test 171 172 public void testMixed() { 172 def Changeset cs = new Changeset(1) 173 def Changeset cs = new Changeset(1) 173 174 OsmChangeBuilder builder = new OsmChangeBuilder(cs) 174 175 Node n1 = new Node(1) … … 176 177 n1.incomplete = false 177 178 n1.deleted = true 178 179 179 180 Node n2 = new Node(new LatLon(0,0)) 180 181 181 182 Node n3 = new Node(2) 182 183 n3.coor = new LatLon(0,0) 183 184 n3.incomplete = false 184 185 n3.modified = true 185 186 186 187 builder.start() 187 188 builder.append([n1,n2,n3]) 188 189 builder.finish() 189 190 def doc = new XmlParser().parseText(builder.document) 191 190 191 def doc = new XmlParser().parseText(builder.document) 192 192 193 assert doc.children().size() == 3 193 194 assert doc.children()[0].name() == "delete" 194 195 assert doc.children()[1].name() == "create" 195 196 assert doc.children()[2].name() == "modify" 196 197 197 198 def node = doc.children()[0].node[0] 198 199 assert node.@id == n1.uniqueId.toString() 199 200 200 201 node = doc.children()[1].node[0] 201 202 assert node.@id == n2.uniqueId.toString() 202 203 203 204 node = doc.children()[2].node[0] 204 assert node.@id == n3.uniqueId.toString() 205 assert node.@id == n3.uniqueId.toString() 205 206 } 206 207 } -
trunk/test/unit/org/openstreetmap/josm/io/ParseWithChangesetReaderTest.groovy
r2605 r7081 2 2 package org.openstreetmap.josm.io; 3 3 4 import org.junit.Test 5 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 6 10 import org.openstreetmap.josm.data.osm.Node 7 11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType 8 import org.openstreetmap.josm.data.osm.DataSet9 10 import static org.junit.Assert.*;11 12 12 13 class ParseWithChangesetReaderTest { 13 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 14 22 /** 15 23 * A new node with a changeset id. Ignore it. … … 19 27 String doc = """\ 20 28 <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 == -130 assert n.changesetId == 0 31 } 32 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 33 41 /** 34 42 * A new node with an invalid changeset id. Ignore it. … … 43 51 </osm> 44 52 """ 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 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 53 60 /** 54 61 * A new node with an invalid changeset id. Ignore it. … … 63 70 </osm> 64 71 """ 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 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 73 79 /** 74 80 * A new node with an invalid changeset id. Ignore it. … … 83 89 </osm> 84 90 """ 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 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 93 98 /** 94 99 * A new node with a missing changeset id. That's fine. The changeset id … … 104 109 </osm> 105 110 """ 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 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 115 119 /** 116 120 * An existing node with a missing changeset id. That's fine. The changeset id … … 124 128 </osm> 125 129 """ 126 127 OsmReader reader = new OsmReader() 128 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null) 130 131 DataSet ds = getDataSet(doc) 129 132 Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE) 130 133 assert n != null … … 132 135 assert n.changesetId == 0 133 136 } 134 137 135 138 /** 136 139 * An existing node with a valid changeset id id. That's fine. The changeset id … … 144 147 </osm> 145 148 """ 146 147 OsmReader reader = new OsmReader() 148 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null) 149 150 DataSet ds = getDataSet(doc) 149 151 Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE) 150 152 assert n != null … … 152 154 assert n.changesetId == 4 153 155 } 154 156 155 157 /** 156 158 * An existing node with an invalid changeset id. That's a problem. An exception … … 164 166 </osm> 165 167 """ 166 168 167 169 final shouldFail = new GroovyTestCase().&shouldFail 168 169 OsmReader reader = new OsmReader() 170 170 171 shouldFail(IllegalDataException) { 171 DataSet ds =reader.parseDataSet(new StringBufferInputStream(doc), null)172 DataSet ds = getDataSet(doc) 172 173 } 173 } 174 } 174 175 /** 175 176 * An existing node with an invalid changeset id. That's a problem. An exception … … 183 184 </osm> 184 185 """ 185 186 186 187 final shouldFail = new GroovyTestCase().&shouldFail 187 188 OsmReader reader = new OsmReader() 188 189 189 shouldFail(IllegalDataException) { 190 DataSet ds =reader.parseDataSet(new StringBufferInputStream(doc), null)190 DataSet ds = getDataSet(doc) 191 191 } 192 } 192 } 193 193 /** 194 194 * An existing node with an invalid changeset id. That's a problem. An exception … … 202 202 </osm> 203 203 """ 204 204 205 205 final shouldFail = new GroovyTestCase().&shouldFail 206 207 OsmReader reader = new OsmReader() 206 208 207 shouldFail(IllegalDataException) { 209 DataSet ds =reader.parseDataSet(new StringBufferInputStream(doc), null)208 DataSet ds = getDataSet(doc) 210 209 } 211 } 210 } 212 211 } -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java
r7040 r7081 26 26 import org.junit.Before; 27 27 import org.junit.Test; 28 import org.openstreetmap.josm.JOSMFixture; 28 29 import org.openstreetmap.josm.Main; 29 30 import org.openstreetmap.josm.tools.Utils; … … 36 37 private String httpBase; 37 38 private String httpsBase; 38 39 39 40 /** 40 41 * Starts Remote control before testing requests. … … 42 43 @Before 43 44 public void setUp() { 44 Main.initApplicationPreferences();45 JOSMFixture.createUnitTestFixture().init(); 45 46 RemoteControl.start(); 46 47 disableCertificateValidation(); … … 48 49 httpsBase = "https://127.0.0.1:"+Main.pref.getInteger("remote.control.https.port", 8112); 49 50 } 50 51 51 52 /** 52 * Disable all HTTPS validation mechanisms as described 53 * Disable all HTTPS validation mechanisms as described 53 54 * <a href="http://stackoverflow.com/a/2893932/2257172">here</a> and 54 55 * <a href="http://stackoverflow.com/a/19542614/2257172">here</a> … … 56 57 public void disableCertificateValidation() { 57 58 // Create a trust manager that does not validate certificate chains 58 TrustManager[] trustAllCerts = new TrustManager[] { 59 TrustManager[] trustAllCerts = new TrustManager[] { 59 60 new X509TrustManager() { 60 61 public X509Certificate[] getAcceptedIssuers() { … … 76 77 fail(e.getMessage()); 77 78 } 78 79 79 80 // Create all-trusting host name verifier 80 81 HostnameVerifier allHostsValid = new HostnameVerifier() { … … 100 101 * Tests that sending an HTTP request without command results in HTTP 400, with all available commands in error message. 101 102 * @throws IOException if an I/O error occurs 102 * @throws MalformedURLException if HTTP URL is invalid 103 * @throws MalformedURLException if HTTP URL is invalid 103 104 */ 104 105 @Test … … 110 111 * Tests that sending an HTTPS request without command results in HTTP 400, with all available commands in error message. 111 112 * @throws IOException if an I/O error occurs 112 * @throws MalformedURLException if HTTPS URL is invalid 113 * @throws MalformedURLException if HTTPS URL is invalid 113 114 */ 114 115 @Test … … 122 123 assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST); 123 124 try (InputStream is = connection.getErrorStream()) { 124 // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes 125 // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes 125 126 StringBuilder responseBody = new StringBuilder(); 126 127 try (BufferedReader in = new BufferedReader(new InputStreamReader(is, Utils.UTF_8))) { -
trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java
r7075 r7081 11 11 import org.junit.BeforeClass; 12 12 import org.junit.Test; 13 import org.openstreetmap.josm.JOSMFixture; 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.data.gpx.GpxData; … … 74 75 @BeforeClass 75 76 public static void setUpBeforeClass() { 76 Main.initApplicationPreferences(); 77 Main.determinePlatformHook(); 77 JOSMFixture.createUnitTestFixture().init(); 78 78 ProjectionPreference.setProjection(); 79 79 Main.toolbar = new ToolbarPreferences();
Note:
See TracChangeset
for help on using the changeset viewer.
