use of com.sldeditor.datasource.impl.CreateExternalDataSource in project sldeditor by robward-scisys.
the class DataSourceImplTest method testConnectToExternalDataSource.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}.
*/
@Test
public void testConnectToExternalDataSource() {
DataSourceImpl ds = new DataSourceImpl();
DummyExternalSLDFile editorFile = new DummyExternalSLDFile();
DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
ds.addListener(dataSourceUpdateListener);
CreateDataSourceInterface internalDataSource = new DummyCreateDataSource();
CreateDataSourceInterface externalDataSource = new CreateExternalDataSource();
CreateDataSourceInterface inlineDataSource = new DummyCreateDataSource();
ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
ds.connect(editorFile.getTypeName(), editorFile, null);
assertEquals(GeometryTypeEnum.POINT, dataSourceUpdateListener.geometryType);
assertTrue(dataSourceUpdateListener.isConnectedToDataSourceFlag);
Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
assertTrue(fieldList != null);
List<String> actualFieldnameList = new ArrayList<String>();
for (PropertyDescriptor field : fieldList) {
actualFieldnameList.add(field.getName().getLocalPart());
}
// Check fields extracted ok
List<String> expectedFieldList = editorFile.getExpectedFieldList();
assertTrue(expectedFieldList.size() == actualFieldnameList.size());
// Not assuming fields are in the same order
int count = 0;
for (String fieldName : actualFieldnameList) {
if (expectedFieldList.contains(fieldName)) {
count++;
}
}
assertTrue(expectedFieldList.size() == count);
// Check for fields of certain types
assertEquals(1, ds.getAttributes(Integer.class).size());
assertEquals(1, ds.getAttributes(Long.class).size());
assertEquals(1, ds.getAttributes(Double.class).size());
assertEquals(1, ds.getAttributes(String.class).size());
// Add new field - shouldn't work because connections to external data sources are fixed
DataSourceAttributeData dataSourceField = new DataSourceAttributeData("bearing", Double.class, null);
ds.addField(dataSourceField);
assertTrue(ds.getAttributes(Double.class).size() == 1);
// Update field
DataSourceAttributeList attributeData = new DataSourceAttributeList();
ds.readAttributes(attributeData);
assertTrue(ds.getPropertyDescriptorList().size() == attributeData.getData().size());
List<DataSourceAttributeData> attributeDataList = attributeData.getData();
DataSourceAttributeData data = attributeDataList.remove(2);
data.setType(Integer.class);
attributeDataList.add(2, data);
// Update fields - shouldn't work because connections to external data sources are fixed
ds.updateFields(attributeData);
assertTrue(ds.getAttributes(Integer.class).size() == 1);
FeatureSource<SimpleFeatureType, SimpleFeature> features = ds.getFeatureSource();
try {
assertTrue(features.getFeatures().size() > 1);
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
}
use of com.sldeditor.datasource.impl.CreateExternalDataSource 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);
}
Aggregations