Search in sources :

Example 1 with EmptyReader

use of org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader in project osmosis by openstreetmap.

the class ChangeDeriverTest method rightEmpty.

/**
 * Deriving change with an empty right input should yield
 * a change with creates only.
 *
 * @throws Exception if something goes wrong.
 */
@Test
public void rightEmpty() throws Exception {
    // Cannot be tested with file comparison as the derived
    // change contains deletes which have a current timestamp
    // that cannot be reliably predicted.
    // Therefore, check all relevant attributes manually.
    ChangeDeriver deriver = new ChangeDeriver(1);
    RunnableSource left = new XmlReader(dataUtils.createDataFile("v0_6/derive_change/simple.osm"), true, CompressionMethod.None);
    RunnableSource right = new EmptyReader();
    SinkChangeInspector result = RunTaskUtilities.run(deriver, left, right);
    List<ChangeContainer> changes = result.getProcessedChanges();
    Assert.assertEquals(3, changes.size());
    for (ChangeContainer changeContainer : changes) {
        Assert.assertEquals(ChangeAction.Delete, changeContainer.getAction());
    }
    Entity e;
    e = changes.get(0).getEntityContainer().getEntity();
    Assert.assertEquals(EntityType.Node, e.getType());
    Assert.assertEquals(10, e.getId());
    Assert.assertEquals(34, e.getVersion());
    e = changes.get(1).getEntityContainer().getEntity();
    Assert.assertEquals(EntityType.Way, e.getType());
    Assert.assertEquals(100, e.getId());
    Assert.assertEquals(56, e.getVersion());
    e = changes.get(2).getEntityContainer().getEntity();
    Assert.assertEquals(EntityType.Relation, e.getType());
    Assert.assertEquals(1000, e.getId());
    Assert.assertEquals(78, e.getVersion());
}
Also used : SinkChangeInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkChangeInspector) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer) XmlReader(org.openstreetmap.osmosis.xml.v0_6.XmlReader) RunnableSource(org.openstreetmap.osmosis.core.task.v0_6.RunnableSource) EmptyReader(org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader) AbstractDataTest(org.openstreetmap.osmosis.testutil.AbstractDataTest) Test(org.junit.Test)

Example 2 with EmptyReader

use of org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader in project osmosis by openstreetmap.

the class EntityMergerTest method mergeAndLookForException.

/**
 * Runs a merge and records the exceptions that happened during the merge.
 *
 * The test is considered passed iff at least one exception was thrown and
 * the exception message begins with a given string.
 *
 * This method does not use command line parsing because it is impossible
 * to check whether the right exception has been thrown. Also, as all
 * exceptions are OsmosisRuntimeExceptions, we need to check the message
 * so the JUnit expected exception facility is no good here.
 *
 * To add insult to injury, running a merge task involves three worker threads;
 * the exception we expect is thrown on one of those worker threads which brings
 * the pipeline down. But we want to check for that one source exception
 * is thrown for the correct reason, otherwise the test becomes very unspecific.
 */
private void mergeAndLookForException(File sourceFile, String exceptionMessagePrefix) throws Exception {
    final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
    XmlReader reader = new XmlReader(sourceFile, false, CompressionMethod.None);
    EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
    RunTaskUtilities.run(merger, reader, new EmptyReader(), new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            exceptions.add(e);
        }
    });
    // At least one of those exceptions should be a "Pipeline not sorted" one
    boolean sortExceptionFound = false;
    for (Throwable t : exceptions) {
        if (!(t instanceof OsmosisRuntimeException)) {
            Assert.fail("Unexpected exception thrown: " + t);
        }
        sortExceptionFound |= t.getMessage().startsWith(exceptionMessagePrefix);
    }
    if (!sortExceptionFound) {
        Assert.fail("Expected exception not thrown");
    }
}
Also used : XmlReader(org.openstreetmap.osmosis.xml.v0_6.XmlReader) EmptyReader(org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 3 with EmptyReader

use of org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader in project osmosis by openstreetmap.

the class MergeBoundTest method testOneSourceEmpty.

/**
 * Tests the proper working of the merge task if exactly one source is
 * empty with respect to the declared bound.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testOneSourceEmpty() throws Exception {
    RunnableSource source0 = new EmptyReader();
    Bound bound1 = new Bound(5, 6, 8, 7, "source2");
    RunnableSource source1 = new BoundSource(bound1, true);
    EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
    SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
    List<EntityContainer> mergedList = createList(merged.getProcessedEntities());
    Assert.assertEquals(2, mergedList.size());
    Assert.assertEquals(bound1, mergedList.get(0).getEntity());
    Assert.assertEquals(EntityType.Node, mergedList.get(1).getEntity().getType());
}
Also used : Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) RunnableSource(org.openstreetmap.osmosis.core.task.v0_6.RunnableSource) EmptyReader(org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader) Test(org.junit.Test)

Example 4 with EmptyReader

use of org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader in project osmosis by openstreetmap.

the class MergeBoundTest method testBothEmpty.

/**
 * Tests the proper working of the merge task if both sources are
 * empty.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testBothEmpty() throws Exception {
    RunnableSource source0 = new EmptyReader();
    RunnableSource source1 = new EmptyReader();
    EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
    SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
    Assert.assertTrue("Expected empty result set but got some data", merged.getLastEntityContainer() == null);
}
Also used : SinkEntityInspector(org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector) RunnableSource(org.openstreetmap.osmosis.core.task.v0_6.RunnableSource) EmptyReader(org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader) Test(org.junit.Test)

Aggregations

EmptyReader (org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader)4 Test (org.junit.Test)3 RunnableSource (org.openstreetmap.osmosis.core.task.v0_6.RunnableSource)3 SinkEntityInspector (org.openstreetmap.osmosis.testutil.v0_6.SinkEntityInspector)2 XmlReader (org.openstreetmap.osmosis.xml.v0_6.XmlReader)2 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)1 ChangeContainer (org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer)1 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)1 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)1 Entity (org.openstreetmap.osmosis.core.domain.v0_6.Entity)1 AbstractDataTest (org.openstreetmap.osmosis.testutil.AbstractDataTest)1 SinkChangeInspector (org.openstreetmap.osmosis.testutil.v0_6.SinkChangeInspector)1