Search in sources :

Example 26 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseInputTest method testDeleteConnections.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.database.DatabaseInput#deleteConnections(java.util.List)}.
 */
@Test
public void testDeleteConnections() {
    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.deleteConnections(null);
    // Populate some styles
    List<String> featureClassList = new ArrayList<String>();
    featureClassList.add("Feature Class 1");
    featureClassList.add("Feature Class 2");
    input.populateComplete(connection1, featureClassList);
    List<String> featureClassList2 = new ArrayList<String>();
    featureClassList2.add("Feature Class 3");
    featureClassList2.add("Feature Class 4");
    input.populateComplete(connection2, featureClassList2);
    // Delete a delete connection
    List<DatabaseConnection> connectionList = new ArrayList<DatabaseConnection>();
    connectionList.add(connection1);
    input.deleteConnections(connectionList);
    List<DatabaseConnection> actual = input.getConnectionDetails();
    assertEquals(1, actual.size());
}
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 27 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseInputTest method testDatabaseInput.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.database.DatabaseInput#DatabaseInput(com.sldeditor.common.ToolSelectionInterface)}.
 */
@Test
public void testDatabaseInput() {
    DatabaseInput input = new DatabaseInput(ToolManager.getInstance());
    input.readPropertyFile();
    FSTree tree = new FSTree();
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode("Root");
        DefaultTreeModel model = new DefaultTreeModel(rootNode);
        input.populate(tree, model, rootNode);
        List<SLDDataInterface> sldDataList = input.open(null);
        assertNull(sldDataList);
        DatabaseConnection connection1 = DatabaseConnectionFactory.createGeoPackage();
        String featureClassName = "test feature class";
        DatabaseFeatureClassNode fcTreeNode = new DatabaseFeatureClassNode(input, connection1, featureClassName);
        Map<String, String> connectionDataMap = new HashMap<String, String>();
        connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test.gpkg");
        connection1.setConnectionDataMap(connectionDataMap);
        // Try with no known database connections
        SelectedFiles actualSLDContents = input.getSLDContents(fcTreeNode);
        assertNotNull(actualSLDContents);
        assertTrue(actualSLDContents.isDataSource());
        // 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);
        List<SLDDataInterface> sldDataContentsList = input.getSLDContents(fcTreeNode).getSldData();
        assertEquals(0, sldDataContentsList.size());
        // Try saving a null object
        assertFalse(input.save(null));
        // Check how many connections we have
        assertEquals(2, input.getConnectionDetails().size());
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DatabaseFeatureClassNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Test(org.junit.Test)

Example 28 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseInputTest method testDisconnect.

/**
 * Test method for {@link com.sldeditor.extension.filesystem.database.DatabaseInput#disconnect(java.util.List)}.
 */
@Test
public void testDisconnect() {
    PropertyManagerFactory.getInstance().setPropertyFile(configPropertiesFile);
    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 passing null
    input.disconnect(null);
    // Try disconnecting from one database
    List<DatabaseConnection> connectionList = new ArrayList<DatabaseConnection>();
    connectionList.add(connection1);
    input.disconnect(connectionList);
    // Try disconnecting from to 2
    connectionList.add(connection2);
    input.disconnect(connectionList);
}
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 29 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection 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 30 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection 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)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)33 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)11 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)10 HashMap (java.util.HashMap)10 DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)7 File (java.io.File)6 NodeInterface (com.sldeditor.common.NodeInterface)3 DatabaseNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)2 DatabaseOverallNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseOverallNode)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)2 FileNotFoundException (java.io.FileNotFoundException)2 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Param (org.geotools.data.DataAccessFactory.Param)2 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1