use of com.sldeditor.datasource.impl.ExtractAttributes in project sldeditor by robward-scisys.
the class ExtractAttributesTest method testFunctionImpl.
@Test
public void testFunctionImpl() {
DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();
StyledLayerDescriptor sld = createTestSLD(dummy);
List<Rule> ruleList = getRuleList(sld);
ExtractAttributes extract = new ExtractAttributes();
Rule rule = DefaultSymbols.createNewRule();
String expectedAttribute = "world";
FunctionImpl function = new ConcatenateFunction();
List<Expression> params = new ArrayList<Expression>();
params.add(ff.property(expectedAttribute));
params.add(ff.property(expectedAttribute));
function.setParameters(params);
Filter filter = ff.equal(ff.literal("not equal"), function, true);
rule.setFilter(filter);
ruleList.clear();
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(String.class, dataSourceField.getType());
}
use of com.sldeditor.datasource.impl.ExtractAttributes in project sldeditor by robward-scisys.
the class ExtractAttributesTest method testNonStandardGeometryNamespace.
/**
* Test sld symbol contains non-default geometry field and non-standard xml namespace.
*
* <p>{@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);
}
use of com.sldeditor.datasource.impl.ExtractAttributes 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.impl.ExtractAttributes 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.impl.ExtractAttributes 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());
}
Aggregations