CSVDataStoreFactory implements FileDataStoreFactorySpi { @Override public FileDataStore createDataStore(Map<String, Serializable> params) throws IOException { File file = fileFromParams(params); if (file == null) { throw new IllegalArgumentException( "Could not find file from params to create csv data store"); } URI namespace = (URI) NAMESPACEP.lookUp(params); return createDataStoreFromFile(file, namespace, params); }  @Override String getDisplayName(); @Override String getDescription(); @Override Param[] getParametersInfo(); @Override boolean canProcess(Map<String, Serializable> params); @Override boolean isAvailable(); @Override Map<Key, ?> getImplementationHints(); FileDataStore createDataStoreFromFile(File file); FileDataStore createDataStoreFromFile(File file, URI namespace); @Override FileDataStore createDataStore(Map<String, Serializable> params); @Override DataStore createNewDataStore(Map<String, Serializable> params); @Override FileDataStore createDataStore(URL url); @Override String[] getFileExtensions(); @Override boolean canProcess(URL url); @Override String getTypeName(URL url); static final String[] EXTENSIONS; static final Param FILE_PARAM; static final Param URL_PARAM; static final Param NAMESPACEP; static final Param STRATEGYP; static final Param LATFIELDP; static final Param LnGFIELDP; static final Param WKTP; static final Param[] parametersInfo; }
@Test public void testCreateDataStoreFileParams() throws Exception { Map<String, Serializable> fileParams = new HashMap<String, Serializable>(1); fileParams.put("file", file); FileDataStore dataStore = csvDataStoreFactory.createDataStore(fileParams); assertNotNull("Could not create datastore from file params", dataStore); }
@Test public void testCreateDataStoreURLParams() throws Exception { Map<String, Serializable> urlParams = new HashMap<String, Serializable>(1); urlParams.put("url", locationsResource); FileDataStore dataStore = csvDataStoreFactory.createDataStore(urlParams); assertNotNull("Could not create datastore from url params", dataStore); }
@Test public void testCreateDataStoreURL() throws MalformedURLException, IOException { FileDataStore dataStore = csvDataStoreFactory.createDataStore(locationsResource); assertNotNull("Failure creating data store", dataStore); }
@Test public void testInvalidParamsCreation() throws Exception { Map<String, Serializable> params = Collections.emptyMap(); try { csvDataStoreFactory.createDataStore(params); } catch (IllegalArgumentException e) { assertTrue(true); return; } catch (Exception e) { } fail("Did not throw illegal argument exception for null file"); }
@Test public void testCSVStrategyGuess() throws Exception { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("strategy", "guess"); params.put("file", file); CSVDataStore datastore = (CSVDataStore) csvDataStoreFactory.createDataStore(params); CSVStrategy csvStrategy = datastore.getCSVStrategy(); assertEquals("Unexpected strategy", CSVLatLonStrategy.class, csvStrategy.getClass()); }
@Test public void testCSVStrategySpecifiedBadParams() throws Exception { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("strategy", "specify"); params.put("file", file); try { csvDataStoreFactory.createDataStore(params); } catch (IllegalArgumentException e) { return; } fail("Expected illegal argument exception for missing latField and lngField"); }
@Test public void testCSVStrategySpecified() throws Exception { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("strategy", "specify"); params.put("file", file); params.put("latField", "foo"); params.put("lngField", "bar"); CSVDataStore datastore = (CSVDataStore) csvDataStoreFactory.createDataStore(params); CSVStrategy csvStrategy = datastore.getCSVStrategy(); assertEquals("Unexpected strategy", CSVSpecifiedLatLngStrategy.class, csvStrategy.getClass()); }
@Test public void testCSVStrategyWKTMissingWktField() throws IOException { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("strategy", "wkt"); params.put("file", file); try { csvDataStoreFactory.createDataStore(params); } catch (IllegalArgumentException e) { return; } fail("Expected illegal argument exception for missing wktField"); }
@Test public void testCSVStrategyWKT() throws IOException { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("strategy", "wkt"); params.put("wktField", "whatever"); params.put("file", file); CSVDataStore datastore = (CSVDataStore) csvDataStoreFactory.createDataStore(params); CSVStrategy csvStrategy = datastore.getCSVStrategy(); assertEquals("Unexpected strategy", CSVSpecifiedWKTStrategy.class, csvStrategy.getClass()); }