Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Ingest test
Browse files Browse the repository at this point in the history
  • Loading branch information
go0ty committed Feb 29, 2016
1 parent d4bcc42 commit 329cd6f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@
<version>2.1.0</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ingest/inspect/ShapefileInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public DataResource inspect(DataResource dataResource, boolean host) throws Exce
// Set the spatial metadata
dataResource.spatialMetadata = spatialMetadata;

// Process and persist shape file into the Piazza PostGIS database.
// Process and persist shapotepae file into the Piazza PostGIS database.
if (host) {
persistShapeFile(featureSource, dataResource);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ingest/inspect/WfsInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void copyWfsToPostGis(DataResource dataResource,
* @return GeoTools Feature Source that can be queried for spatial features
* and metadata
*/
private FeatureSource<SimpleFeatureType, SimpleFeature> getWfsFeatureSource(DataResource dataResource)
public FeatureSource<SimpleFeatureType, SimpleFeature> getWfsFeatureSource(DataResource dataResource)
throws IOException {
// Form the Get Capabilities URL
WfsResource wfsResource = (WfsResource) dataResource.getDataType();
Expand Down
92 changes: 92 additions & 0 deletions src/test/java/ingest/test/IngestTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package ingest.test;

import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.isA;
import ingest.inspect.WfsInspector;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import model.data.DataResource;
import model.data.type.WfsResource;

import org.geotools.data.DataUtilities;
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.data.store.ContentFeatureSource;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.referencing.CRS;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;

/**
* Tests internal Ingest components such as data type Inspectors
*
* @author Patrick.Doody
*
*/
public class IngestTests {
private static final String MOCK_FEATURE_NAME = "Test";
MemoryDataStore mockDataStore;
@Spy
private WfsInspector wfsInspector;

@Before
public void init() throws Exception {
MockitoAnnotations.initMocks(this);

// Creating a Mock in-memory Data Store
mockDataStore = new MemoryDataStore();
SimpleFeatureType featureType = DataUtilities.createType(MOCK_FEATURE_NAME, "the_geom:Point:srid=4326");
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
// Create some sample Test Points
List<SimpleFeature> features = new ArrayList<SimpleFeature>();
Point point = geometryFactory.createPoint(new Coordinate(5, 5));
featureBuilder.add(point);
SimpleFeature feature = featureBuilder.buildFeature(null);
features.add(feature);
Point otherPoint = geometryFactory.createPoint(new Coordinate(0, 0));
featureBuilder.add(otherPoint);
SimpleFeature otherFeature = featureBuilder.buildFeature(null);
features.add(otherFeature);
mockDataStore.addFeatures(features);
}

/**
* Tests the WFS Inspector
*/
@Test
public void testWfsInspector() throws Exception {
// Mock a WFS DataResource
WfsResource wfsResource = new WfsResource();
DataResource mockResource = new DataResource();
mockResource.dataId = UUID.randomUUID().toString();
mockResource.dataType = wfsResource;
ContentFeatureSource featureSource = mockDataStore.getFeatureSource(MOCK_FEATURE_NAME);

Mockito.doReturn(featureSource).when(wfsInspector).getWfsFeatureSource(isA(DataResource.class));

// Inspect our sample resource
DataResource inspectedResource = wfsInspector.inspect(mockResource, false);

// Verify that the Spatial Metadata has been appropriately populated
assertTrue(inspectedResource.getSpatialMetadata().getMinX().equals(featureSource.getBounds().getMinX()));
assertTrue(inspectedResource.getSpatialMetadata().getMinY().equals(featureSource.getBounds().getMinY()));
assertTrue(inspectedResource.getSpatialMetadata().getMaxX().equals(featureSource.getBounds().getMaxX()));
assertTrue(inspectedResource.getSpatialMetadata().getMaxY().equals(featureSource.getBounds().getMaxY()));
assertTrue(inspectedResource.getSpatialMetadata().getEpsgCode()
.equals(CRS.lookupEpsgCode(featureSource.getInfo().getCRS(), true)));
}

}

0 comments on commit 329cd6f

Please sign in to comment.