/** * Tests case where filter is makes use of 2 different attributes but Query object only requests 1 * of the two attributes. This is a fix for a bug that has occurred. */ @Test public void testFeatureReaderWithQuery() throws Exception { if (url == null) return; Map m = new HashMap(); m.put(WFSDataStoreFactory.URL.key, url); m.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(100000)); WFS_1_0_0_DataStore wfs = (WFS_1_0_0_DataStore) (new WFSDataStoreFactory()).createDataStore(m); FilterFactory2 fac = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); Filter filter = fac.equals(fac.property("NAME"), fac.literal("E 58th St")); Query query = new Query("tiger:tiger_roads", filter); FeatureReader<SimpleFeatureType, SimpleFeature> reader = wfs.getFeatureReader(query, new DefaultTransaction()); int expected = 0; while (reader.hasNext()) { expected++; reader.next(); } query = new Query("tiger:tiger_roads", filter, 100, new String[] {"CFCC"}, ""); reader = wfs.getFeatureReader(query, new DefaultTransaction()); int count = 0; while (reader.hasNext()) { count++; reader.next(); } assertEquals(expected, count); }
private void testVendorParameters(Boolean usePost) throws IOException { if (url == null) return; Map m = new HashMap(); m.put(WFSDataStoreFactory.URL.key, url); m.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(100000)); m.put(WFSDataStoreFactory.PROTOCOL.key, usePost); WFS_1_0_0_DataStore wfs = (WFS_1_0_0_DataStore) (new WFSDataStoreFactory()).createDataStore(m); final WFS100ProtocolHandler originalHandler = wfs.protocolHandler; wfs.protocolHandler = new WFS100ProtocolHandler(null, originalHandler.getConnectionFactory()) { @Override protected WFSCapabilities parseCapabilities(InputStream capabilitiesReader) throws IOException { return originalHandler.getCapabilities(); } @Override public ConnectionFactory getConnectionFactory() { return new ConnectionFactoryWrapper(super.getConnectionFactory()) { @Override public HttpURLConnection getConnection(URL query, HttpMethod method) throws IOException { String[] keyValueArray = query.getQuery().split("&"); Map<String, String> kvp = new HashMap<String, String>(); for (String keyValue : keyValueArray) { String[] skv = keyValue.split("="); kvp.put(skv[0], skv[1]); } // check the vendor params actually made it into the url assertEquals("true", kvp.get("strict")); assertEquals("mysecret", kvp.get("authkey")); assertEquals("low%3A2000000%3Bhigh%3A5000000", kvp.get("viewparams")); return super.getConnection(query, method); } }; } }; Map<String, String> vparams = new HashMap<String, String>(); vparams.put("authkey", "mysecret"); vparams.put("viewparams", "low:2000000;high:5000000"); vparams.put("strict", "true"); Hints hints = new Hints(WFSDataStore.WFS_VENDOR_PARAMETERS, vparams); Query q = new Query("topp:states"); q.setHints(hints); // try with FeatureReader fr = wfs.getFeatureReader(q, Transaction.AUTO_COMMIT); assertTrue(fr.hasNext()); fr.close(); }