Search in sources :

Example 16 with DataSourceAttributeData

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);
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) DataSourceImpl(com.sldeditor.datasource.impl.DataSourceImpl) CreateDataSourceInterface(com.sldeditor.datasource.impl.CreateDataSourceInterface) ArrayList(java.util.ArrayList) CreateExternalDataSource(com.sldeditor.datasource.impl.CreateExternalDataSource) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Test(org.junit.Test)

Example 17 with DataSourceAttributeData

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());
}
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.Test)

Example 18 with DataSourceAttributeData

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());
}
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.Test)

Example 19 with DataSourceAttributeData

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

Example 20 with DataSourceAttributeData

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

Aggregations

DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)40 Test (org.junit.Test)23 ExtractAttributes (com.sldeditor.datasource.impl.ExtractAttributes)12 ArrayList (java.util.ArrayList)11 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 Rule (org.geotools.styling.Rule)8 Filter (org.opengis.filter.Filter)8 LineString (com.vividsolutions.jts.geom.LineString)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)4 DataSourceAttributeList (com.sldeditor.datasource.attribute.DataSourceAttributeList)4 Point (com.vividsolutions.jts.geom.Point)4 IOException (java.io.IOException)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 DataSourceImpl (com.sldeditor.datasource.impl.DataSourceImpl)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)3 SLDData (com.sldeditor.common.data.SLDData)2 CreateDataSourceInterface (com.sldeditor.datasource.impl.CreateDataSourceInterface)2