Search in sources :

Example 1 with PoiManager

use of io.jawg.osmcontributor.ui.managers.PoiManager in project osm-contributor by jawg.

the class PoiManagerTest method testSaveAndQuery.

@Test
public void testSaveAndQuery() {
    PoiManager poiManager = component.getPoiManager();
    Poi poi = getPoi(poiManager.savePoiType(getPoiType()), 1);
    Poi saved = poiManager.savePoi(poi);
    Poi queried = poiManager.queryForId(saved.getId());
    assertThat(queried.getName()).isEqualTo("MyPoi1");
    assertThat(queried.getLatitude()).isEqualTo(42.0);
    assertThat(queried.getLongitude()).isEqualTo(73.0);
    assertThat(queried.getUpdated()).isFalse();
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi) PoiManager(io.jawg.osmcontributor.ui.managers.PoiManager) Test(org.junit.Test)

Example 2 with PoiManager

use of io.jawg.osmcontributor.ui.managers.PoiManager in project osm-contributor by jawg.

the class PoiManagerTest method testBulkSaveAndBulkUpdate.

@Test
public void testBulkSaveAndBulkUpdate() {
    PoiManager poiManager = component.getPoiManager();
    PoiType poiType = poiManager.savePoiType(getPoiType());
    // try to save and then update 1000 pois.
    // 1000 because it can happen in real life and pose problems if we try to do an "IN" sql clause
    List<Poi> pois = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        pois.add(getPoi(poiType, i));
    }
    poiManager.savePois(pois);
    for (Poi poi : pois) {
        assertThat(poi.getId()).isNotNull();
    }
    for (Poi poi : pois) {
        Map<String, String> tags = new HashMap<>();
        tags.put("tag2", "value2");
        poi.getTags().clear();
        poi.applyChanges(tags);
    }
    List<Poi> savedPois = poiManager.savePois(pois);
    for (Poi poi : savedPois) {
        assertThat(poi.getTags()).hasSize(1);
        PoiTag tag = poi.getTags().iterator().next();
        assertThat(tag.getKey()).isEqualTo("tag2");
        assertThat(tag.getValue()).isEqualTo("value2");
    }
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) HashMap(java.util.HashMap) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiManager(io.jawg.osmcontributor.ui.managers.PoiManager) Test(org.junit.Test)

Aggregations

Poi (io.jawg.osmcontributor.model.entities.Poi)2 PoiManager (io.jawg.osmcontributor.ui.managers.PoiManager)2 Test (org.junit.Test)2 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)1 PoiType (io.jawg.osmcontributor.model.entities.PoiType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1