Index: C:/Documents and Settings/KNewman/workspace/Osmosis/test/com/bretth/osmosis/core/filter/v0_5/AreaFilterTest.java
===================================================================
--- C:/Documents and Settings/KNewman/workspace/Osmosis/test/com/bretth/osmosis/core/filter/v0_5/AreaFilterTest.java	(revision 0)
+++ C:/Documents and Settings/KNewman/workspace/Osmosis/test/com/bretth/osmosis/core/filter/v0_5/AreaFilterTest.java	(revision 0)
@@ -0,0 +1,266 @@
+package com.bretth.osmosis.core.filter.v0_5;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+import java.util.Iterator;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.bretth.osmosis.core.container.v0_5.EntityContainer;
+import com.bretth.osmosis.core.container.v0_5.NodeContainer;
+import com.bretth.osmosis.core.container.v0_5.WayContainer;
+import com.bretth.osmosis.core.domain.v0_5.Entity;
+import com.bretth.osmosis.core.domain.v0_5.Node;
+import com.bretth.osmosis.core.domain.v0_5.Way;
+import com.bretth.osmosis.core.domain.v0_5.WayNode;
+import com.bretth.osmosis.core.filter.common.IdTrackerType;
+import com.bretth.osmosis.test.task.SinkEntityInspector;
+
+public class AreaFilterTest {
+
+	private SinkEntityInspector entityInspector;
+	private AreaFilter simpleAreaFilter;
+	private AreaFilter simpleCompleteWayFilter;
+	private AreaFilter simpleCompleteRelationFilter;
+	private AreaFilter simpleCompleteWayRelationFilter;
+	private Node inAreaNode;
+	private Node outOfAreaNode;
+	private Node inAreaWayNode1;
+	private Node inAreaWayNode2;
+	private Node outOfAreaWayNode1;
+	private Node outOfAreaWayNode2;
+	private Way inAreaWay;
+	private Way outOfAreaWay;
+	private Way inOutWay;
+	private Way mangledInOutWay;
+
+
+	@Before
+	public void setUp() throws Exception {
+		entityInspector = new SinkEntityInspector();
+		// simpleAreaFilter doesn't cross antimeridian; no complete ways or relations
+		simpleAreaFilter = new BoundingBoxFilter(
+		        IdTrackerType.IdList,
+		        -20,
+		        20,
+		        20,
+		        -20,
+		        false,
+		        false);
+		// simpleCompleteWayFilter doesn't cross antimeridian; complete ways but not relations
+		simpleCompleteWayFilter = new BoundingBoxFilter(
+		        IdTrackerType.IdList,
+		        -20,
+		        20,
+		        20,
+		        -20,
+		        true,
+		        false);
+		// simpleCompleteRelationFilter doesn't cross antimeridian; complete ways but not relations
+		simpleCompleteRelationFilter = new BoundingBoxFilter(
+		        IdTrackerType.IdList,
+		        -20,
+		        20,
+		        20,
+		        -20,
+		        false,
+		        true);
+		// simpleCompleteWayRelationFilter doesn't cross antimeridian; complete ways and relations
+		simpleCompleteWayRelationFilter = new BoundingBoxFilter(
+		        IdTrackerType.IdList,
+		        -20,
+		        20,
+		        20,
+		        -20,
+		        true,
+		        true);
+		simpleAreaFilter.setSink(entityInspector);
+		simpleCompleteWayFilter.setSink(entityInspector);
+		simpleCompleteRelationFilter.setSink(entityInspector);
+		simpleCompleteWayRelationFilter.setSink(entityInspector);
+		inAreaNode = new Node(1234, new Date(), "OsmosisTest", 10, 10);
+		outOfAreaNode = new Node(1235, new Date(), "OsmosisTest", 30, 30);
+		inAreaWayNode1 = new Node(2345, new Date(), "OsmosisTest", 10, 10);
+		inAreaWayNode2 = new Node(2346, new Date(), "OsmosisTest", -10, -10);
+		outOfAreaWayNode1 = new Node(2347, new Date(), "OsmosisTest", -30, -30);
+		outOfAreaWayNode2 = new Node(2348, new Date(), "OsmosisTest", -40, -40);
+		inAreaWay = new Way(3456, new Date(), "OsmosisTest");
+		inAreaWay.addWayNode(new WayNode(inAreaWayNode1.getId()));
+		inAreaWay.addWayNode(new WayNode(inAreaWayNode2.getId()));
+		outOfAreaWay = new Way(3457, new Date(), "OsmosisTest");
+		outOfAreaWay.addWayNode(new WayNode(outOfAreaWayNode1.getId()));
+		outOfAreaWay.addWayNode(new WayNode(outOfAreaWayNode2.getId()));
+		inOutWay = new Way(3458, new Date(), "OsmosisTest");
+		inOutWay.addWayNode(new WayNode(inAreaWayNode1.getId()));
+		inOutWay.addWayNode(new WayNode(outOfAreaWayNode1.getId()));
+		inOutWay.addWayNode(new WayNode(inAreaWayNode2.getId()));
+		inOutWay.addWayNode(new WayNode(outOfAreaWayNode2.getId()));
+		mangledInOutWay = new Way(inOutWay.getId(), inOutWay.getTimestamp(), inOutWay.getUser());
+		mangledInOutWay.addWayNode(new WayNode(inAreaWayNode1.getId()));
+		mangledInOutWay.addWayNode(new WayNode(inAreaWayNode2.getId()));		
+	}
+
+
+	@After
+	public void tearDown() throws Exception {
+		simpleAreaFilter.release();
+		simpleCompleteWayFilter.release();
+		simpleCompleteRelationFilter.release();
+		simpleCompleteWayRelationFilter.release();
+	}
+
+
+	/**
+	 * Test simple passing of a node that falls within the area.
+	 */
+	@Test
+	public final void testProcessNodeContainer1() {
+		Entity compareNode;
+		
+		simpleAreaFilter.process(new NodeContainer(inAreaNode));
+		simpleAreaFilter.complete();
+		
+		compareNode = entityInspector.getLastEntityContainer().getEntity();
+		assertTrue(compareNode instanceof Node && inAreaNode.compareTo((Node)compareNode) == 0);
+	}
+
+
+	/**
+	 * Test simple non-passing of node that falls outside the area.
+	 */
+	@Test
+	public final void testProcessNodeContainer2() {
+		simpleAreaFilter.process(new NodeContainer(outOfAreaNode));
+		simpleAreaFilter.complete();
+		assertNull(entityInspector.getLastEntityContainer());
+	}
+
+
+	/**
+	 * Test passing of nodes and ways strictly inside the area with completeWays = false.
+	 */
+	@Test
+	public final void testProcessWayContainer1() {
+		Iterator<EntityContainer> ecIterator;
+		
+		simpleAreaFilter.process(new NodeContainer(inAreaWayNode1));
+		simpleAreaFilter.process(new NodeContainer(inAreaWayNode2));
+		simpleAreaFilter.process(new WayContainer(inAreaWay));
+		simpleAreaFilter.complete();
+
+		ecIterator = entityInspector.getProcessedEntities().iterator();
+		assertTrue(inAreaWayNode1.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inAreaWayNode2.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inAreaWay.compareTo((Way)ecIterator.next().getEntity()) == 0
+		        && !ecIterator.hasNext());
+	}
+
+
+	/**
+	 * Test non-passing of nodes and ways which are strictly outside the area with completeWays =
+	 * false.
+	 */
+	@Test
+	public final void testProcessWayContainer2() {
+		simpleAreaFilter.process(new NodeContainer(outOfAreaWayNode1));
+		simpleAreaFilter.process(new NodeContainer(outOfAreaWayNode2));
+		simpleAreaFilter.process(new WayContainer(outOfAreaWay));
+		simpleAreaFilter.complete();
+
+		assertNull(entityInspector.getLastEntityContainer());
+	}
+
+
+	/**
+	 * Test mangling of a way which has nodes both inside and outside the area with completeWays =
+	 * false.
+	 */
+	@Test
+	public final void testProcessWayContainer3() {
+		Iterator<EntityContainer> ecIterator;
+
+		simpleAreaFilter.process(new NodeContainer(inAreaWayNode1));
+		simpleAreaFilter.process(new NodeContainer(inAreaWayNode2));
+		simpleAreaFilter.process(new NodeContainer(outOfAreaWayNode1));
+		simpleAreaFilter.process(new NodeContainer(outOfAreaWayNode2));
+		simpleAreaFilter.process(new WayContainer(inOutWay));
+		simpleAreaFilter.complete();
+
+		ecIterator = entityInspector.getProcessedEntities().iterator();
+		assertTrue(inAreaWayNode1.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inAreaWayNode2.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && mangledInOutWay.compareTo((Way)ecIterator.next().getEntity()) == 0
+		        && !ecIterator.hasNext());
+	}
+
+
+	/**
+	 * Test passing of nodes and ways strictly inside the area with completeWays = true.
+	 */
+	@Test
+	public final void testProcessWayContainer4() {
+		Iterator<EntityContainer> ecIterator;
+		
+		simpleCompleteWayFilter.process(new NodeContainer(inAreaWayNode1));
+		simpleCompleteWayFilter.process(new NodeContainer(inAreaWayNode2));
+		simpleCompleteWayFilter.process(new WayContainer(inAreaWay));
+		simpleCompleteWayFilter.complete();
+
+		ecIterator = entityInspector.getProcessedEntities().iterator();
+		assertTrue(inAreaWayNode1.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inAreaWayNode2.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inAreaWay.compareTo((Way)ecIterator.next().getEntity()) == 0
+		        && !ecIterator.hasNext());
+	}
+
+
+	/**
+	 * Test non-passing of nodes and ways which are strictly outside the area with completeWays =
+	 * true.
+	 */
+	@Test
+	public final void testProcessWayContainer5() {
+		simpleCompleteWayFilter.process(new NodeContainer(outOfAreaWayNode1));
+		simpleCompleteWayFilter.process(new NodeContainer(outOfAreaWayNode2));
+		simpleCompleteWayFilter.process(new WayContainer(outOfAreaWay));
+		simpleCompleteWayFilter.complete();
+
+		assertNull(entityInspector.getLastEntityContainer());
+	}
+
+
+	/**
+	 * Test mangling of a way which has nodes both inside and outside the area with completeWays =
+	 * true.
+	 */
+	@Test
+	public final void testProcessWayContainer6() {
+		Iterator<EntityContainer> ecIterator;
+
+		simpleCompleteWayFilter.process(new NodeContainer(inAreaWayNode1));
+		simpleCompleteWayFilter.process(new NodeContainer(inAreaWayNode2));
+		simpleCompleteWayFilter.process(new NodeContainer(outOfAreaWayNode1));
+		simpleCompleteWayFilter.process(new NodeContainer(outOfAreaWayNode2));
+		simpleCompleteWayFilter.process(new WayContainer(inOutWay));
+		simpleCompleteWayFilter.complete();
+
+		ecIterator = entityInspector.getProcessedEntities().iterator();
+		assertTrue(inAreaWayNode1.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inAreaWayNode2.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && outOfAreaWayNode1.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && outOfAreaWayNode2.compareTo((Node)ecIterator.next().getEntity()) == 0
+		        && inOutWay.compareTo((Way)ecIterator.next().getEntity()) == 0
+		        && !ecIterator.hasNext());
+	}
+
+
+	@Test
+	public final void testProcessRelationContainer() {
+		// Should exercise this with different settings of completeRelations
+		fail("Not yet implemented"); // TODO
+	}
+
+}

