Search in sources :

Example 6 with DataSourceInfo

use of com.sldeditor.datasource.impl.DataSourceInfo in project sldeditor by robward-scisys.

the class DataSourceInfoTest method testSetTypeName.

/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.DataSourceInfo#setTypeName(java.lang.String)}. Test
 * method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getTypeName()}.
 */
@Test
public void testSetTypeName() {
    DataSourceInfo ds = new DataSourceInfo();
    String expectedTypeName = "test type name";
    ds.setTypeName(expectedTypeName);
    assertEquals(expectedTypeName, ds.getTypeName());
    ds.reset();
    assertNull(ds.getTypeName());
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) Test(org.junit.Test)

Example 7 with DataSourceInfo

use of com.sldeditor.datasource.impl.DataSourceInfo in project sldeditor by robward-scisys.

the class CreateExternalDataSourceTest method testConnect.

/**
 * Test method for {@link com.sldeditor.datasource.impl.CreateExternalDataSource#connect(com.sldeditor.datasource.SLDEditorFileInterface)}.
 */
@Test
public void testConnect() {
    CreateExternalDataSource ds = new CreateExternalDataSource();
    List<DataSourceInfo> dataSourceInfoList = ds.connect(null, null, null);
    DataSourceInfo dsInfo = dataSourceInfoList.get(0);
    assertTrue(dsInfo != null);
    assertNull(dsInfo.getDataStore());
    assertNull(dsInfo.getTypeName());
    DummyExternalSLDFile dummyExternalSLDFile = new DummyExternalSLDFile();
    SLDEditorFileInterface sldEditor = dummyExternalSLDFile;
    dataSourceInfoList = ds.connect(dummyExternalSLDFile.getTypeName(), null, sldEditor);
    dsInfo = dataSourceInfoList.get(0);
    assertTrue(dsInfo != null);
    assertTrue(dsInfo.getTypeName() != null);
    assertTrue(dsInfo.getDataStore() != null);
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) SLDEditorFileInterface(com.sldeditor.datasource.SLDEditorFileInterface) CreateExternalDataSource(com.sldeditor.datasource.impl.CreateExternalDataSource) Test(org.junit.Test)

Example 8 with DataSourceInfo

use of com.sldeditor.datasource.impl.DataSourceInfo in project sldeditor by robward-scisys.

the class DataSourceInfoTest method testDataStore.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getDataStore()}. Test
 * method for
 * {@link com.sldeditor.datasource.impl.DataSourceInfo#setDataStore(org.geotools.data.DataStore)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#unloadDataStore()}.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataStore() {
    File file = new File("example.shp");
    Map map = new HashMap();
    try {
        map.put("url", file.toURI().toURL());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        DataStore dataStore = DataStoreFinder.getDataStore(map);
        DataSourceInfo ds = new DataSourceInfo();
        ds.setDataStore(dataStore);
        assertEquals(dataStore, ds.getDataStore());
        ds.unloadDataStore();
        ds.reset();
        assertNull(ds.getDataStore());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with DataSourceInfo

use of com.sldeditor.datasource.impl.DataSourceInfo in project sldeditor by robward-scisys.

the class DataSourceInfoTest method testGetFeatureStore.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureStore()}. Test
 * method for
 * {@link com.sldeditor.datasource.impl.DataSourceInfo#setSchema(org.opengis.feature.type.FeatureType)}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatureStore() {
    URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
        DataSourceInfo dsInfo = new DataSourceInfo();
        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        dsInfo.setSchema(schema);
        assertNull(dsInfo.getFeatureStore());
        dsInfo.setDataStore(dataStore);
        FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = dsInfo.getFeatureStore();
        assertTrue(featureStore != null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 10 with DataSourceInfo

use of com.sldeditor.datasource.impl.DataSourceInfo in project sldeditor by robward-scisys.

the class DataSourceInfoTest method testGetPropertyDescriptorList.

/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.DataSourceInfo#getPropertyDescriptorList()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetPropertyDescriptorList() {
    URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
        DataSourceInfo dsInfo = new DataSourceInfo();
        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        assertNull(dsInfo.getPropertyDescriptorList());
        dsInfo.setSchema(schema);
        Collection<PropertyDescriptor> fieldList = dsInfo.getPropertyDescriptorList();
        assertTrue(fieldList.size() == 3);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test)

Aggregations

DataSourceInfo (com.sldeditor.datasource.impl.DataSourceInfo)10 Test (org.junit.Test)10 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DataStore (org.geotools.data.DataStore)6 URL (java.net.URL)5 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 SLDEditorFileInterface (com.sldeditor.datasource.SLDEditorFileInterface)2 CreateExternalDataSource (com.sldeditor.datasource.impl.CreateExternalDataSource)1 CreateInternalDataSource (com.sldeditor.datasource.impl.CreateInternalDataSource)1 GeometryTypeEnum (com.sldeditor.datasource.impl.GeometryTypeEnum)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1