Search in sources :

Example 6 with DataSourceConnector

use of com.sldeditor.datasource.connector.instance.DataSourceConnector in project sldeditor by robward-scisys.

the class DataSourceConnectorTest method testGetConnectionProperties.

/**
 * Test method for
 * {@link com.sldeditor.datasource.connector.instance.DataSourceConnector#getConnectionProperties(com.sldeditor.DataSourcePropertiesInterface)}.
 */
@Test
public void testGetConnectionProperties() {
    DataSourceConnector dsc = new DataSourceConnector();
    assertNull(dsc.getConnectionProperties(null));
    Map<String, Object> expectedPropertyMap = new HashMap<String, Object>();
    expectedPropertyMap.put("server", "localhost");
    expectedPropertyMap.put("port", "5432");
    expectedPropertyMap.put("database", "testdb");
    expectedPropertyMap.put("user", "testuser");
    expectedPropertyMap.put("password", "pasword123");
    DataSourcePropertiesInterface dataSource = new DataSourceProperties(dsc);
    dataSource.setPropertyMap(expectedPropertyMap);
    assertEquals(expectedPropertyMap, dsc.getConnectionProperties(dataSource));
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) HashMap(java.util.HashMap) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Test(org.junit.Test)

Example 7 with DataSourceConnector

use of com.sldeditor.datasource.connector.instance.DataSourceConnector in project sldeditor by robward-scisys.

the class DataSourcePropertiesTest method testEncodeDecodeXML.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#encodeXML(org.w3c.dom.Document, org.w3c.dom.Element, java.lang.String)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#decodeXML(org.w3c.dom.Document, java.lang.String)}.
 */
@Test
public void testEncodeDecodeXML() {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    propertyMap.put("field1", "value1");
    propertyMap.put("field2", "value2");
    propertyMap.put("field3", "value3");
    DataSourceConnectorInterface dsc = new DataSourceConnector();
    DataSourceProperties dsp = new DataSourceProperties(dsc);
    dsp.setPropertyMap(propertyMap);
    dsp.setFilename("testfilename.shp");
    dsp.setPassword("top secret password");
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = null;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Document doc = documentBuilder.newDocument();
    String elementName = "test_data_source_properties";
    Element root = doc.createElement("test");
    doc.appendChild(root);
    dsp.encodeXML(doc, root, elementName);
    // Try null parameters
    dsp.encodeXML(null, null, null);
    assertNull(DataSourceProperties.decodeXML(null, null));
    // Now decode XML
    DataSourcePropertiesInterface decodeDSP = DataSourceProperties.decodeXML(doc, elementName);
    assertEquals(dsp.getConnectionProperties(), decodeDSP.getConnectionProperties());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Document(org.w3c.dom.Document) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 8 with DataSourceConnector

use of com.sldeditor.datasource.connector.instance.DataSourceConnector in project sldeditor by robward-scisys.

the class DataSourcePropertiesTest method testDataSourcePropertiesWithConnector.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#DataSourceProperties(com.sldeditor.DataSourceConnectorInterface)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#setPropertyMap(java.util.Map)}.
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceProperties#getDataSourceConnector()}.
 */
@Test
public void testDataSourcePropertiesWithConnector() {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    propertyMap.put("field1", "value1");
    propertyMap.put("field2", "value2");
    propertyMap.put("field3", "value3");
    DataSourceConnectorInterface dsc = new DataSourceConnector();
    DataSourceProperties dsp = new DataSourceProperties(dsc);
    dsp.setPropertyMap(propertyMap);
    Map<String, Object> actualPropertyMap = dsp.getConnectionProperties();
    assertEquals(propertyMap, actualPropertyMap);
    assertEquals(propertyMap, dsp.getAllConnectionProperties());
    // Is empty
    assertFalse(dsp.isEmpty());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) HashMap(java.util.HashMap) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Test(org.junit.Test)

Example 9 with DataSourceConnector

use of com.sldeditor.datasource.connector.instance.DataSourceConnector in project sldeditor by robward-scisys.

the class DataSourceConnectorTest method testGetDisplayName.

/**
 * Test method for {@link com.sldeditor.datasource.connector.instance.DataSourceConnector#getDisplayName()}.
 */
@Test
public void testGetDisplayName() {
    DataSourceConnector dsc = new DataSourceConnector();
    assertEquals("Database", dsc.getDisplayName());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) Test(org.junit.Test)

Example 10 with DataSourceConnector

use of com.sldeditor.datasource.connector.instance.DataSourceConnector in project sldeditor by robward-scisys.

the class DataSourceConnectorTest method testGetPanel.

/**
 * Test method for {@link com.sldeditor.datasource.connector.instance.DataSourceConnector#getPanel()}.
 */
@Test
public void testGetPanel() {
    DataSourceConnector dsc = new DataSourceConnector();
    assertTrue(dsc.getPanel() != null);
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) Test(org.junit.Test)

Aggregations

DataSourceConnector (com.sldeditor.datasource.connector.instance.DataSourceConnector)12 Test (org.junit.Test)11 DataSourceProperties (com.sldeditor.datasource.impl.DataSourceProperties)5 HashMap (java.util.HashMap)5 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)3 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)3 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)1 DataSourceConnectorEmpty (com.sldeditor.datasource.connector.instance.DataSourceConnectorEmpty)1 File (java.io.File)1 Map (java.util.Map)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1