/* * Constellation - An open source and standard compliant SDI * http://www.constellation-sdi.org * * Copyright 2014 Geomatys. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.constellation.wfs; import java.io.File; import java.io.StringWriter; import java.net.URL; import java.sql.Connection; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.namespace.QName; import org.apache.sis.util.logging.Logging; import org.apache.sis.xml.MarshallerPool; import org.constellation.business.*; import org.constellation.configuration.ConfigDirectory; import org.constellation.admin.SpringHelper; import org.constellation.api.ProviderType; import org.constellation.configuration.ConfigurationException; import org.constellation.configuration.LayerContext; import org.constellation.provider.DataProviders; import org.constellation.provider.ProviderFactory; import org.constellation.test.utils.CstlDOMComparator; import org.constellation.test.utils.Order; import org.constellation.test.utils.SpringTestRunner; import org.constellation.util.Util; import org.constellation.wfs.ws.DefaultWFSWorker; import org.constellation.wfs.ws.WFSWorker; import org.constellation.wfs.ws.rs.FeatureCollectionWrapper; import org.constellation.ws.CstlServiceException; import org.constellation.ws.embedded.AbstractGrizzlyServer; import org.geotoolkit.data.FeatureCollection; import org.geotoolkit.feature.xml.XmlFeatureWriter; import org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter; import org.geotoolkit.internal.sql.DefaultDataSource; import org.geotoolkit.ogc.xml.v110.BBOXType; import org.geotoolkit.ogc.xml.v110.ComparisonOpsType; import org.geotoolkit.ogc.xml.v110.FilterType; import org.geotoolkit.ogc.xml.v110.LiteralType; import org.geotoolkit.ogc.xml.v110.PropertyIsEqualToType; import org.geotoolkit.ogc.xml.v110.PropertyNameType; import org.geotoolkit.ogc.xml.v110.SortByType; import org.geotoolkit.ogc.xml.v110.SortOrderType; import org.geotoolkit.ogc.xml.v110.SortPropertyType; import org.geotoolkit.ogc.xml.v110.SpatialOpsType; import static org.geotoolkit.ows.xml.OWSExceptionCode.INVALID_PARAMETER_VALUE; import static org.geotoolkit.ows.xml.OWSExceptionCode.INVALID_VALUE; import static org.geotoolkit.ows.xml.OWSExceptionCode.MISSING_PARAMETER_VALUE; import static org.geotoolkit.ows.xml.OWSExceptionCode.VERSION_NEGOTIATION_FAILED; import org.geotoolkit.ows.xml.v100.AcceptVersionsType; import org.geotoolkit.ows.xml.v100.SectionsType; import static org.geotoolkit.utility.parameter.ParametersExt.getOrCreateGroup; import static org.geotoolkit.utility.parameter.ParametersExt.getOrCreateValue; import org.geotoolkit.referencing.CRS; import org.geotoolkit.util.FileUtilities; import org.geotoolkit.util.sql.DerbySqlScriptRunner; import org.geotoolkit.wfs.xml.AllSomeType; import org.geotoolkit.wfs.xml.ResultTypeType; import org.geotoolkit.wfs.xml.StoredQueries; import org.geotoolkit.wfs.xml.StoredQueryDescription; import org.geotoolkit.wfs.xml.TransactionResponse; import org.geotoolkit.wfs.xml.WFSCapabilities; import org.geotoolkit.wfs.xml.WFSMarshallerPool; import org.geotoolkit.wfs.xml.v110.DeleteElementType; import org.geotoolkit.wfs.xml.v110.DescribeFeatureTypeType; import org.geotoolkit.wfs.xml.v110.FeatureCollectionType; import org.geotoolkit.wfs.xml.v110.GetCapabilitiesType; import org.geotoolkit.wfs.xml.v110.GetFeatureType; import org.geotoolkit.wfs.xml.v110.InsertElementType; import org.geotoolkit.wfs.xml.v110.PropertyType; import org.geotoolkit.wfs.xml.v110.QueryType; import org.geotoolkit.wfs.xml.v110.TransactionResponseType; import org.geotoolkit.wfs.xml.v110.TransactionSummaryType; import org.geotoolkit.wfs.xml.v110.TransactionType; import org.geotoolkit.wfs.xml.v110.UpdateElementType; import org.geotoolkit.wfs.xml.v110.ValueType; import org.geotoolkit.wfs.xml.v200.ObjectFactory; import org.geotoolkit.wfs.xml.v200.ParameterExpressionType; import org.geotoolkit.wfs.xml.v200.QueryExpressionTextType; import org.geotoolkit.wfs.xml.v200.StoredQueryDescriptionType; import org.geotoolkit.xsd.xml.v2001.ComplexType; import org.geotoolkit.xsd.xml.v2001.Schema; import org.geotoolkit.xsd.xml.v2001.TopLevelComplexType; import org.geotoolkit.xsd.xml.v2001.TopLevelElement; import org.geotoolkit.xsd.xml.v2001.XSDMarshallerPool; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.opengis.parameter.ParameterValueGroup; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; /** * * @author Guilhem Legal (Geomatys) */ @RunWith(SpringTestRunner.class) @ContextConfiguration("classpath:/cstl/spring/test-context.xml") @ActiveProfiles({"standard"}) public class WFSWorkerTest implements ApplicationContextAware { private static final Logger LOGGER = Logging.getLogger("org.constellation.wfs"); protected ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } @Inject private IServiceBusiness serviceBusiness; @Inject protected ILayerBusiness layerBusiness; @Inject protected IProviderBusiness providerBusiness; @Inject protected IDataBusiness dataBusiness; private static MarshallerPool pool; private static WFSWorker worker ; private static DefaultDataSource ds = null; private static DefaultDataSource ds2 = null; private XmlFeatureWriter featureWriter; private static String EPSG_VERSION; private static boolean initialized = false; private static boolean mdweb_active = true; @BeforeClass public static void initTestDir() { ConfigDirectory.setupTestEnvironement("WFSWorkerTest"); } @PostConstruct public void setUpClass() { SpringHelper.setApplicationContext(applicationContext); if (!initialized) { try { layerBusiness.removeAll(); serviceBusiness.deleteAll(); dataBusiness.deleteAll(); providerBusiness.removeAll(); final ProviderFactory featfactory = DataProviders.getInstance().getFactory("feature-store"); final File outputDir = AbstractGrizzlyServer.initDataDirectory(); final ProviderFactory ffactory = DataProviders.getInstance().getFactory("feature-store"); final ParameterValueGroup sourcef = ffactory.getProviderDescriptor().createValue(); getOrCreateValue(sourcef, "id").setValue("shapeSrc"); getOrCreateValue(sourcef, "load_all").setValue(true); final ParameterValueGroup choice2 = getOrCreateGroup(sourcef, "choice"); final ParameterValueGroup shpconfig = getOrCreateGroup(choice2, "ShapefileParametersFolder"); getOrCreateValue(shpconfig, "url").setValue(new URL("file:"+outputDir.getAbsolutePath() + "/org/constellation/ws/embedded/wms111/shapefiles")); getOrCreateValue(shpconfig, "namespace").setValue("http://www.opengis.net/gml"); final ParameterValueGroup layer = getOrCreateGroup(sourcef, "Layer"); getOrCreateValue(layer, "name").setValue("NamedPlaces"); getOrCreateValue(layer, "style").setValue("cite_style_NamedPlaces"); providerBusiness.storeProvider("shapeSrc", null, ProviderType.LAYER, "feature-store", sourcef); dataBusiness.create(new QName("http://www.opengis.net/gml", "BuildingCenters"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "BasicPolygons"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "Bridges"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "Streams"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "Lakes"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "NamedPlaces"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "Buildings"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "RoadSegments"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "DividedRoutes"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "Forests"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "MapNeatline"), "shapeSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/gml", "Ponds"), "shapeSrc", "VECTOR", false, true, null, null); final String url = "jdbc:derby:memory:TestWFSWorkerOM"; final DefaultDataSource ds = new DefaultDataSource(url + ";create=true"); Connection con = ds.getConnection(); DerbySqlScriptRunner sr = new DerbySqlScriptRunner(con); String sql = FileUtilities.getStringFromStream(Util.getResourceAsStream("org/constellation/om2/structure_observations.sql")); sql = sql.replace("$SCHEMA", ""); sr.run(sql); sr.run(Util.getResourceAsStream("org/constellation/sql/sos-data-om2.sql")); con.close(); ds.shutdown(); final ParameterValueGroup sourceOM = featfactory.getProviderDescriptor().createValue(); getOrCreateValue(sourceOM, "id").setValue("omSrc"); getOrCreateValue(sourceOM, "load_all").setValue(true); final ParameterValueGroup choiceOM = getOrCreateGroup(sourceOM, "choice"); final ParameterValueGroup omconfig = getOrCreateGroup(choiceOM, " SOSDBParameters"); getOrCreateValue(omconfig, "sgbdtype").setValue("derby"); getOrCreateValue(omconfig, "derbyurl").setValue(url); providerBusiness.storeProvider("omSrc", null, ProviderType.LAYER, "feature-store", sourceOM); dataBusiness.create(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint"), "omSrc", "VECTOR", false, true, null, null); // MDWEB store mdweb_active = Util.getResourceAsStream("org/mdweb/sql/v24/metadata/model/mdw_schema_2.4_derby.sql") != null; if (mdweb_active) { final String url2 = "jdbc:derby:memory:TestWFSWorkerSMl"; ds2 = new DefaultDataSource(url2 + ";create=true"); Connection con2 = ds2.getConnection(); DerbySqlScriptRunner sr2 = new DerbySqlScriptRunner(con2); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/model/mdw_schema_2.4_derby.sql")); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/schemas/ISO19115.sql")); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/schemas/ISO19119.sql")); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/schemas/ISO19108.sql")); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/data/defaultRecordSets.sql")); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/users/creation_user.sql")); sr2.run(Util.getResourceAsStream("org/mdweb/sql/v24/metadata/schemas/SensorML.sql")); sr2.run(Util.getResourceAsStream("org/constellation/sql/sml-data.sql")); con.close(); final ParameterValueGroup sourceSML = featfactory.getProviderDescriptor().createValue(); getOrCreateValue(sourceSML, "id").setValue("smlSrc"); getOrCreateValue(sourceSML, "load_all").setValue(true); final ParameterValueGroup choiceSML = getOrCreateGroup(sourceSML, "choice"); final ParameterValueGroup smlconfig = getOrCreateGroup(choiceSML, "SMLParameters"); getOrCreateValue(smlconfig, "sgbdtype").setValue("derby"); getOrCreateValue(smlconfig, "derbyurl").setValue(url2); providerBusiness.storeProvider("smlSrc", null, ProviderType.LAYER, "feature-store", sourceSML); dataBusiness.create(new QName("http://www.opengis.net/sml/1.0", "System"), "smlSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/sml/1.0", "Component"), "smlSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/sml/1.0", "DataSourceType"), "smlSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/sml/1.0", "ProcessModel"), "smlSrc", "VECTOR", false, true, null, null); dataBusiness.create(new QName("http://www.opengis.net/sml/1.0", "ProcessChain"), "smlSrc", "VECTOR", false, true, null, null); } DataProviders.getInstance().reload(); final LayerContext config = new LayerContext(); config.getCustomParameters().put("shiroAccessible", "false"); config.getCustomParameters().put("transactionSecurized", "false"); config.getCustomParameters().put("transactionnal", "true"); serviceBusiness.create("wfs", "default", config, null); layerBusiness.add("SamplingPoint", "http://www.opengis.net/sampling/1.0", "omSrc", null, "default", "wfs", null); layerBusiness.add("BuildingCenters", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("BasicPolygons", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("Bridges", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("Streams", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("Lakes", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("NamedPlaces", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("Buildings", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("RoadSegments", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("DividedRoutes", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("Forests", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("MapNeatline", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); layerBusiness.add("Ponds", "http://www.opengis.net/gml", "shapeSrc", null, "default", "wfs", null); serviceBusiness.create("wfs", "test", config, null); layerBusiness.add("SamplingPoint", "http://www.opengis.net/sampling/1.0", "omSrc", null, "test", "wfs", null); layerBusiness.add("BuildingCenters", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("BasicPolygons", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("Bridges", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("Streams", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("Lakes", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("NamedPlaces", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("Buildings", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("RoadSegments", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("DividedRoutes", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("Forests", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("MapNeatline", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); layerBusiness.add("Ponds", "http://www.opengis.net/gml", "shapeSrc", null, "test", "wfs", null); final LayerContext config2 = new LayerContext(); config2.getCustomParameters().put("shiroAccessible", "false"); config2.getCustomParameters().put("transactionSecurized", "false"); config2.getCustomParameters().put("transactionnal", "true"); serviceBusiness.create("wfs", "test1", config, null); layerBusiness.add("SamplingPoint", "http://www.opengis.net/sampling/1.0", "omSrc", null, "test1", "wfs", null); layerBusiness.add("BuildingCenters", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("BasicPolygons", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("Bridges", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("Streams", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("Lakes", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("NamedPlaces", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("Buildings", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("RoadSegments", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("DividedRoutes", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("Forests", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("MapNeatline", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); layerBusiness.add("Ponds", "http://www.opengis.net/gml", "shapeSrc", null, "test1", "wfs", null); if (mdweb_active) { layerBusiness.add("System", "http://www.opengis.net/sml/1.0", "smlSrc", null, "test1", "wfs", null); layerBusiness.add("Component", "http://www.opengis.net/sml/1.0", "smlSrc", null, "test1", "wfs", null); layerBusiness.add("DataSourceType", "http://www.opengis.net/sml/1.0", "smlSrc", null, "test1", "wfs", null); layerBusiness.add("ProcessModel", "http://www.opengis.net/sml/1.0", "smlSrc", null, "test1", "wfs", null); layerBusiness.add("ProcessChain", "http://www.opengis.net/sml/1.0", "smlSrc", null, "test1", "wfs", null); } pool = WFSMarshallerPool.getInstance(); final List<StoredQueryDescription> descriptions = new ArrayList<>(); final ParameterExpressionType param = new ParameterExpressionType("name", "name Parameter", "A parameter on the name of the feature", new QName("http://www.w3.org/2001/XMLSchema", "string", "xs")); final List<QName> types = Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")); final org.geotoolkit.ogc.xml.v200.PropertyIsEqualToType pis = new org.geotoolkit.ogc.xml.v200.PropertyIsEqualToType(new org.geotoolkit.ogc.xml.v200.LiteralType("$name"), "name", true); final org.geotoolkit.ogc.xml.v200.FilterType filter = new org.geotoolkit.ogc.xml.v200.FilterType(pis); final org.geotoolkit.wfs.xml.v200.QueryType query = new org.geotoolkit.wfs.xml.v200.QueryType(filter, types, "2.0.0"); final QueryExpressionTextType queryEx = new QueryExpressionTextType("urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression", null, types); final ObjectFactory factory = new ObjectFactory(); queryEx.getContent().add(factory.createQuery(query)); final StoredQueryDescriptionType des1 = new StoredQueryDescriptionType("nameQuery", "Name query" , "filter on name for samplingPoint", param, queryEx); descriptions.add(des1); final StoredQueries queries = new StoredQueries(descriptions); serviceBusiness.setExtraConfiguration("wfs", "test1", "StoredQueries.xml", queries, pool); EPSG_VERSION = CRS.getVersion("EPSG").toString(); worker = new DefaultWFSWorker("test1"); worker.setLogLevel(Level.FINER); worker.setServiceUrl("http://geomatys.com/constellation/WS/"); worker.setShiroAccessible(false); initialized = true; } catch (Exception ex) { Logger.getAnonymousLogger().log(Level.SEVERE, "error while initializing test", ex); } } } @AfterClass public static void tearDownClass() throws Exception { try { final ILayerBusiness layerBean = SpringHelper.getBean(ILayerBusiness.class); if (layerBean != null) { layerBean.removeAll(); } final IServiceBusiness service = SpringHelper.getBean(IServiceBusiness.class); if (service != null) { service.deleteAll(); } final IDataBusiness dataBean = SpringHelper.getBean(IDataBusiness.class); if (dataBean != null) { dataBean.deleteAll(); } final IProviderBusiness provider = SpringHelper.getBean(IProviderBusiness.class); if (provider != null) { provider.removeAll(); } } catch (ConfigurationException ex) { Logger.getAnonymousLogger().log(Level.WARNING, ex.getMessage()); } ConfigDirectory.shutdownTestEnvironement("WFSWorkerTest"); if (ds != null) { ds.shutdown(); } if (ds2 != null) { ds2.shutdown(); } if (worker != null) { worker.destroy(); } File derbyLog = new File("derby.log"); if (derbyLog.exists()) { derbyLog.delete(); } } @Before public void setUp() throws Exception { featureWriter = new JAXPStreamFeatureWriter(); } @After public void tearDown() throws Exception { } /** * test the feature marshall * */ @Test @Order(order=1) public void getCapabilitiesTest() throws Exception { final Marshaller marshaller = pool.acquireMarshaller(); AcceptVersionsType acceptVersion = new AcceptVersionsType("1.1.0"); SectionsType sections = new SectionsType("featureTypeList"); GetCapabilitiesType request = new GetCapabilitiesType(acceptVersion, sections, null, null, "WFS"); WFSCapabilities result = worker.getCapabilities(request); StringWriter sw = new StringWriter(); marshaller.marshal(result, sw); if (mdweb_active) { domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0-ftl-mdw.xml"), sw.toString()); } else { // try to fix an issue with variant generated prefix final String resultCapa = sw.toString(); final String gmlPrefix = getGmlPrefix(resultCapa); final File expectedFile = FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0-ftl.xml"); final String expectedCapa = FileUtilities.getStringFromFile(expectedFile).replace("{gmlPrefix}", gmlPrefix); domCompare( expectedCapa, sw.toString()); } request = new GetCapabilitiesType("WFS"); result = worker.getCapabilities(request); sw = new StringWriter(); marshaller.marshal(result, sw); if (mdweb_active) { domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0-mdw.xml"), sw.toString()); } else { // try to fix an issue with variant generated prefix final String resultCapa = sw.toString(); final String gmlPrefix = getGmlPrefix(resultCapa); final File expectedFile = FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0.xml"); final String expectedCapa = FileUtilities.getStringFromFile(expectedFile).replace("{gmlPrefix}", gmlPrefix); domCompare( expectedCapa, sw.toString()); } acceptVersion = new AcceptVersionsType("2.3.0"); request = new GetCapabilitiesType(acceptVersion, null, null, null, "WFS"); try { worker.getCapabilities(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), VERSION_NEGOTIATION_FAILED); assertEquals(ex.getLocator(), "version"); } request = new GetCapabilitiesType(acceptVersion, null, null, null, "WPS"); try { worker.getCapabilities(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); assertEquals(ex.getLocator(), "service"); } request = new GetCapabilitiesType(null); try { worker.getCapabilities(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), MISSING_PARAMETER_VALUE); assertEquals(ex.getLocator(), "service"); } acceptVersion = new AcceptVersionsType("1.1.0"); sections = new SectionsType("operationsMetadata"); request = new GetCapabilitiesType(acceptVersion, sections, null, null, "WFS"); result = worker.getCapabilities(request); sw = new StringWriter(); marshaller.marshal(result, sw); String resultCapa = sw.toString(); String gmlPrefix = getGmlPrefix(resultCapa); File expectedFile = FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0-om.xml"); String expectedCapa = FileUtilities.getStringFromFile(expectedFile).replace("{gmlPrefix}", gmlPrefix); domCompare( expectedCapa, sw.toString()); acceptVersion = new AcceptVersionsType("1.1.0"); sections = new SectionsType("serviceIdentification"); request = new GetCapabilitiesType(acceptVersion, sections, null, null, "WFS"); result = worker.getCapabilities(request); sw = new StringWriter(); marshaller.marshal(result, sw); resultCapa = sw.toString(); gmlPrefix = getGmlPrefix(resultCapa); expectedFile = FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0-si.xml"); expectedCapa = FileUtilities.getStringFromFile(expectedFile).replace("{gmlPrefix}", gmlPrefix); domCompare( expectedCapa, sw.toString()); acceptVersion = new AcceptVersionsType("1.1.0"); sections = new SectionsType("serviceProvider"); request = new GetCapabilitiesType(acceptVersion, sections, null, null, "WFS"); result = worker.getCapabilities(request); sw = new StringWriter(); marshaller.marshal(result, sw); resultCapa = sw.toString(); gmlPrefix = getGmlPrefix(resultCapa); expectedFile = FileUtilities.getFileFromResource("org.constellation.wfs.xml.WFSCapabilities1-1-0-sp.xml"); expectedCapa = FileUtilities.getStringFromFile(expectedFile).replace("{gmlPrefix}", gmlPrefix); domCompare( expectedCapa, sw.toString()); pool.recycle(marshaller); } /** * test the Getfeature operations with bad parameter causing exception return * */ @Test @Order(order=2) public void getFeatureErrorTest() throws Exception { /** * Test 1 : empty query => error */ GetFeatureType request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, null, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object result = null; try { result = worker.getFeature(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { //ok } /** * Test 2 : bad version => error */ request = new GetFeatureType("WFS", "1.2.0", null, Integer.MAX_VALUE, null, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); try { result = worker.getFeature(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); assertEquals(ex.getLocator(), "version"); } } /** * test the feature marshall * */ @Test @Order(order=3) public void getFeatureOMTest() throws Exception { /** * Test 1 : query on typeName samplingPoint */ List<QueryType> queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null)); GetFeatureType request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); FeatureCollectionWrapper wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); StringWriter writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); String expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-3.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); String sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 2 : query on typeName samplingPoint whith HITS result type */ queries = new ArrayList<>(); QueryType query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.HITS, "text/gml; subtype=gml/3.1.1"); FeatureCollectionType resultHits = (FeatureCollectionType) worker.getFeature(request); assertTrue(resultHits.getNumberOfFeatures() == 6); /** * Test 3 : query on typeName samplingPoint with propertyName = {gml:name} */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null); query.getPropertyNameOrXlinkPropertyNameOrFunction().add("gml:name"); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-5.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 4 : query on typeName samplingPoint whith a filter name = 10972X0137-PONT */ queries = new ArrayList<>(); ComparisonOpsType pe = new PropertyIsEqualToType(new LiteralType("10972X0137-PONT"), new PropertyNameType("name"), Boolean.TRUE); FilterType filter = new FilterType(pe); queries.add(new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-4.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 5 : query on typeName samplingPoint whith a filter xpath //gml:name = 10972X0137-PONT */ queries = new ArrayList<>(); pe = new PropertyIsEqualToType(new LiteralType("10972X0137-PONT"), new PropertyNameType("//{http://www.opengis.net/gml}name"), Boolean.TRUE); filter = new FilterType(pe); queries.add(new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-4.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 6 : query on typeName samplingPoint whith a spatial filter BBOX */ queries = new ArrayList<>(); SpatialOpsType bbox = new BBOXType("{http://www.opengis.net/sampling/1.0}position", 65300.0, 1731360.0, 65500.0, 1731400.0, "urn:ogc:def:crs:epsg:7.6:27582"); filter = new FilterType(bbox); queries.add(new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-8.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 7 : query on typeName samplingPoint whith a spatial filter BBOX () with no namespace */ queries = new ArrayList<>(); bbox = new BBOXType("position", 65300.0, 1731360.0, 65500.0, 1731400.0, "urn:ogc:def:crs:epsg:7.6:27582"); filter = new FilterType(bbox); queries.add(new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-8.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 8 : query on typeName samplingPoint with sort on gml:name */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null); query.setSortBy(new SortByType(Arrays.asList(new SortPropertyType("http://www.opengis.net/gml:name", SortOrderType.ASC)))); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-6.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 9 : query on typeName samplingPoint with sort on gml:name */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null); query.setSortBy(new SortByType(Arrays.asList(new SortPropertyType("http://www.opengis.net/gml:name", SortOrderType.DESC)))); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.samplingPointCollection-7.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 10 : query on typeName samplingPoint whith HITS result type */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.HITS, "text/gml; subtype=gml/3.1.1"); resultHits = (FeatureCollectionType) worker.getFeature(request); assertTrue(resultHits.getNumberOfFeatures() == 6); /** * Test 11 : query on typeName samplingPoint whith a filter with unexpected property */ queries = new ArrayList<>(); pe = new PropertyIsEqualToType(new LiteralType("whatever"), new PropertyNameType("wrongProperty"), Boolean.TRUE); filter = new FilterType(pe); queries.add(new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); try { worker.getFeature(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { //ok } /** * Test 12 : query on typeName samplingPoint whith a an unexpected property in propertyNames */ queries = new ArrayList<>(); query = new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")), null); query.getPropertyNameOrXlinkPropertyNameOrFunction().add("wrongProperty"); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); try { worker.getFeature(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); } } /** * test the feature marshall * */ @Test @Order(order=4) public void getFeatureSMLTest() throws Exception { if (!mdweb_active) return; /** * Test 1 : query on typeName sml:System */ List<QueryType> queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null)); GetFeatureType request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); FeatureCollectionWrapper wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); StringWriter writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); String expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-3.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); String sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 2 : query on typeName sml:System avec srsName = EPSG:4326 */ queries = new ArrayList<>(); QueryType query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); query.setSrsName("urn:ogc:def:crs:epsg:EPSG:27582"); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-1.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 3 : query on typeName sml:System with propertyName = {sml:keywords, sml:phenomenons} */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); query.getPropertyNameOrXlinkPropertyNameOrFunction().add("sml:keywords"); query.getPropertyNameOrXlinkPropertyNameOrFunction().add("sml:phenomenons"); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, null); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-2.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 4 : query on typeName sml:System filter on name = 'Piezometer Test' */ ComparisonOpsType pe1 = new PropertyIsEqualToType(new LiteralType("Piezometer Test"), new PropertyNameType("name"), Boolean.TRUE); FilterType filter = new FilterType(pe1); queries = new ArrayList<>(); query = new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, null); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); assertEquals("3.1.1", wrapper.getGmlVersion()); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-4.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 5 : same test xpath style */ pe1 = new PropertyIsEqualToType(new LiteralType("Piezometer Test"), new PropertyNameType("/name"), Boolean.TRUE); filter = new FilterType(pe1); queries = new ArrayList<>(); query = new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, null); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); assertEquals("3.1.1", wrapper.getGmlVersion()); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-4.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 6 : query on typeName sml:System filter on input name = 'height' (xpath style) */ pe1 = new PropertyIsEqualToType(new LiteralType("height"), new PropertyNameType("/inputs/input/name"), Boolean.TRUE); filter = new FilterType(pe1); queries = new ArrayList<>(); query = new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, null); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); assertEquals("3.1.1", wrapper.getGmlVersion()); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-5.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); /** * Test 7 : query on typeName sml:System with bad xpath NOT WORKING pe1 = new PropertyIsEqualToType(new LiteralType("height"), new PropertyNameType("/inputs/inputation/namein"), Boolean.TRUE); filter = new FilterType(pe1); queries = new ArrayList<>(); query = new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, null); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); assertEquals("3.1.1", wrapper.getGmlVersion()); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-5.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); domCompare(expectedResult, writer.toString()); */ /** * Test 8 : query on typeName sml:System filter on input name = 'height' (xpath style) prefixed with featureType name */ pe1 = new PropertyIsEqualToType(new LiteralType("height"), new PropertyNameType("{http://www.opengis.net/sml/1.0}System/inputs/input/name"), Boolean.TRUE); filter = new FilterType(pe1); queries = new ArrayList<>(); query = new QueryType(filter, Arrays.asList(new QName("http://www.opengis.net/sml/1.0", "System")), null); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, null); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); assertEquals("3.1.1", wrapper.getGmlVersion()); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); expectedResult = FileUtilities.getStringFromFile(FileUtilities.getFileFromResource("org.constellation.wfs.xml.systemCollection-5.xml")); expectedResult = expectedResult.replace("EPSG_VERSION", EPSG_VERSION); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare(expectedResult, sresult); } /** * test the feature marshall * */ @Test @Order(order=5) public void getFeatureShapeFileTest() throws Exception { /** * Test 1 : query on typeName bridges */ List<QueryType> queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "Bridges")), null)); GetFeatureType request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); FeatureCollectionWrapper wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); StringWriter writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); String sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.bridgeCollection.xml"), sresult); /** * Test 2 : query on typeName bridges with propertyName = {FID} */ queries = new ArrayList<>(); QueryType query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "Bridges")), null); query.getPropertyNameOrXlinkPropertyNameOrFunction().add("FID"); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.bridgeCollection-2.xml"), sresult); /** * Test 3 : query on typeName NamedPlaces */ queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.namedPlacesCollection-1.xml"), sresult); /** * Test 4 : query on typeName NamedPlaces with resultType = HITS */ queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null)); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.HITS, "text/gml; subtype=gml/3.1.1"); FeatureCollectionType resultHits = (FeatureCollectionType) worker.getFeature(request);worker.getFeature(request); assertTrue(resultHits.getNumberOfFeatures() == 2); /** * Test 5 : query on typeName NamedPlaces with srsName = EPSG:27582 */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null); query.setSrsName("EPSG:27582"); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.namedPlacesCollection-1_reproj.xml"), sresult); /** * Test 6 : query on typeName NamedPlaces with DESC sortBy on NAME property (not supported) */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null); query.setSortBy(new SortByType(Arrays.asList(new SortPropertyType("NAME", SortOrderType.DESC)))); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.namedPlacesCollection-5.xml"), sresult); /** * Test 7 : query on typeName NamedPlaces with ASC sortBy on NAME property (not supported) */ queries = new ArrayList<>(); query = new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null); query.setSortBy(new SortByType(Arrays.asList(new SortPropertyType("NAME", SortOrderType.ASC)))); queries.add(query); request = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); result = worker.getFeature(request); assertTrue(result instanceof FeatureCollectionWrapper); wrapper = (FeatureCollectionWrapper) result; result = wrapper.getFeatureCollection(); writer = new StringWriter(); featureWriter.write((FeatureCollection)result,writer); sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.namedPlacesCollection-1.xml"), sresult); } /** * * */ @Test @Order(order=6) public void DescribeFeatureTest() throws Exception { Unmarshaller unmarshaller = XSDMarshallerPool.getInstance().acquireUnmarshaller(); /** * Test 1 : describe Feature type bridges */ List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName("http://www.opengis.net/gml", "Bridges")); DescribeFeatureTypeType request = new DescribeFeatureTypeType("WFS", "1.1.0", null, typeNames, "text/gml; subtype=gml/3.1.1"); Schema result = (Schema) worker.describeFeatureType(request); Schema expResult = (Schema) unmarshaller.unmarshal(Util.getResourceAsStream("org/constellation/wfs/xsd/bridge.xsd")); // fix for equlity on empty list / null list for (ComplexType type : expResult.getComplexTypes()) { type.getAttributeOrAttributeGroup(); } assertEquals(expResult, result); /** * Test 2 : describe Feature type Sampling point */ typeNames = new ArrayList<>(); typeNames.add(new QName("http://www.opengis.net/sampling/1.0", "SamplingPoint")); request = new DescribeFeatureTypeType("WFS", "1.1.0", null, typeNames, "text/gml; subtype=gml/3.1.1"); result = (Schema) worker.describeFeatureType(request); expResult = (Schema) unmarshaller.unmarshal(Util.getResourceAsStream("org/constellation/wfs/xsd/sampling.xsd")); // fix for equlity on empty list / null list for (ComplexType type : expResult.getComplexTypes()) { type.getAttributeOrAttributeGroup(); } assertEquals(expResult, result); /** * Test 3 : describe Feature type System */ if (mdweb_active) { typeNames = new ArrayList<>(); typeNames.add(new QName("http://www.opengis.net/sml/1.0", "System")); request = new DescribeFeatureTypeType("WFS", "1.1.0", null, typeNames, "text/gml; subtype=gml/3.1.1"); result = (Schema) worker.describeFeatureType(request); expResult = (Schema) unmarshaller.unmarshal(Util.getResourceAsStream("org/constellation/wfs/xsd/system.xsd")); assertEquals(expResult.getElements().size(), result.getElements().size()); for (int i = 0; i < expResult.getElements().size(); i++) { TopLevelElement expElem = expResult.getElements().get(i); TopLevelElement resElem = result.getElements().get(i); assertEquals(expElem, resElem); } assertEquals(expResult.getComplexTypes().size(), result.getComplexTypes().size()); for (int i = 0; i < expResult.getComplexTypes().size(); i++) { TopLevelComplexType expElem = expResult.getComplexTypes().get(i); TopLevelComplexType resElem = result.getComplexTypes().get(i); assertEquals(expElem, resElem); } assertEquals(expResult, result); } XSDMarshallerPool.getInstance().recycle(unmarshaller); } /** * * */ @Test @Order(order=7) public void TransactionUpdateTest() throws Exception { /** * Test 1 : transaction update for Feature type bridges with a bad inputFormat */ QName typeName = new QName("http://www.opengis.net/gml", "Bridges"); List<PropertyType> properties = new ArrayList<>(); UpdateElementType update = new UpdateElementType(null, properties, null, typeName, null); update.setInputFormat("bad inputFormat"); TransactionType request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, update); try { worker.transaction(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); assertEquals(ex.getLocator(), "inputFormat"); } /** * Test 2 : transaction update for Feature type bridges with a bad property */ typeName = new QName("http://www.opengis.net/gml", "Bridges"); properties = new ArrayList<>(); properties.add(new PropertyType(new QName("whatever"), new ValueType("someValue"))); request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, new UpdateElementType(null, properties, null, typeName, null)); try { worker.transaction(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_VALUE); assertEquals(ex.getMessage(), "The feature Type {http://www.opengis.net/gml}Bridges does not has such a property: whatever"); } /** * Test 3 : transaction update for Feature type bridges with a bad property in filter */ typeName = new QName("http://www.opengis.net/gml", "Bridges"); properties = new ArrayList<>(); properties.add(new PropertyType(new QName("NAME"), new ValueType("someValue"))); ComparisonOpsType pe = new PropertyIsEqualToType(new LiteralType("10972X0137-PONT"), new PropertyNameType("bad"), Boolean.TRUE); FilterType filter = new FilterType(pe); request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, new UpdateElementType(null, properties, filter, typeName, null)); try { worker.transaction(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); assertEquals(ex.getMessage(), "The feature Type {http://www.opengis.net/gml}Bridges does not has such a property: bad"); } /** * Test 4 : transaction update for Feature type NamedPlaces with a property in filter */ typeName = new QName("http://www.opengis.net/gml", "NamedPlaces"); properties = new ArrayList<>(); properties.add(new PropertyType(new QName("FID"), new ValueType("999"))); pe = new PropertyIsEqualToType(new LiteralType("Ashton"), new PropertyNameType("NAME"), Boolean.TRUE); filter = new FilterType(pe); request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, new UpdateElementType(null, properties, filter, typeName, null)); TransactionResponse result = worker.transaction(request); TransactionSummaryType sum = new TransactionSummaryType(0, 1, 0); TransactionResponseType ExpResult = new TransactionResponseType(sum, null, null, "1.1.0"); assertEquals(ExpResult, result); /** * we verify that the feature have been updated */ List<QueryType> queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null)); GetFeatureType requestGF = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object resultGF = worker.getFeature(requestGF); assertTrue(resultGF instanceof FeatureCollectionWrapper); FeatureCollectionWrapper wrapper = (FeatureCollectionWrapper) resultGF; resultGF = wrapper.getFeatureCollection(); StringWriter writer = new StringWriter(); featureWriter.write((FeatureCollection)resultGF,writer); String sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.namedPlacesCollection-3.xml"), sresult); } @Test @Order(order=8) public void TransactionDeleteTest() throws Exception { /** * Test 1 : transaction delete for Feature type bridges with a bad property in filter */ QName typeName = new QName("http://www.opengis.net/gml", "Bridges"); ComparisonOpsType pe = new PropertyIsEqualToType(new LiteralType("10972X0137-PONT"), new PropertyNameType("bad"), Boolean.TRUE); FilterType filter = new FilterType(pe); DeleteElementType delete = new DeleteElementType(filter, null, typeName); TransactionType request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, delete); try { worker.transaction(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); assertEquals(ex.getMessage(), "The feature Type {http://www.opengis.net/gml}Bridges does not has such a property: bad"); } /** * Test 2 : transaction delete for Feature type NamedPlaces with a property in filter */ typeName = new QName("http://www.opengis.net/gml", "NamedPlaces"); pe = new PropertyIsEqualToType(new LiteralType("Ashton"), new PropertyNameType("NAME"), Boolean.TRUE); filter = new FilterType(pe); delete = new DeleteElementType(filter, null, typeName); request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, delete); TransactionResponse result = worker.transaction(request); TransactionSummaryType sum = new TransactionSummaryType(0, 0, 1); TransactionResponseType expresult = new TransactionResponseType(sum, null, null, "1.1.0"); assertEquals(expresult, result); /** * we verify that the feature have been deleted */ List<QueryType> queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null)); GetFeatureType requestGF = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object resultGF = worker.getFeature(requestGF); assertTrue(resultGF instanceof FeatureCollectionWrapper); FeatureCollectionWrapper wrapper = (FeatureCollectionWrapper) resultGF; resultGF = wrapper.getFeatureCollection(); StringWriter writer = new StringWriter(); featureWriter.write((FeatureCollection)resultGF,writer); String sresult = writer.toString(); sresult = sresult.replaceAll("timeStamp=\"[^\"]*\" ", "timeStamp=\"\" "); domCompare( FileUtilities.getFileFromResource("org.constellation.wfs.xml.namedPlacesCollection-2.xml"), sresult); } /** * * */ @Test @Order(order=9) public void TransactionInsertTest() throws Exception { /** * Test 1 : transaction insert for Feature type bridges with a bad inputFormat */ final QName typeName = new QName("http://www.opengis.net/gml", "Bridges"); final InsertElementType insert = new InsertElementType(); insert.setInputFormat("bad inputFormat"); final TransactionType request = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, insert); try { worker.transaction(request); fail("Should have raised an error."); } catch (CstlServiceException ex) { assertEquals(ex.getExceptionCode(), INVALID_PARAMETER_VALUE); assertEquals(ex.getLocator(), "inputFormat"); } } @Test @Order(order=10) public void schemaLocationTest() throws Exception { List<QueryType> queries = new ArrayList<>(); queries.add(new QueryType(null, Arrays.asList(new QName("http://www.opengis.net/gml", "NamedPlaces")), null)); GetFeatureType requestGF = new GetFeatureType("WFS", "1.1.0", null, Integer.MAX_VALUE, queries, ResultTypeType.RESULTS, "text/gml; subtype=gml/3.1.1"); Object resultGF = worker.getFeature(requestGF); assertTrue(resultGF instanceof FeatureCollectionWrapper); FeatureCollectionWrapper wrapper = (FeatureCollectionWrapper) resultGF; final Map<String, String> expResult = new HashMap<>(); expResult.put("http://www.opengis.net/gml", "http://geomatys.com/constellation/WS/wfs/test1?request=DescribeFeatureType&version=1.1.0&service=WFS&namespace=xmlns(ns1=http://www.opengis.net/gml)&typename=ns1:NamedPlaces"); assertEquals(wrapper.getSchemaLocations(), expResult); } public static void domCompare(final Object actual, final Object expected) throws Exception { final CstlDOMComparator comparator = new CstlDOMComparator(expected, actual); comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*"); comparator.ignoredAttributes.add("http://www.w3.org/2001/XMLSchema-instance:schemaLocation"); comparator.compare(); } private static String getGmlPrefix(final String xml) { Pattern p = Pattern.compile("xmlns:([^=]+)=\"http://www.opengis.net/gml\""); Matcher matcher = p.matcher(xml); if (matcher.find()) { return matcher.group(1); } return null; } }