Search in sources :

Example 6 with DataSourceAttributeModel

use of com.sldeditor.datasource.config.DataSourceAttributeModel 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)

Aggregations

DataSourceAttributeModel (com.sldeditor.datasource.config.DataSourceAttributeModel)6 Test (org.junit.Test)6 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 DataSourceAttributeListInterface (com.sldeditor.datasource.attribute.DataSourceAttributeListInterface)1 ArrayList (java.util.ArrayList)1