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);
}
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());
}
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");
}
}
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();
}
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());
}
Aggregations