Changeset 32506 in osm for applications
- Timestamp:
- 2016-07-01T23:58:52+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/ImportUtils.java
r32297 r32506 19 19 20 20 public class ImportUtils { 21 22 23 24 21 22 private ImportUtils() { 23 // private constructor for utils classes 24 } 25 25 26 26 public static DataSet importOsmFile(File file, String layerName) { 27 27 28 29 28 OsmImporter importer = new OsmImporter(); 29 ProgressMonitor progressMonitor = NullProgressMonitor.INSTANCE; 30 30 31 32 33 34 35 31 try { 32 InputStream in = new FileInputStream(file); 33 OsmImporterData oid = importer.loadLayer(in, file, layerName, progressMonitor); 34 OsmDataLayer layer = oid.getLayer(); 35 return layer.data; 36 36 37 38 39 40 41 42 43 44 45 37 } catch (FileNotFoundException e) { 38 // TODO Auto-generated catch block 39 e.printStackTrace(); 40 } catch (IllegalDataException e) { 41 // TODO Auto-generated catch block 42 e.printStackTrace(); 43 } 44 45 return null; 46 46 47 47 } 48 48 49 49 -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/data/RouteRepresentationTest.java
r32304 r32506 21 21 */ 22 22 public class RouteRepresentationTest extends AbstractTest { 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 PTRouteDataManager manager =new PTRouteDataManager(route);167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 23 24 @Test 25 public void correctRouteTest() { 26 27 /*- 28 * Create a [correct] route which has: 29 * stop1 (stop_position) 30 * way1 (Way) 31 * stop2(platform, Way) 32 * way2 (Way) 33 * stop3 (stop_area) 34 * way3 (Relation that consists of Ways only) 35 * stop4 (stop_position) 36 * stop4 (platform, Node) 37 * way4 (Way) 38 * stop5 (platform_exit_only, Relation) 39 * 40 */ 41 42 ArrayList<RelationMember> members = new ArrayList<>(); 43 44 // Create stops: 45 Node n1 = new Node(); 46 n1.put("name", "Stop1"); 47 RelationMember rm1 = new RelationMember("stop", n1); 48 members.add(rm1); 49 Way w1 = new Way(); 50 w1.put("name", "Stop2"); 51 w1.put("highway", "platform"); 52 RelationMember rm2 = new RelationMember("platform", w1); 53 members.add(rm2); 54 Relation r1 = new Relation(); 55 r1.put("name", "Stop3"); 56 RelationMember rm3 = new RelationMember("stop_area", r1); 57 members.add(rm3); 58 Node n2 = new Node(); 59 n2.put("name", "Stop4"); 60 RelationMember rm4 = new RelationMember("stop", n2); 61 members.add(rm4); 62 Node n3 = new Node(); 63 n3.put("name", "Stop4"); 64 RelationMember rm5 = new RelationMember("platform", n3); 65 members.add(rm5); 66 Relation r2 = new Relation(); 67 r2.put("name", "Stop5"); 68 r2.put("highway", "platform_exit_only"); 69 RelationMember rm6 = new RelationMember("platform_exit_only", r2); 70 members.add(rm6); 71 72 // Create ways: 73 Way w2 = new Way(); 74 RelationMember rm7 = new RelationMember("", w2); 75 members.add(rm7); 76 Way w3 = new Way(); 77 RelationMember rm8 = new RelationMember("", w3); 78 members.add(rm8); 79 Relation r3 = new Relation(); // nested relation 80 Way w4 = new Way(); 81 Way w5 = new Way(); 82 Way w6 = new Way(); 83 r3.addMember(new RelationMember("", w4)); 84 r3.addMember(new RelationMember("", w5)); 85 r3.addMember(new RelationMember("", w6)); 86 RelationMember rm9 = new RelationMember("", r3); 87 members.add(rm9); 88 Way w7 = new Way(); 89 RelationMember rm10 = new RelationMember("", w7); 90 members.add(rm10); 91 92 93 94 Relation route = new Relation(); 95 route.setMembers(members); 96 97 PTRouteDataManager manager = new PTRouteDataManager(route); 98 99 assertEquals(manager.getPTStopCount(), 5); 100 assertEquals(manager.getPTWayCount(), 4); 101 102 } 103 104 @Test 105 public void nestedRelationTest() { 106 107 // Same as above, but the nested Relation has a Node (only ways are allowed) 108 109 ArrayList<RelationMember> members = new ArrayList<>(); 110 111 // Create stops: 112 Node n1 = new Node(); 113 n1.put("name", "Stop1"); 114 RelationMember rm1 = new RelationMember("stop", n1); 115 members.add(rm1); 116 Way w1 = new Way(); 117 w1.put("name", "Stop2"); 118 w1.put("highway", "platform"); 119 RelationMember rm2 = new RelationMember("platform", w1); 120 members.add(rm2); 121 Relation r1 = new Relation(); 122 r1.put("name", "Stop3"); 123 RelationMember rm3 = new RelationMember("stop_area", r1); 124 members.add(rm3); 125 Node n2 = new Node(); 126 n2.put("name", "Stop4"); 127 RelationMember rm4 = new RelationMember("stop", n2); 128 members.add(rm4); 129 Node n3 = new Node(); 130 n3.put("name", "Stop4"); 131 RelationMember rm5 = new RelationMember("platform", n3); 132 members.add(rm5); 133 Relation r2 = new Relation(); 134 r2.put("name", "Stop5"); 135 r2.put("highway", "platform_exit_only"); 136 RelationMember rm6 = new RelationMember("platform_exit_only", r2); 137 members.add(rm6); 138 139 // Create ways: 140 Way w2 = new Way(); 141 RelationMember rm7 = new RelationMember("", w2); 142 members.add(rm7); 143 Way w3 = new Way(); 144 RelationMember rm8 = new RelationMember("", w3); 145 members.add(rm8); 146 Relation r3 = new Relation(); // nested relation 147 Way w4 = new Way(); 148 Node wrongNode = new Node(); // CHANGED COMPARED TO PREVIOUS TEST 149 Way w6 = new Way(); 150 r3.addMember(new RelationMember("", w4)); 151 r3.addMember(new RelationMember("platform", wrongNode)); 152 r3.addMember(new RelationMember("", w6)); 153 RelationMember rm9 = new RelationMember("", r3); 154 members.add(rm9); 155 Way w7 = new Way(); 156 RelationMember rm10 = new RelationMember("", w7); 157 members.add(rm10); 158 159 160 Relation route = new Relation(); 161 route.setMembers(members); 162 163 boolean thrown = false; 164 String message = ""; 165 try { 166 /*PTRouteDataManager manager =*/ new PTRouteDataManager(route); 167 } catch(IllegalArgumentException e) { 168 thrown = true; 169 message = e.getMessage(); 170 } 171 172 assertTrue(thrown); 173 assertEquals(message, "A route relation member of OsmPrimitiveType.RELATION can only have ways as members"); 174 175 } 176 177 178 @Test 179 public void multipleStopElementTest() { 180 181 // Same as correctRouteTest(), but 182 183 ArrayList<RelationMember> members = new ArrayList<>(); 184 185 // Create stops: 186 Node n1 = new Node(); 187 n1.put("name", "Stop1"); 188 RelationMember rm1 = new RelationMember("stop", n1); 189 members.add(rm1); 190 Way w1 = new Way(); 191 w1.put("name", "Stop2"); 192 w1.put("highway", "platform"); 193 RelationMember rm2 = new RelationMember("platform", w1); 194 members.add(rm2); 195 Relation r1 = new Relation(); 196 r1.put("name", "Stop3"); 197 RelationMember rm3 = new RelationMember("stop_area", r1); 198 members.add(rm3); 199 Node n2 = new Node(); 200 n2.put("name", "Stop4"); 201 RelationMember rm4 = new RelationMember("stop", n2); 202 members.add(rm4); 203 Node n3 = new Node(); 204 n3.put("name", "Stop4"); 205 RelationMember rm5 = new RelationMember("platform", n3); 206 members.add(rm5); 207 Relation r2 = new Relation(); 208 r2.put("name", "Stop5"); 209 r2.put("highway", "platform_exit_only"); 210 RelationMember rm6 = new RelationMember("platform_exit_only", r2); 211 members.add(rm6); 212 213 // Create ways: 214 Way w2 = new Way(); 215 RelationMember rm7 = new RelationMember("", w2); 216 members.add(rm7); 217 Way w3 = new Way(); 218 RelationMember rm8 = new RelationMember("", w3); 219 members.add(rm8); 220 Relation r3 = new Relation(); // nested relation 221 Way w4 = new Way(); 222 Way w5 = new Way(); 223 Way w6 = new Way(); 224 r3.addMember(new RelationMember("", w4)); 225 r3.addMember(new RelationMember("", w5)); 226 r3.addMember(new RelationMember("", w6)); 227 RelationMember rm9 = new RelationMember("", r3); 228 members.add(rm9); 229 Way w7 = new Way(); 230 RelationMember rm10 = new RelationMember("", w7); 231 members.add(rm10); 232 233 234 235 Relation route = new Relation(); 236 route.setMembers(members); 237 238 PTRouteDataManager manager = new PTRouteDataManager(route); 239 240 assertEquals(manager.getPTStopCount(), 5); 241 assertEquals(manager.getPTWayCount(), 4); 242 243 } 244 245 245 246 246 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/DirecionTestTest.java
r32299 r32506 16 16 17 17 public class DirecionTestTest extends AbstractTest { 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 int roundaboutErrorCaught = 0; 46 for (TestError e: errors) {47 if (e.getCode() == DirectionTest.ERROR_CODE_DIRECTION) { 48 onewayErrorCaught++; 49 50 } 51 52 assertEquals(onewayErrorCaught, 1); 53 54 // fix the direction errors: 55 56 boolean detectedErrorsAreCorrect = true; 57 for (TestError e: errors) {58 if (e.getCode() == DirectionTest.ERROR_CODE_DIRECTION) { 59 60 61 62 63 64 65 66 67 68 69 18 19 @Test 20 public void test() { 21 // this file has: 22 // Way 23 24 25 File file = new File(AbstractTest.PATH_TO_ROUNDABOUT_ONEWAY); 26 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 27 28 Relation route = null; 29 for (Relation r: ds.getRelations()) { 30 if (r.hasKey("route")) { 31 route = r; 32 } 33 } 34 35 assertEquals(route.getMembersCount(), 213); 36 37 DirectionTest directionTest = new DirectionTest(); 38 for (Relation r: ds.getRelations()) { 39 directionTest.visit(r); 40 } 41 42 List<TestError> errors = directionTest.getErrors(); 43 assertEquals(errors.size(), 1); 44 int onewayErrorCaught = 0; 45 for (TestError e: errors ) { 46 if (e.getCode() == DirectionTest.ERROR_CODE_DIRECTION) { 47 onewayErrorCaught++; 48 } 49 } 50 51 assertEquals(onewayErrorCaught, 1); 52 53 // fix the direction errors: 54 55 boolean detectedErrorsAreCorrect = true; 56 for (TestError e: errors) { 57 if (e.getCode() == DirectionTest.ERROR_CODE_DIRECTION) { 58 @SuppressWarnings("unchecked") 59 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); 60 if (highlighted.get(0).getId() != 26130630 && highlighted.get(0).getId() != 151278290) { 61 detectedErrorsAreCorrect = false; 62 } 63 } 64 } 65 66 assertTrue(detectedErrorsAreCorrect); 67 68 69 } 70 70 71 71 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/GapTestTest.java
r32299 r32506 15 15 public class GapTestTest extends AbstractTest { 16 16 17 18 19 20 17 @Test 18 public void sortingTestBeforeFile() { 19 File file = new File(AbstractTest.PATH_TO_DL131_BEFORE); 20 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 21 21 22 23 24 25 22 GapTest gapTest = new GapTest(); 23 for (Relation r : ds.getRelations()) { 24 gapTest.visit(r); 25 } 26 26 27 27 List<TestError> errors = gapTest.getErrors(); 28 28 29 30 31 32 29 assertEquals(errors.size(), 1); 30 assertEquals(errors.iterator().next().getCode(), GapTest.ERROR_CODE_SORTING); 31 assertEquals(errors.iterator().next().getTester().getClass().getName(), GapTest.class.getName()); 32 } 33 33 34 35 36 37 34 @Test 35 public void sortingTestAfterFile() { 36 File file = new File(AbstractTest.PATH_TO_DL131_AFTER); 37 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 38 38 39 40 41 42 39 GapTest gapTest = new GapTest(); 40 for (Relation r : ds.getRelations()) { 41 gapTest.visit(r); 42 } 43 43 44 44 List<TestError> errors = gapTest.getErrors(); 45 45 46 47 46 assertEquals(errors.size(), 0); 47 } 48 48 49 50 51 // 52 // 53 // 54 // 49 // TODO: this test will only pass after the functionality for recognizing 50 // and closing the gap is implemented. 51 // @Test 52 // public void overshootTestBeforeFile() { 53 // File file = new File(AbstractTest.PATH_TO_DL286_BEFORE); 54 // DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 55 55 // 56 // 57 // 58 // 59 // 56 // GapTest gapTest = new GapTest(); 57 // for (Relation r : ds.getRelations()) { 58 // gapTest.visit(r); 59 // } 60 60 // 61 // 61 // List<TestError> errors = gapTest.getErrors(); 62 62 // 63 // 64 // 63 // assertEquals(errors.size(), 1); 64 // assertEquals(errors.get(0).getCode(), GapTest.ERROR_CODE_OVERSHOOT); 65 65 // 66 // 66 // } 67 67 68 69 70 71 68 @Test 69 public void overshootTestAfterFile() { 70 File file = new File(AbstractTest.PATH_TO_DL286_AFTER); 71 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 72 72 73 74 75 76 73 GapTest gapTest = new GapTest(); 74 for (Relation r : ds.getRelations()) { 75 gapTest.visit(r); 76 } 77 77 78 78 List<TestError> errors = gapTest.getErrors(); 79 79 80 81 80 assertEquals(errors.size(), 0); 81 } 82 82 83 83 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/PlatformAsWayTest.java
r32299 r32506 14 14 15 15 public class PlatformAsWayTest extends AbstractTest{ 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 16 17 @Test 18 public void sortingTest() { 19 File file = new File(AbstractTest.PATH_TO_PLATFORM_AS_WAY); 20 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 21 22 GapTest gapTest = new GapTest(); 23 for (Relation r: ds.getRelations()) { 24 gapTest.visit(r); 25 } 26 27 List<TestError> errors = gapTest.getErrors(); 28 29 assertEquals(errors.size(), 0); 30 } 31 31 32 32 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/PlatformsFirstTestTest.java
r32299 r32506 15 15 public class PlatformsFirstTestTest extends AbstractTest { 16 16 17 18 19 20 21 22 23 24 25 17 @Test 18 public void testBeforeFile() { 19 DataSet ds = ImportUtils.importOsmFile(new File(AbstractTest.PATH_TO_DL131_BEFORE), "testLayer"); 20 21 PlatformsFirstTest pf = new PlatformsFirstTest(); 22 for (Relation r: ds.getRelations()) { 23 pf.visit(r); 24 } 25 List<TestError> errors = pf.getErrors(); 26 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 27 assertEquals(errors.size(), 1); 28 assertEquals(errors.iterator().next().getCode(), PlatformsFirstTest.ERROR_CODE); 29 assertEquals(errors.iterator().next().getTester().getClass().getName(), PlatformsFirstTest.class.getName()); 30 31 } 32 33 @Test 34 public void testAfterFile() { 35 DataSet ds = ImportUtils.importOsmFile(new File(AbstractTest.PATH_TO_DL131_AFTER), "testLayer"); 36 37 PlatformsFirstTest pf = new PlatformsFirstTest(); 38 for (Relation r: ds.getRelations()) { 39 pf.visit(r); 40 } 41 List<TestError> errors = pf.getErrors(); 42 assertEquals(errors.size(), 0); 43 44 45 } 46 46 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/RoadTypeTestTest.java
r32299 r32506 17 17 18 18 public class RoadTypeTestTest extends AbstractTest { 19 20 @Test 21 public void test() { 22 23 File file = new File(AbstractTest.PATH_TO_ROAD_TYPE_ERROR); 24 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 26 RoadTypeTest roadTypeTest = new RoadTypeTest(); 27 for (Relation r: ds.getRelations()) { 28 roadTypeTest.visit(r); 29 } 30 31 List<TestError> errors = roadTypeTest.getErrors(); 32 assertEquals(errors.size(), 2); 33 34 for (TestError e: errors) { 35 assertEquals(e.getCode(), RoadTypeTest.ERROR_CODE_ROAD_TYPE); 36 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); 37 Way way = (Way) highlighted.get(0); 38 assertTrue(way.getId() == 8169083 || way.getId() == 8034569); 39 } 40 } 19 20 @Test 21 public void test() { 22 23 File file = new File(AbstractTest.PATH_TO_ROAD_TYPE_ERROR); 24 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 26 RoadTypeTest roadTypeTest = new RoadTypeTest(); 27 for (Relation r: ds.getRelations()) { 28 roadTypeTest.visit(r); 29 } 30 31 List<TestError> errors = roadTypeTest.getErrors(); 32 assertEquals(errors.size(), 2); 33 34 for (TestError e: errors) { 35 assertEquals(e.getCode(), RoadTypeTest.ERROR_CODE_ROAD_TYPE); 36 @SuppressWarnings("unchecked") 37 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); 38 Way way = (Way) highlighted.get(0); 39 assertTrue(way.getId() == 8169083 || way.getId() == 8034569); 40 } 41 } 41 42 42 43
Note:
See TracChangeset
for help on using the changeset viewer.