Property changes on: C:\Documents and Settings\KNewman\workspace\Osmosis\test\com\bretth\osmosis\core\filter\v0_5\AreaFilterTest.java
___________________________________________________________________
Name: svn:eol-style
   + native
Name: svn:keywords Author Id Revision
   + 

Index: C:/Documents and Settings/KNewman/workspace/Osmosis/test/com/bretth/osmosis/test/task/SinkEntityInspector.java
===================================================================
--- C:/Documents and Settings/KNewman/workspace/Osmosis/test/com/bretth/osmosis/test/task/SinkEntityInspector.java	(revision 0)
+++ C:/Documents and Settings/KNewman/workspace/Osmosis/test/com/bretth/osmosis/test/task/SinkEntityInspector.java	(revision 0)
@@ -0,0 +1,87 @@
+/**
+ * 
+ */
+package com.bretth.osmosis.test.task;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import com.bretth.osmosis.core.container.v0_5.EntityContainer;
+import com.bretth.osmosis.core.task.v0_5.Sink;
+
+/**
+ * Mock object for inspecting the resulting entities after passing through a pipeline task.
+ * 
+ * @author Karl Newman
+ */
+public class SinkEntityInspector implements Sink {
+
+	private List<EntityContainer> processedEntities;
+
+
+	private void initialize() {
+		if (processedEntities == null) {
+			processedEntities = new LinkedList<EntityContainer>();
+		}
+	}
+
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.bretth.osmosis.core.task.v0_5.Sink#complete()
+	 */
+	@Override
+	public void complete() {
+		// Nothing to do here
+	}
+
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.bretth.osmosis.core.task.v0_5.Sink#process(com.bretth.osmosis.core.container.v0_5.EntityContainer)
+	 */
+	@Override
+	public void process(EntityContainer entityContainer) {
+		initialize();
+		processedEntities.add(entityContainer);
+	}
+
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see com.bretth.osmosis.core.task.v0_5.Sink#release()
+	 */
+	@Override
+	public void release() {
+		// Nothing to do here
+	}
+
+
+	/**
+	 * Shortcut method if you only care about the most recent EntityContainer.
+	 * 
+	 * @return the lastEntityContainer
+	 */
+	public EntityContainer getLastEntityContainer() {
+		initialize();
+		if (processedEntities.isEmpty()) {
+			return null;
+		} else
+			return processedEntities.get(processedEntities.size() - 1);
+	}
+
+
+	/**
+	 * Retrieve an Iterable of all the processed EntityContainers.
+	 * 
+	 * @return the processedEntities
+	 */
+	public Iterable<EntityContainer> getProcessedEntities() {
+		initialize();
+		return Collections.unmodifiableList(processedEntities);
+	}
+
+}

Property changes on: C:\Documents and Settings\KNewman\workspace\Osmosis\test\com\bretth\osmosis\test\task\SinkEntityInspector.java
___________________________________________________________________
Name: svn:eol-style
   + native
Name: svn:keywords Author Id Revision
   + 

