Search in sources :

Example 26 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeDataTest method testDataSourceAttributeDataNameClassOfQObject.

/**
 * Test method for {@link com.sldeditor.datasource.attribute.DataSourceAttributeData#DataSourceAttributeData(org.opengis.feature.type.Name, java.lang.Class, java.lang.Object)}.
 */
@Test
public void testDataSourceAttributeDataNameClassOfQObject() {
    String expectedName = "test name";
    Class<?> expectedType = Integer.class;
    Object expectedValue = Integer.valueOf(42);
    DataSourceAttributeData dsa = new DataSourceAttributeData(expectedName, expectedType, expectedValue);
    assertTrue(expectedName.compareTo(dsa.getName()) == 0);
    assertEquals(expectedType, dsa.getType());
    assertEquals(expectedValue, dsa.getValue());
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Test(org.junit.Test)

Example 27 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeDataTest method testSetName.

/**
 * Test method for {@link com.sldeditor.datasource.attribute.DataSourceAttributeData#setName(org.opengis.feature.type.Name)}.
 */
@Test
public void testSetName() {
    String expectedName1 = "test name";
    Class<?> expectedType = Integer.class;
    Object expectedValue = Integer.valueOf(42);
    DataSourceAttributeData dsa = new DataSourceAttributeData(expectedName1, expectedType, expectedValue);
    String expectedName2 = "updated test name";
    dsa.setName(expectedName2);
    assertTrue(expectedName2.compareTo(dsa.getName()) == 0);
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) Test(org.junit.Test)

Example 28 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeListTest method testDataSourceAttributeList.

/**
 * Test method for
 * {@link com.sldeditor.datasource.attribute.DataSourceAttributeList#DataSourceAttributeList()}.
 */
@Test
public void testDataSourceAttributeList() {
    List<DataSourceAttributeData> expectedAttributeList = new ArrayList<DataSourceAttributeData>();
    expectedAttributeList.add(new DataSourceAttributeData("field 1", String.class, "test value"));
    expectedAttributeList.add(new DataSourceAttributeData("field 2", Double.class, 42.0));
    expectedAttributeList.add(new DataSourceAttributeData("field 3", Integer.class, 22));
    expectedAttributeList.add(new DataSourceAttributeData("field 4", Long.class, 454));
    DataSourceAttributeList dsaList = new DataSourceAttributeList();
    dsaList.setData(expectedAttributeList);
    assertEquals(expectedAttributeList, dsaList.getData());
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DataSourceAttributeList(com.sldeditor.datasource.attribute.DataSourceAttributeList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 29 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class DataSourceAttributeModelTest method testPopulate.

/**
 * Test method for {@link com.sldeditor.datasource.config.DataSourceAttributeModel#populate(java.util.List)}.
 * Test method for {@link com.sldeditor.datasource.config.DataSourceAttributeModel#getValueAt(int, int)}.
 * Test method for {@link com.sldeditor.datasource.config.DataSourceAttributeModel#setValueAt(java.lang.Object, int, int)}.
 * Test method for {@link com.sldeditor.datasource.config.DataSourceAttributeModel#retrieveData()}.
 * Test method for {@link com.sldeditor.datasource.config.DataSourceAttributeModel#getAttributeData()}.
 */
@Test
public void testPopulate() {
    DataSourceAttributeModel model = new DataSourceAttributeModel();
    assertEquals(0, model.getRowCount());
    String expectedName1 = "test name1";
    Class<?> expectedType1 = Integer.class;
    Object expectedValue1 = Integer.valueOf(42);
    DataSourceAttributeData dsa1 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue1);
    String expectedName2 = "test name2";
    Class<?> expectedType2 = Integer.class;
    Object expectedValue2 = Integer.valueOf(53);
    DataSourceAttributeData dsa2 = new DataSourceAttributeData(expectedName2, expectedType2, expectedValue2);
    List<DataSourceAttributeData> attributeList = new ArrayList<DataSourceAttributeData>();
    attributeList.add(dsa1);
    attributeList.add(dsa2);
    model.populate(null);
    model.populate(attributeList);
    assertEquals(attributeList.size(), model.getRowCount());
    // Check get value at
    assertNull(model.getValueAt(0, 9));
    assertNull(model.getValueAt(0, -1));
    assertNull(model.getValueAt(-1, 0));
    assertNull(model.getValueAt(attributeList.size(), 0));
    assertTrue(expectedName1.compareTo(((String) model.getValueAt(0, 0))) == 0);
    String actualType = (String) model.getValueAt(0, 1);
    assertTrue(expectedType1.getSimpleName().compareTo(actualType) == 0);
    assertEquals(expectedValue1, model.getValueAt(0, 2));
    assertTrue(expectedName2.compareTo(((String) model.getValueAt(1, 0))) == 0);
    actualType = (String) model.getValueAt(1, 1);
    assertTrue(expectedType2.getSimpleName().compareTo(actualType) == 0);
    assertEquals(expectedValue2, model.getValueAt(1, 2));
    // Check set value at
    // Set Value At - illegal values
    model.setValueAt(null, 0, 9);
    model.setValueAt(null, 0, -1);
    model.setValueAt(null, -1, 0);
    model.setValueAt(null, attributeList.size(), 0);
    // Set Value At - legal values
    String expectedName3 = "test name3";
    Class<?> expectedType3 = String.class;
    model.setValueAt(expectedName3, 0, 0);
    assertTrue(expectedName3.compareTo(((String) model.getValueAt(0, 0))) == 0);
    model.setValueAt(expectedType3.getSimpleName(), 1, 1);
    actualType = (String) model.getValueAt(1, 1);
    assertTrue(expectedType3.getSimpleName().compareTo(actualType) == 0);
    Object expectedValue3 = String.valueOf(42);
    model.setValueAt(expectedValue3, 1, 2);
    assertEquals(expectedValue3, model.getValueAt(1, 2));
    // Retrieve data
    List<DataSourceAttributeData> actualAttributeList = model.retrieveData();
    assertEquals(attributeList.size(), actualAttributeList.size());
    assertTrue(expectedName3.compareTo(actualAttributeList.get(0).getName()) == 0);
    assertEquals(expectedType3, actualAttributeList.get(1).getType());
    assertEquals(expectedValue3, actualAttributeList.get(1).getValue());
    // Get attribute data
    DataSourceAttributeListInterface attributeDataImpl = model.getAttributeData();
    actualAttributeList = attributeDataImpl.getData();
    assertEquals(attributeList.size(), actualAttributeList.size());
    assertTrue(expectedName3.compareTo(actualAttributeList.get(0).getName()) == 0);
    assertEquals(expectedType3, actualAttributeList.get(1).getType());
    assertEquals(expectedValue3, actualAttributeList.get(1).getValue());
    // Try and set an unknown type
    model.setValueAt(DataSourceAttributeModel.class.getSimpleName(), 0, 1);
    assertNull(model.getValueAt(0, 1));
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DataSourceAttributeModel(com.sldeditor.datasource.config.DataSourceAttributeModel) ArrayList(java.util.ArrayList) DataSourceAttributeListInterface(com.sldeditor.datasource.attribute.DataSourceAttributeListInterface) Test(org.junit.Test)

Example 30 with DataSourceAttributeData

use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.

the class CreateInternalDataSource method addFields.

/**
 * Adds the fields.
 *
 * @param attrDescList the attribute descriptor list
 * @param b the feature type builder
 * @param fieldList the field list
 */
private void addFields(List<AttributeDescriptor> attrDescList, ExtendedSimpleFeatureTypeBuilder b, List<DataSourceAttributeData> fieldList) {
    for (DataSourceAttributeData field : fieldList) {
        Class<?> fieldType = field.getType();
        if (!isGeometryField(field.getType())) {
            AttributeDescriptor attributeDescriptor = b.createAttributeDescriptor(field.getName(), fieldType);
            attrDescList.add(attributeDescriptor);
        }
    }
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

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