Changeset 16611 in josm for trunk/test/unit
- Timestamp:
- 2020-06-13T06:35:37+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/MultiFetchOverpassObjectReaderTest.java
r16009 r16611 5 5 6 6 import java.util.Arrays; 7 import java.util.List; 7 8 8 9 import org.junit.Rule; 9 10 import org.junit.Test; 10 11 import org.openstreetmap.josm.data.osm.Node; 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 13 import org.openstreetmap.josm.data.osm.Relation; 12 14 import org.openstreetmap.josm.data.osm.Way; … … 31 33 */ 32 34 @Test 35 public void testBuildRequestNodesString() { 36 List<OsmPrimitive> objects = Arrays.asList(new Node(123), new Node(126), new Node(130)); 37 String requestString; 38 // nodes without parents 39 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, false); 40 assertEquals("node(id:123,126,130)->.n;(.n;);out meta;", requestString); 41 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, true); 42 assertEquals("node(id:123,126,130)->.n;(.n;);out meta;", requestString); 43 44 // nodes with parents 45 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, false); 46 assertEquals("node(id:123,126,130)->.n;.n;way(bn)->.wn;.n;rel(bn)->.rn;(.n;.wn;node(w);.rn;);out meta;", 47 requestString); 48 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, true); 49 assertEquals("node(id:123,126,130)->.n;.n;way(bn)->.wn;.n;rel(bn)->.rn;(.n;.wn;node(w);.rn;);out meta;", 50 requestString); 51 52 // simulate download referrers 53 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, false, true, false); 54 assertEquals("node(id:123,126,130)->.n;.n;way(bn)->.wn;.n;rel(bn)->.rn;(.wn;node(w);.rn;);out meta;", 55 requestString); 56 57 } 58 59 /** 60 * Test {@link MultiFetchOverpassObjectReader#buildRequestString} 61 */ 62 @Test 33 63 public void testBuildRequestWaysString() { 34 MultiFetchOverpassObjectReader reader = new MultiFetchOverpassObjectReader(); 35 reader.append(Arrays.asList(new Way(123), new Way(126), new Way(130))); 36 String requestString = reader.buildComplexRequestString(); 37 assertEquals("(way(id:123,126,130);>;);out meta;", requestString); 64 List<OsmPrimitive> objects = Arrays.asList(new Way(123), new Way(126), new Way(130)); 65 String requestString; 66 // ways without parents (always with nodes) 67 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, false); 68 assertEquals("way(id:123,126,130)->.w;(.w;>;);out meta;", requestString); 69 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, true); 70 assertEquals("way(id:123,126,130)->.w;(.w;>;);out meta;", requestString); 71 72 // ways with parents (always with nodes) 73 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, false); 74 assertEquals("way(id:123,126,130)->.w;.w;rel(bw)->.pw;(.w;>;.pw;);out meta;", requestString); 75 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, true); 76 assertEquals("way(id:123,126,130)->.w;.w;rel(bw)->.pw;(.w;>;.pw;);out meta;", requestString); 77 78 // simulate download referrers 79 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, false, true, false); 80 assertEquals("way(id:123,126,130)->.w;.w;rel(bw)->.pw;(.pw;);out meta;", requestString); 81 38 82 } 39 83 … … 43 87 @Test 44 88 public void testBuildRequestRelationsString() { 45 MultiFetchOverpassObjectReader reader = new MultiFetchOverpassObjectReader(); 46 reader.append(Arrays.asList(new Relation(123), new Relation(126), new Relation(130))); 47 reader.setRecurseDownRelations(true); 48 String requestString = reader.buildComplexRequestString(); 49 assertEquals("(relation(id:123,126,130)->.r;.r;rel(r);.r;way(r);>;.r;node(r););out meta;", requestString); 50 reader.setRecurseDownRelations(false); 51 requestString = reader.buildComplexRequestString(); 52 assertEquals("relation(id:123,126,130);out meta;", requestString); 89 List<OsmPrimitive> objects = Arrays.asList(new Relation(123), new Relation(126), new Relation(130)); 90 String requestString; 91 // objects without parents or children 92 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, false); 93 assertEquals("relation(id:123,126,130)->.r;(.r;);out meta;", requestString); 94 // objects without parents, with children 95 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, true); 96 assertEquals("relation(id:123,126,130)->.r;.r;rel(r)->.rm;(.r;.r;>;.rm;);out meta;", requestString); 97 // objects with parents, without children 98 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, false); 99 assertEquals("relation(id:123,126,130)->.r;.r;rel(br)->.pr;(.r;.pr;);out meta;", requestString); 100 // objects with parents and with children 101 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, true); 102 assertEquals("relation(id:123,126,130)->.r;.r;rel(br)->.pr;.r;rel(r)->.rm;(.r;.pr;.r;>;.rm;);out meta;", 103 requestString); 104 // simulate download referrers 105 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, false, true, false); 106 assertEquals("relation(id:123,126,130)->.r;.r;rel(br)->.pr;(.pr;);out meta;", requestString); 107 53 108 } 54 109 … … 58 113 @Test 59 114 public void testBuildComplexString() { 60 MultiFetchOverpassObjectReader reader = new MultiFetchOverpassObjectReader(); 61 reader.setRecurseDownRelations(true); 62 reader.append(Arrays.asList(new Relation(123), new Relation(126), new Relation(130), new Way(88), new Way(99), 63 new Node(1))); 64 String requestString = reader.buildComplexRequestString(); 115 List<OsmPrimitive> objects = Arrays.asList(new Relation(123), new Relation(126), new Relation(130), new Way(88), new Way(99), 116 new Node(1)); 117 // all request strings should start with the same list of objects 118 final String ids = "relation(id:123,126,130)->.r;way(id:88,99)->.w;node(1)->.n;"; 119 String requestString; 120 121 // objects without parents (ways always with nodes) 122 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, false); 123 assertEquals(ids + "(.r;.w;>;.n;);out meta;", requestString); 124 // objects without parents (ways always with nodes), recurse down one level for sub relations 125 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, false, true); 126 assertEquals(ids + ".r;rel(r)->.rm;(.r;.r;>;.rm;.w;>;.n;);out meta;", requestString); 127 128 // objects with parents 129 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, false); 65 130 assertEquals( 66 "((relation(id:123,126,130)->.r;.r;rel(r);.r;way(r);>;.r;node(r););(way(id:88,99);>;);node(1););out meta;",131 ids + ".r;rel(br)->.pr;.w;rel(bw)->.pw;.n;way(bn)->.wn;.n;rel(bn)->.rn;(.r;.pr;.w;>;.pw;.n;.wn;node(w);.rn;);out meta;", 67 132 requestString); 68 reader.setRecurseDownRelations(false); 69 requestString = reader.buildComplexRequestString(); 70 assertEquals("(relation(id:123,126,130);(way(id:88,99);>;);node(1););out meta;", requestString); 133 134 // objects with parents, recurse down one level for sub relations 135 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, true, true, true); 136 assertEquals(ids + ".r;rel(br)->.pr;.w;rel(bw)->.pw;.n;way(bn)->.wn;.n;rel(bn)->.rn;.r;rel(r)->.rm;" 137 + "(.r;.pr;.r;>;.rm;.w;>;.pw;.n;.wn;node(w);.rn;);out meta;", requestString); 138 // simulate download referrers 139 requestString = MultiFetchOverpassObjectReader.genOverpassQuery(objects, false, true, false); 140 assertEquals( 141 ids + ".r;rel(br)->.pr;.w;rel(bw)->.pw;.n;way(bn)->.wn;.n;rel(bn)->.rn;(.pr;.pw;.wn;node(w);.rn;);out meta;", 142 requestString); 71 143 } 72 73 144 }
Note:
See TracChangeset
for help on using the changeset viewer.