Search in sources :

Example 1 with DataSourceProperties

use of com.sldeditor.datasource.impl.DataSourceProperties in project sldeditor by robward-scisys.

the class DataSourcePropertiesTest method testDataSourcePropertiesNoConnector.

/**
 * 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#setFilename(java.lang.String)}. Test
 * method for {@link com.sldeditor.datasource.impl.DataSourceProperties#getFilename()}. Test
 * method for {@link
 * com.sldeditor.datasource.impl.DataSourceProperties#getDataSourceConnector()}.
 */
@Test
public void testDataSourcePropertiesNoConnector() {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    propertyMap.put("field1", "value1");
    propertyMap.put("field2", "value2");
    propertyMap.put("field3", "value3");
    DataSourceProperties dsp = new DataSourceProperties(null);
    dsp.setPropertyMap(propertyMap);
    Map<String, Object> actualPropertyMap = dsp.getConnectionProperties();
    assertEquals(propertyMap, actualPropertyMap);
    assertEquals(propertyMap, dsp.getAllConnectionProperties());
    // Make sure filename key does not exist
    assertFalse(actualPropertyMap.containsKey("url"));
    String expectedFilename = "this is a filename";
    dsp.setFilename(expectedFilename);
    actualPropertyMap = dsp.getConnectionProperties();
    assertTrue(actualPropertyMap.containsKey("url"));
    assertEquals(expectedFilename, dsp.getFilename());
    // Is empty
    assertTrue(dsp.isEmpty());
}
Also used : HashMap(java.util.HashMap) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) Test(org.junit.jupiter.api.Test)

Example 2 with DataSourceProperties

use of com.sldeditor.datasource.impl.DataSourceProperties 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.jupiter.api.Test)

Example 3 with DataSourceProperties

use of com.sldeditor.datasource.impl.DataSourceProperties 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.jupiter.api.Test)

Example 4 with DataSourceProperties

use of com.sldeditor.datasource.impl.DataSourceProperties in project sldeditor by robward-scisys.

the class MissingSLDAttributesTest method testCheckAttributes.

/**
 * Test method for {@link
 * com.sldeditor.datasource.checks.MissingSLDAttributes#checkAttributes(com.sldeditor.datasource.SLDEditorFileInterface)}.
 */
@Test
void testCheckAttributes() {
    MissingSLDAttributes obj = new MissingSLDAttributes();
    obj.checkAttributes(null);
    DummyInternalSLDFile3 testSLD = new DummyInternalSLDFile3();
    SLDDataInterface sldData = testSLD.getSLDData();
    SLDEditorFile.destroyInstance();
    SelectedSymbol.destroyInstance();
    SelectedSymbol.getInstance().setSld(testSLD.getSLD());
    SLDEditorFile editorFile = SLDEditorFile.getInstance();
    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);
    List<DataSourceAttributeData> fieldList = new ArrayList<DataSourceAttributeData>();
    fieldList.add(new DataSourceAttributeData("Field 1", String.class, null));
    fieldList.add(new DataSourceAttributeData("Field 2", Double.class, null));
    fieldList.add(new DataSourceAttributeData("Field 3", Double.class, null));
    // Try when no fields have been specified
    obj.checkAttributes(editorFile);
    editorFile.setSLDData(sldData);
    obj.checkAttributes(editorFile);
    // Specify the field list
    sldData.setFieldList(fieldList);
    sldData.setDataSourceProperties(dsp);
    editorFile.setDataSource(dsp);
    obj.checkAttributes(editorFile);
    // Tidy up
    SLDEditorFile.destroyInstance();
    SelectedSymbol.destroyInstance();
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MissingSLDAttributes(com.sldeditor.datasource.checks.MissingSLDAttributes) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) DummyInternalSLDFile3(com.sldeditor.test.unit.datasource.impl.DummyInternalSLDFile3) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) Test(org.junit.jupiter.api.Test)

Example 5 with DataSourceProperties

use of com.sldeditor.datasource.impl.DataSourceProperties 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.jupiter.api.Test)

Aggregations

DataSourceProperties (com.sldeditor.datasource.impl.DataSourceProperties)9 Test (org.junit.jupiter.api.Test)8 DataSourceConnector (com.sldeditor.datasource.connector.instance.DataSourceConnector)6 HashMap (java.util.HashMap)5 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)4 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)4 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 MissingSLDAttributes (com.sldeditor.datasource.checks.MissingSLDAttributes)1 DummyInternalSLDFile3 (com.sldeditor.test.unit.datasource.impl.DummyInternalSLDFile3)1 File (java.io.File)1 ArrayList (java.util.ArrayList)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