use of com.sldeditor.datasource.attribute.DataSourceAttributeList in project sldeditor by robward-scisys.
the class DataSourceImplTest method testConnectToInternalDataSource.
/**
* Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}. Test method
* for
* {@link com.sldeditor.datasource.impl.DataSourceImpl#addListener(com.sldeditor.datasource.DataSourceUpdatedInterface)}.
*/
@Test
public void testConnectToInternalDataSource() {
DataSourceImpl ds = new DataSourceImpl();
DummyInternalSLDFile editorFile = new DummyInternalSLDFile();
DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate();
ds.addListener(dataSourceUpdateListener);
ds.addListener(dataSourceUpdateListener);
CreateDataSourceInterface internalDataSource = new CreateInternalDataSource();
CreateDataSourceInterface externalDataSource = new DummyCreateDataSource();
CreateDataSourceInterface inlineDataSource = new DummyCreateDataSource();
ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource);
ds.connect("typeName", editorFile, null);
assertEquals(GeometryTypeEnum.POINT, dataSourceUpdateListener.geometryType);
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList();
assertTrue(fieldList != null);
List<String> actualFieldnameList = new ArrayList<String>();
for (PropertyDescriptor field : fieldList) {
if (!(field instanceof GeometryDescriptorImpl)) {
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
assertFalse(ds.getAttributes(Integer.class).isEmpty());
assertFalse(ds.getAttributes(Double.class).isEmpty());
assertEquals(2, ds.getAttributes(String.class).size());
// Add new field
DataSourceAttributeData dataSourceField = new DataSourceAttributeData("bearing", Double.class, null);
ds.addField(dataSourceField);
assertTrue(ds.getAttributes(Double.class).size() == 2);
// Update field
DataSourceAttributeList attributeData = new DataSourceAttributeList();
ds.readAttributes(null);
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);
ds.updateFields(null);
ds.updateFields(attributeData);
List<String> actualAttributes = ds.getAttributes(Integer.class);
assertTrue(actualAttributes.size() == 2);
FeatureSource<SimpleFeatureType, SimpleFeature> features = ds.getFeatureSource();
try {
assertEquals(1, features.getFeatures().size());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
ds.removeListener(dataSourceUpdateListener);
assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag);
}
Aggregations