| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package relcontext.relationfix;
|
|---|
| 3 |
|
|---|
| 4 | import java.util.Arrays;
|
|---|
| 5 | import java.util.stream.Stream;
|
|---|
| 6 |
|
|---|
| 7 | import org.junit.jupiter.api.BeforeEach;
|
|---|
| 8 | import org.openstreetmap.josm.TestUtils;
|
|---|
| 9 | import org.openstreetmap.josm.data.osm.DataSet;
|
|---|
| 10 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 12 | import org.openstreetmap.josm.data.osm.RelationMember;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 14 | import relcontext.ChosenRelation;
|
|---|
| 15 | import relcontext.actions.SortAndFixAction;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * Test class for {@link BoundaryFixer}
|
|---|
| 19 | */
|
|---|
| 20 | class BoundaryFixerTest implements RelationFixerTest {
|
|---|
| 21 |
|
|---|
| 22 | private BoundaryFixer instance;
|
|---|
| 23 |
|
|---|
| 24 | @BeforeEach
|
|---|
| 25 | void setup() {
|
|---|
| 26 | this.instance = new BoundaryFixer();
|
|---|
| 27 | this.instance.setFixAction(new SortAndFixAction(new ChosenRelation()));
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | @Override
|
|---|
| 31 | public RelationFixer getInstance() {
|
|---|
| 32 | return instance;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | @Override
|
|---|
| 36 | public Stream<Relation> getBadRelations() {
|
|---|
| 37 | final Relation wayRelation = TestUtils.newRelation("type=boundary boundary=administrative",
|
|---|
| 38 | new RelationMember("outer_misspelled", TestUtils.newWay("", TestUtils.newNode(""), TestUtils.newNode(""))));
|
|---|
| 39 | final Relation nodeRelation = TestUtils.newRelation("type=boundary boundary=administrative",
|
|---|
| 40 | new RelationMember("admin_centre_misspelled", TestUtils.newNode("")));
|
|---|
| 41 | final Relation relationRelation = TestUtils.newRelation("type=boundary boundary=administrative",
|
|---|
| 42 | new RelationMember("subarea_misspelled", TestUtils.newRelation("")));
|
|---|
| 43 | Relation[] relations = {nodeRelation, wayRelation, relationRelation};
|
|---|
| 44 | for (Relation relation : relations) {
|
|---|
| 45 | final DataSet ds = new DataSet();
|
|---|
| 46 | ds.addPrimitiveRecursive(relation);
|
|---|
| 47 | }
|
|---|
| 48 | // Ensure that the boundary is enclosed
|
|---|
| 49 | final Node tNode = TestUtils.newNode("");
|
|---|
| 50 | wayRelation.getDataSet().addPrimitive(tNode);
|
|---|
| 51 | final Way way2 = TestUtils.newWay("", wayRelation.getMember(0).getWay().firstNode(),
|
|---|
| 52 | tNode, wayRelation.getMember(0).getWay().lastNode());
|
|---|
| 53 | wayRelation.getDataSet().addPrimitive(way2);
|
|---|
| 54 | wayRelation.addMember(new RelationMember("outer_misspelled", way2));
|
|---|
| 55 | return Arrays.stream(relations);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | @Override
|
|---|
| 59 | public Stream<Relation> getGoodRelations() {
|
|---|
| 60 | final Relation wayRelation = TestUtils.newRelation("type=boundary boundary=administrative",
|
|---|
| 61 | new RelationMember("outer", TestUtils.newWay("", TestUtils.newNode(""), TestUtils.newNode(""))));
|
|---|
| 62 | final Relation nodeRelation = TestUtils.newRelation("type=boundary boundary=administrative",
|
|---|
| 63 | new RelationMember("admin_centre", TestUtils.newNode("place=city")));
|
|---|
| 64 | final Relation relationRelation = TestUtils.newRelation("type=boundary boundary=administrative",
|
|---|
| 65 | new RelationMember("subarea", TestUtils.newRelation("")));
|
|---|
| 66 | Relation[] relations = {nodeRelation, wayRelation, relationRelation};
|
|---|
| 67 | for (Relation relation : relations) {
|
|---|
| 68 | final DataSet ds = new DataSet();
|
|---|
| 69 | ds.addPrimitiveRecursive(relation);
|
|---|
| 70 | }
|
|---|
| 71 | return Arrays.stream(relations);
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|