}
@Test
public void testDataStore() throws Exception {
DataAccess<FeatureType, Feature> mappingDataStore;
final Name typeName = new NameImpl(AWNS, "SiteSinglePhenomTimeSeries");
{
final Map dsParams = new HashMap();
String configLocation = schemaBase + "TimeSeriesTest_properties.xml";
final URL url = getClass().getResource(configLocation);
// configLocation =
// "file:/home/gabriel/svn/geoserver/trunk/configuration/community-schema-timeseries2/TimeSeriesTest_properties.xml";
// URL url = new URL(configLocation);
dsParams.put("dbtype", "app-schema");
dsParams.put("url", url.toExternalForm());
mappingDataStore = DataAccessFinder.getDataStore(dsParams);
}
assertNotNull(mappingDataStore);
FeatureSource<FeatureType, Feature> fSource;
{
FeatureType fType = mappingDataStore.getSchema(typeName);
assertNotNull(fType);
fSource = mappingDataStore.getFeatureSource(typeName);
}
FeatureCollection features;
// make a getFeatures request with a nested properties filter.
//
// was 96, but now 3 as mapped features are grouped by id
final int EXPECTED_MAPPED_FEATURE_COUNT = 3;
// 96 data rows from property file
final int EXPECTED_SIMPLE_FEATURE_COUNT = 96;
{
features = fSource.getFeatures();
int resultCount = getCount(features);
String msg = "be sure difference in result count is not due to different dataset.";
assertEquals(msg, EXPECTED_MAPPED_FEATURE_COUNT, resultCount);
}
Feature feature;
int count = 0;
FilterFactory ffac;
{
NamespaceSupport namespaces = new NamespaceSupport();
namespaces.declarePrefix("aw", AWNS);
namespaces.declarePrefix("om", OMNS);
namespaces.declarePrefix("swe", SWENS);
namespaces.declarePrefix("gml", GMLNS);
namespaces.declarePrefix("sa", SANS);
namespaces.declarePrefix("cv", CVNS);
// TODO: use commonfactoryfinder or the mechanism choosed
// to pass namespace context to filter factory
ffac = new FilterFactoryImplNamespaceAware(namespaces);
}
final String phenomNamePath = "aw:relatedObservation/aw:PhenomenonTimeSeries/om:observedProperty/swe:Phenomenon/gml:name";
FeatureIterator it = features.features();
for (; it.hasNext();) {
feature = (Feature) it.next();
count++;
{
PropertyName gmlName = ffac.property("gml:name");
PropertyName phenomName = ffac.property(phenomNamePath);
Object nameVal = gmlName.evaluate(feature, String.class);
assertNotNull("gml:name evaluated to null", nameVal);
Object phenomNameVal = phenomName.evaluate(feature, String.class);
assertNotNull(phenomNamePath + " evaluated to null", phenomNameVal);
}
{
PropertyName sampledFeatureName = ffac.property("sa:sampledFeature");
Attribute sampledFeatureVal = (Attribute) sampledFeatureName.evaluate(feature);
assertNotNull("sa:sampledFeature evaluated to null", sampledFeatureVal);
assertEquals(0, ((Collection) sampledFeatureVal.getValue()).size());
Map attributes = (Map) sampledFeatureVal.getUserData().get(Attributes.class);
assertNotNull(attributes);
Name xlinkTitle = name(XLINK.NAMESPACE, "title");
assertTrue(attributes.containsKey(xlinkTitle));
assertNotNull(attributes.get(xlinkTitle));
Name xlinkHref = name(XLINK.NAMESPACE, "href");
assertTrue(attributes.containsKey(xlinkHref));
assertNotNull(attributes.get(xlinkHref));
}
{