use of com.sldeditor.datasource.attribute.DataSourceAttributeData 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.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class ExtractAttributesTest method testFilter.
/**
* Test filter.
*/
@Test
public void testFilter() {
DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();
StyledLayerDescriptor sld = createTestSLD(dummy);
List<Rule> ruleList = getRuleList(sld);
ExtractAttributes extract = new ExtractAttributes();
Rule rule = DefaultSymbols.createNewRule();
// Try it 1) property 2) Literal
Filter filter = ff.greater(ff.property("width"), ff.literal(42.1));
rule.setFilter(filter);
ruleList.add(rule);
extract.extractDefaultFields(sld);
// Check fields extracted ok
List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
assertEquals(1, actualFieldnameList.size());
DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
assertEquals(Double.class, dataSourceField.getType());
// Check geometry fields extracted ok
List<String> actualGeometryFields = extract.getGeometryFields();
assertEquals(1, actualGeometryFields.size());
// Try it 1) literal 2) property
filter = ff.greater(ff.literal(42.1), ff.property("dble"));
rule.setFilter(filter);
ruleList.clear();
ruleList.add(rule);
extract.extractDefaultFields(sld);
// Check fields extracted ok
actualFieldnameList = extract.getFields();
assertEquals(2, actualFieldnameList.size());
dataSourceField = actualFieldnameList.get(0);
assertEquals(Double.class, dataSourceField.getType());
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class ExtractAttributesTest method testIsBetween.
@Test
public void testIsBetween() {
DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();
StyledLayerDescriptor sld = createTestSLD(dummy);
List<Rule> ruleList = getRuleList(sld);
Rule rule = DefaultSymbols.createNewRule();
// Try isBetween
Filter filter = ff.between(ff.property("test"), ff.literal("1.23"), ff.literal(4));
rule.setFilter(filter);
ruleList.clear();
ruleList.add(rule);
ExtractAttributes extract = new ExtractAttributes();
extract.extractDefaultFields(sld);
// Check fields extracted ok
List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
assertEquals(1, actualFieldnameList.size());
DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
assertEquals(Double.class, dataSourceField.getType());
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class ExtractAttributesTest method testAddDefaultFields.
/**
* Test method for
* {@link com.sldeditor.datasource.impl.ExtractAttributes#addDefaultFields(org.geotools.feature.simple.SimpleFeatureTypeBuilder, java.lang.String)}.
*/
@Test
public void testAddDefaultFields() {
DummyInternalSLDFile dummy = new DummyInternalSLDFile();
ExtractAttributes extract = new ExtractAttributes();
extract.extractDefaultFields(SLDUtils.createSLDFromString(dummy.getSLDData()));
// Check fields extracted ok
List<String> expectedFieldList = dummy.getExpectedFieldList();
List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
assertTrue(expectedFieldList.size() == actualFieldnameList.size());
// Not assuming fields are in the same order
int count = 0;
for (DataSourceAttributeData dataSourceField : actualFieldnameList) {
if (expectedFieldList.contains(dataSourceField.getName())) {
count++;
}
}
assertTrue(expectedFieldList.size() == count);
// Check geometry fields extracted ok
List<String> actualGeometryFields = extract.getGeometryFields();
assertEquals(0, actualGeometryFields.size());
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class ExtractAttributesTest method testNonStandardGeometryNamespace.
/**
* Test sld symbol contains non-default geometry field and non-standard xml namespace.
*
* {@link com.sldeditor.datasource.impl.ExtractAttributes#addDefaultFields(org.geotools.feature.simple.SimpleFeatureTypeBuilder, java.lang.String)}.
*/
@Test
public void testNonStandardGeometryNamespace() {
DummyInternalSLDFile3 dummy = new DummyInternalSLDFile3();
ExtractAttributes extract = new ExtractAttributes();
extract.extractDefaultFields(SLDUtils.createSLDFromString(dummy.getSLDData()));
// Check fields extracted ok - should be none
List<String> expectedFieldList = dummy.getExpectedFieldList();
List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
assertTrue(expectedFieldList.size() == actualFieldnameList.size());
// Not assuming fields are in the same order
int count = 0;
for (DataSourceAttributeData dataSourceField : actualFieldnameList) {
if (expectedFieldList.contains(dataSourceField.getName())) {
count++;
}
}
assertTrue(expectedFieldList.size() == count);
// Check geometry fields extracted ok
List<String> actualGeometryFields = extract.getGeometryFields();
assertEquals(1, actualGeometryFields.size());
String expectedGeometryFieldName = dummy.getExpectedGeometryFieldList().get(0);
assertTrue(expectedGeometryFieldName.compareTo(actualGeometryFields.get(0)) == 0);
}
Aggregations