Search in sources :

Example 16 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class MemberMergeStrategiesTest method testDiffBasedRelationBeanMergeREMOVEREMOVEConflictFail.

@Test
public void testDiffBasedRelationBeanMergeREMOVEREMOVEConflictFail() {
    final RelationBean beforeBean = new RelationBean();
    beforeBean.addItem(new RelationBeanItem(1L, "pointRole1", ItemType.POINT));
    beforeBean.addItem(new RelationBeanItem(2L, "pointRole2", ItemType.POINT));
    beforeBean.addItem(new RelationBeanItem(3L, "pointRole3", ItemType.POINT));
    beforeBean.addItem(new RelationBeanItem(1L, "lineRole1", ItemType.LINE));
    beforeBean.addItem(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    beforeBean.addItem(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    /*
         * Remove one instance of [1, AREA, areaRole1].
         */
    final RelationBean afterBean1 = new RelationBean();
    afterBean1.addItem(new RelationBeanItem(1L, "pointRole1", ItemType.POINT));
    afterBean1.addItem(new RelationBeanItem(2L, "pointRole2", ItemType.POINT));
    afterBean1.addItem(new RelationBeanItem(3L, "pointRole3", ItemType.POINT));
    afterBean1.addItem(new RelationBeanItem(1L, "lineRole1", ItemType.LINE));
    afterBean1.addItem(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    /*
         * Remove both instances of [1, AREA, areaRole1].
         */
    final RelationBean afterBean2 = new RelationBean();
    afterBean2.addItem(new RelationBeanItem(1L, "pointRole1", ItemType.POINT));
    afterBean2.addItem(new RelationBeanItem(2L, "pointRole2", ItemType.POINT));
    afterBean2.addItem(new RelationBeanItem(3L, "pointRole3", ItemType.POINT));
    afterBean2.addItem(new RelationBeanItem(1L, "lineRole1", ItemType.LINE));
    afterBean2.addItemExplicitlyExcluded(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    /*
         * The merge will fail, since the number of removed [1, AREA, areaRole1] conflict.
         */
    this.expectedException.expect(FeatureChangeMergeException.class);
    this.expectedException.expectMessage("diffBasedRelationBeanMerger failed due to REMOVE/REMOVE conflict on key: [[AREA, 1, areaRole1]]: beforeValue absolute count was 2 but removedLeft/Right diff counts conflict [1 vs 2]");
    MemberMergeStrategies.diffBasedRelationBeanMerger.apply(beforeBean, afterBean1, afterBean2);
}
Also used : RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) RelationBeanItem(org.openstreetmap.atlas.geography.atlas.builder.RelationBean.RelationBeanItem) Test(org.junit.Test)

Example 17 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class MultipleChangeAtlasTest method addTurnRestrictions.

@Test
public void addTurnRestrictions() {
    resetAndChange("addTurnRestrictions", new AtlasChangeGeneratorAddTurnRestrictions());
    final Node via = this.changeAtlas.node(3985226613000000L);
    final Relation restriction = via.relations().iterator().next();
    Assert.assertNotNull(restriction);
    final RelationBean members = new RelationBean();
    members.addItem(221434099000002L, "from", ItemType.EDGE);
    members.addItem(via.getIdentifier(), "via", ItemType.NODE);
    members.addItem(634444999000000L, "to", ItemType.EDGE);
    members.addItem(-634444999000000L, "to", ItemType.EDGE);
    Assert.assertEquals(members, restriction.members().asBean());
}
Also used : Relation(org.openstreetmap.atlas.geography.atlas.items.Relation) RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) CompleteNode(org.openstreetmap.atlas.geography.atlas.complete.CompleteNode) Node(org.openstreetmap.atlas.geography.atlas.items.Node) AtlasChangeGeneratorAddTurnRestrictions(org.openstreetmap.atlas.geography.atlas.change.testing.AtlasChangeGeneratorAddTurnRestrictions) Test(org.junit.Test)

Example 18 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class FeatureChangeMergerTest method testMergeRelationsFail.

@Test
public void testMergeRelationsFail() {
    final RelationBean beforeMemberBean = new RelationBean();
    beforeMemberBean.addItem(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    beforeMemberBean.addItem(new RelationBeanItem(2L, "areaRole2", ItemType.AREA));
    beforeMemberBean.addItem(new RelationBeanItem(1L, "pointRole1", ItemType.POINT));
    final CompleteRelation beforeRelation = new CompleteRelation(123L, Maps.hashMap("a", "1", "b", "2"), Rectangle.TEST_RECTANGLE, beforeMemberBean, Arrays.asList(10L, 11L, 12L), null, 123456L, Sets.hashSet(1L, 2L, 3L));
    final RelationBean afterMemberBean1 = new RelationBean();
    afterMemberBean1.addItem(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    afterMemberBean1.addItem(new RelationBeanItem(2L, "areaRole2", ItemType.AREA));
    afterMemberBean1.addItem(new RelationBeanItem(1L, "pointRole1", ItemType.POINT));
    afterMemberBean1.addItem(new RelationBeanItem(2L, "pointRole2", ItemType.POINT));
    afterMemberBean1.addItem(new RelationBeanItem(2L, "pointRole2", ItemType.POINT));
    final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, new CompleteRelation(123L, Maps.hashMap("a", "1", "b", "2", "c", "3"), Rectangle.TEST_RECTANGLE, afterMemberBean1, Arrays.asList(10L, 11L, 12L, 13L), null, 1234567L, Sets.hashSet(1L, 2L, 3L, 4L)), beforeRelation);
    final RelationBean afterMemberBean2 = new RelationBean();
    afterMemberBean2.addItem(new RelationBeanItem(1L, "areaRole1", ItemType.AREA));
    afterMemberBean2.addItem(new RelationBeanItem(2L, "areaRole2", ItemType.AREA));
    afterMemberBean2.addItem(new RelationBeanItem(1L, "pointRole1", ItemType.POINT));
    afterMemberBean2.addItem(new RelationBeanItem(2L, "pointRole2", ItemType.POINT));
    final FeatureChange featureChange2 = new FeatureChange(ChangeType.ADD, new CompleteRelation(123L, Maps.hashMap("b", "100"), Rectangle.TEST_RECTANGLE_2, afterMemberBean2, Arrays.asList(11L, 12L), null, 1234567L, Sets.hashSet(2L, 3L)), beforeRelation);
    /*
         * This merge will fail due to an ADD/ADD conflict in the member list bean.
         */
    boolean caught = false;
    try {
        featureChange1.merge(featureChange2);
    } catch (final FeatureChangeMergeException exception) {
        caught = true;
        Assert.assertEquals(MergeFailureType.DIFF_BASED_RELATION_BEAN_ADD_ADD_CONFLICT, exception.rootLevelFailure());
        Assert.assertTrue(exception.traceMatchesExactFailureSequence(Arrays.asList(MergeFailureType.DIFF_BASED_RELATION_BEAN_ADD_ADD_CONFLICT, MergeFailureType.AFTER_VIEW_CONSISTENT_BEFORE_VIEW_MERGE_STRATEGY_FAILED, MergeFailureType.HIGHEST_LEVEL_MERGE_FAILURE)));
    }
    if (!caught) {
        Assert.fail("Did not catch expected FeatureChangeMergeException");
    }
}
Also used : RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) CompleteRelation(org.openstreetmap.atlas.geography.atlas.complete.CompleteRelation) FeatureChangeMergeException(org.openstreetmap.atlas.exception.change.FeatureChangeMergeException) RelationBeanItem(org.openstreetmap.atlas.geography.atlas.builder.RelationBean.RelationBeanItem) Test(org.junit.Test)

Example 19 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class FeatureChangeTest method testBeforeViewUsefulnessValidationRelation.

@Test
public void testBeforeViewUsefulnessValidationRelation() {
    final Rectangle bounds = Rectangle.TEST_RECTANGLE;
    final Map<String, String> tags = Maps.hashMap("a", "1", "b", "2");
    final RelationBean members = new RelationBean();
    members.addItem(new RelationBeanItem(1L, "role", ItemType.POINT));
    final List<Long> allRelationsWithSameOsmIdentifier = Arrays.asList(1L, 2L);
    final RelationBean allKnownOsmMembers = new RelationBean();
    allKnownOsmMembers.addItem(new RelationBeanItem(2L, "role2", ItemType.AREA));
    final Long osmRelationIdentifier = 456L;
    final Set<Long> relations = Sets.hashSet(1L, 2L);
    final CompleteRelation before = new CompleteRelation(123L, tags, bounds, members, allRelationsWithSameOsmIdentifier, allKnownOsmMembers, osmRelationIdentifier, relations);
    final CompleteRelation after = CompleteRelation.shallowFrom(before).withTags(tags).withMembers(members, bounds).withRelationIdentifiers(relations).withAllRelationsWithSameOsmIdentifier(allRelationsWithSameOsmIdentifier).withAllKnownOsmMembers(allKnownOsmMembers).withOsmRelationIdentifier(osmRelationIdentifier);
    this.expectedException.expect(CoreException.class);
    this.expectedException.expectMessage("is not useful");
    new FeatureChangeUsefulnessValidator(new FeatureChange(ChangeType.ADD, after, before)).validate();
}
Also used : RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) CompleteRelation(org.openstreetmap.atlas.geography.atlas.complete.CompleteRelation) Rectangle(org.openstreetmap.atlas.geography.Rectangle) RelationBeanItem(org.openstreetmap.atlas.geography.atlas.builder.RelationBean.RelationBeanItem) FeatureChangeUsefulnessValidator(org.openstreetmap.atlas.geography.atlas.validators.FeatureChangeUsefulnessValidator) Test(org.junit.Test)

Example 20 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class FeatureChangeTest method testChangeDescriptionRelationMember.

@Test
public void testChangeDescriptionRelationMember() {
    final CompleteRelation before1 = new CompleteRelation(123L, null, Rectangle.TEST_RECTANGLE, null, null, null, null, null);
    final CompleteRelation after1 = new CompleteRelation(123L, null, Rectangle.TEST_RECTANGLE, null, null, null, null, null);
    final RelationBean bean1 = new RelationBean();
    bean1.addItem(123L, "myRole", ItemType.AREA);
    bean1.addItem(456L, "myRole", ItemType.AREA);
    final RelationBean bean2 = new RelationBean();
    bean2.addItem(456L, "myRole", ItemType.AREA);
    bean2.addItem(789L, "myRole", ItemType.AREA);
    before1.withMembers(bean1, Rectangle.TEST_RECTANGLE);
    after1.withMembers(bean2, Rectangle.TEST_RECTANGLE);
    final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, after1, before1);
    final ChangeDescription description = featureChange1.explain();
    System.out.println(description);
    final String goldenString = "ChangeDescription [\n" + "UPDATE RELATION 123\n" + "RELATION_MEMBER(ADD, AREA, 789, myRole)\n" + "RELATION_MEMBER(REMOVE, AREA, 123, myRole)\n" + "]";
    Assert.assertEquals(goldenString, description.toString());
}
Also used : RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) CompleteRelation(org.openstreetmap.atlas.geography.atlas.complete.CompleteRelation) ChangeDescription(org.openstreetmap.atlas.geography.atlas.change.description.ChangeDescription) Test(org.junit.Test)

Aggregations

RelationBean (org.openstreetmap.atlas.geography.atlas.builder.RelationBean)73 Test (org.junit.Test)40 PackedAtlasBuilder (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder)21 CompleteRelation (org.openstreetmap.atlas.geography.atlas.complete.CompleteRelation)20 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)17 RelationBeanItem (org.openstreetmap.atlas.geography.atlas.builder.RelationBean.RelationBeanItem)17 PolyLine (org.openstreetmap.atlas.geography.PolyLine)12 Relation (org.openstreetmap.atlas.geography.atlas.items.Relation)9 ArrayList (java.util.ArrayList)8 Location (org.openstreetmap.atlas.geography.Location)8 PackedAtlas (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas)8 Polygon (org.openstreetmap.atlas.geography.Polygon)7 ItemType (org.openstreetmap.atlas.geography.atlas.items.ItemType)7 AtlasResourceLoader (org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader)6 FeatureChange (org.openstreetmap.atlas.geography.atlas.change.FeatureChange)6 ByteArrayResource (org.openstreetmap.atlas.streaming.resource.ByteArrayResource)6 CoreException (org.openstreetmap.atlas.exception.CoreException)5 CompleteNode (org.openstreetmap.atlas.geography.atlas.complete.CompleteNode)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4