Search in sources :

Example 11 with DatabaseInput

use of com.sldeditor.extension.filesystem.database.DatabaseInput in project sldeditor by robward-scisys.

the class DatabaseInputTest method testConnect.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.database.DatabaseInput#connect(java.util.List)}.
 */
@Test
public void testConnect() {
    DatabaseInput input = new DatabaseInput(null);
    DatabaseConnection connection1 = DatabaseConnectionFactory.createGeoPackage();
    Map<String, String> connectionDataMap = new HashMap<String, String>();
    connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test.gpkg");
    connection1.setConnectionDataMap(connectionDataMap);
    // Add some database connections
    input.addNewConnection(connection1);
    DatabaseConnection connection2 = DatabaseConnectionFactory.createGeoPackage();
    Map<String, String> connectionDataMap2 = new HashMap<String, String>();
    connectionDataMap2.put(GeoPkgDataStoreFactory.DATABASE.key, "test2.gpkg");
    connection2.setConnectionDataMap(connectionDataMap2);
    input.addNewConnection(connection2);
    input.addNewConnection(null);
    input.connect(null);
    // Try connecting to one database
    List<DatabaseConnection> connectionList = new ArrayList<DatabaseConnection>();
    connectionList.add(connection1);
    // Try passing null
    input.connect(connectionList);
    // Try connecting to 2
    connectionList.add(connection2);
    input.connect(connectionList);
    assertTrue(input.isConnected(connection1));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Test(org.junit.Test)

Example 12 with DatabaseInput

use of com.sldeditor.extension.filesystem.database.DatabaseInput in project sldeditor by robward-scisys.

the class DatabaseInputTest method testUpdateConnectionDetails.

/**
 * Test method for
 * {@link com.sldeditor.extension.filesystem.database.DatabaseInput#updateConnectionDetails(com.sldeditor.common.data.DatabaseConnection, com.sldeditor.common.data.DatabaseConnection)}.
 */
@Test
public void testUpdateConnectionDetails() {
    DatabaseInput input = new DatabaseInput(null);
    // Add some database connections
    DatabaseConnection connection1 = DatabaseConnectionFactory.createGeoPackage();
    Map<String, String> connectionDataMap = new HashMap<String, String>();
    connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test.gpkg");
    connection1.setConnectionDataMap(connectionDataMap);
    input.addNewConnection(connection1);
    DatabaseConnection connection2 = DatabaseConnectionFactory.createGeoPackage();
    Map<String, String> connectionDataMap2 = new HashMap<String, String>();
    connectionDataMap2.put(GeoPkgDataStoreFactory.DATABASE.key, "test2.gpkg");
    connection2.setConnectionDataMap(connectionDataMap2);
    input.addNewConnection(connection2);
    // Try null parameters
    input.updateConnectionDetails(null, null);
    // Delete connection details
    List<DatabaseConnection> listToDelete = new ArrayList<DatabaseConnection>();
    listToDelete.add(connection1);
    input.deleteConnections(listToDelete);
    DatabaseConnection connection1Updated = DatabaseConnectionFactory.createGeoPackage();
    Map<String, String> connectionDataMap3 = new HashMap<String, String>();
    connectionDataMap3.put(GeoPkgDataStoreFactory.DATABASE.key, "updated test.gpkg");
    connection1Updated.setConnectionDataMap(connectionDataMap3);
    input.addNewConnection(connection1Updated);
    // Update the connection details
    input.updateConnectionDetails(connection1, connection1Updated);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Test(org.junit.Test)

Example 13 with DatabaseInput

use of com.sldeditor.extension.filesystem.database.DatabaseInput in project sldeditor by robward-scisys.

the class DatabaseInputTest method testGetNodeTypes.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.database.DatabaseInput#getNodeTypes()}.
 */
@Test
public void testGetNodeTypes() {
    DatabaseInput input = new DatabaseInput(null);
    assertTrue(input.getNodeTypes().isEmpty());
}
Also used : DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) Test(org.junit.Test)

Example 14 with DatabaseInput

use of com.sldeditor.extension.filesystem.database.DatabaseInput in project sldeditor by robward-scisys.

the class DatabaseConnectionToolTest method testDatabaseConnectionTool.

/**
 * Test method for
 * {@link com.sldeditor.tool.databaseconnection.DatabaseConnectionTool#DatabaseConnectionTool(com.sldeditor.tool.databaseconnection.DatabaseConnectStateInterface)}.
 */
@Test
public void testDatabaseConnectionTool() {
    TestDatabaseConnectState state = new TestDatabaseConnectState();
    TestDatabaseConnectionTool testObj = new TestDatabaseConnectionTool(state);
    testObj.setSelectedItems(null, null);
    List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
    DatabaseConnection connection = DatabaseConnectionFactory.createGeoPackage();
    nodeTypeList.add(new DatabaseNode(new DatabaseInput(ToolManager.getInstance()), connection));
    File parent = new File("");
    String filename = "test.gpkg";
    FileTreeNode fileTreeNode = null;
    try {
        fileTreeNode = new FileTreeNode(parent, filename);
        fileTreeNode.setFileCategory(FileTreeNodeTypeEnum.DATABASE);
        nodeTypeList.add(fileTreeNode);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    testObj.setSelectedItems(nodeTypeList, null);
    testObj.populateComplete(null);
    assertNotNull(testObj.getPanel());
    List<Class<?>> uniqueNodeTypeList = new ArrayList<Class<?>>();
    List<SLDDataInterface> sldDataList = null;
    assertFalse(testObj.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
    uniqueNodeTypeList.add(String.class);
    assertTrue(testObj.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
    nodeTypeList.remove(0);
    assertTrue(testObj.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
    testObj.testConnect();
    testObj.testDisconnect();
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) DatabaseNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) File(java.io.File) NodeInterface(com.sldeditor.common.NodeInterface) Test(org.junit.Test)

Aggregations

DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)14 Test (org.junit.Test)13 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)7 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 NodeInterface (com.sldeditor.common.NodeInterface)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 FSTree (com.sldeditor.datasource.extension.filesystem.node.FSTree)1 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)1 DatabaseNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode)1 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)1 FileSystemInput (com.sldeditor.extension.filesystem.file.FileSystemInput)1 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1