Search in sources :

Example 1 with ExtractAttributes

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());
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ArrayList(java.util.ArrayList) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Expression(org.opengis.filter.expression.Expression) Filter(org.opengis.filter.Filter) FunctionImpl(org.geotools.filter.FunctionImpl) Rule(org.geotools.styling.Rule) Test(org.junit.jupiter.api.Test)

Example 2 with ExtractAttributes

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);
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes) Test(org.junit.jupiter.api.Test)

Example 3 with ExtractAttributes

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());
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Filter(org.opengis.filter.Filter) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes) Rule(org.geotools.styling.Rule) Test(org.junit.jupiter.api.Test)

Example 4 with ExtractAttributes

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());
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes) Test(org.junit.jupiter.api.Test)

Example 5 with ExtractAttributes

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());
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Filter(org.opengis.filter.Filter) ExtractAttributes(com.sldeditor.datasource.impl.ExtractAttributes) Rule(org.geotools.styling.Rule) Test(org.junit.jupiter.api.Test)

Aggregations

ExtractAttributes (com.sldeditor.datasource.impl.ExtractAttributes)15 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)14 Test (org.junit.jupiter.api.Test)14 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)11 Rule (org.geotools.styling.Rule)10 Filter (org.opengis.filter.Filter)10 ConcatenateFunction (org.geotools.filter.function.string.ConcatenateFunction)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 DataSourceImpl (com.sldeditor.datasource.impl.DataSourceImpl)1 ArrayList (java.util.ArrayList)1 FunctionImpl (org.geotools.filter.FunctionImpl)1 Expression (org.opengis.filter.expression.Expression)1 Function (org.opengis.filter.expression.Function)1