Search in sources :

Example 21 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class WizardConnectionController method showEditConnectionDialog.

@Bindable
public void showEditConnectionDialog() {
    datasourceModel.setEditing(true);
    if (databaseDialog != null) {
        IDatabaseConnection connection = datasourceModel.getSelectedRelationalConnection();
        previousConnectionName = connection.getName();
        existingConnectionName = previousConnectionName;
        DatabaseConnection editConnection = new DatabaseConnection();
        copyDatabaseConnectionProperties(connection, editConnection);
        databaseDialog.setDatabaseConnection(editConnection);
        databaseDialog.show();
    } else {
        databaseDialog = new GwtDatabaseDialog(databaseTypeHelper, GWT.getModuleBaseURL() + "dataaccess-databasedialog.xul", // $NON-NLS-1$
        connectionSetter);
    }
}
Also used : GwtDatabaseDialog(org.pentaho.ui.database.gwt.GwtDatabaseDialog) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 22 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class InMemoryConnectionServiceImplTest method testGetConnectionByName.

@Test
public void testGetConnectionByName() {
    try {
        InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
        List<IDatabaseConnection> conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 0);
        IDatabaseConnection connection = new DatabaseConnection();
        connection.setName("Connection 1");
        serv.addConnection(connection);
        connection = new DatabaseConnection();
        connection.setName("Connection 2");
        serv.addConnection(connection);
        connection = serv.getConnectionByName("Connection 2");
        assertTrue(connection != null && connection.getName().equals("Connection 2"));
        try {
            connection = serv.getConnectionByName("Connection 5");
            fail();
        } catch (Exception ex) {
        }
    } catch (Exception ex) {
        fail();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 23 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class InMemoryConnectionServiceImplTest method testDeleteConnections.

@Test
public void testDeleteConnections() {
    try {
        InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
        List<IDatabaseConnection> conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 0);
        IDatabaseConnection connection = new DatabaseConnection();
        connection.setName("Connection 1");
        serv.addConnection(connection);
        connection = new DatabaseConnection();
        connection.setName("Connection 2");
        serv.addConnection(connection);
        conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 2);
        try {
            serv.deleteConnection(connection);
            connection = serv.getConnectionByName("Connection 2");
            fail();
        } catch (Exception ex) {
        }
        try {
            serv.deleteConnection("Connection 1");
            connection = serv.getConnectionByName("Connection 1");
            fail();
        } catch (Exception ex) {
        }
    } catch (Exception ex) {
        fail();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 24 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class InMemoryConnectionServiceImplTest method testAddConnections.

@Test
public void testAddConnections() {
    try {
        InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
        List<IDatabaseConnection> conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 0);
        IDatabaseConnection connection = new DatabaseConnection();
        connection.setName("Connection 1");
        serv.addConnection(connection);
        connection = new DatabaseConnection();
        connection.setName("Connection 1");
        try {
            // validate adding connection with existing name
            serv.addConnection(connection);
            fail();
        } catch (ConnectionServiceException e) {
        }
        connection = new DatabaseConnection();
        connection.setName("Connection 2");
        serv.addConnection(connection);
        conns = serv.getConnections();
        assertTrue(conns != null && conns.size() > 0);
    } catch (Exception ex) {
        fail();
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 25 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class UtilHtmlSanitizerTest method testUnsanitizeConnectionParameters.

@Test
public void testUnsanitizeConnectionParameters() throws Exception {
    DatabaseConnection connection = new DatabaseConnection();
    connection.setName("<font color=\"red\">\"AAAAAAAAAAAA\"");
    assertEquals("<font color=\"red\">\"AAAAAAAAAAAA\"", connection.getName());
    sanitizer.sanitizeConnectionParameters(connection);
    assertEquals("&lt;font color=&quot;red&quot;&gt;&quot;AAAAAAAAAAAA&quot;", connection.getName());
    sanitizer.unsanitizeConnectionParameters(connection);
    assertEquals("<font color=\"red\">\"AAAAAAAAAAAA\"", connection.getName());
    assertNull(connection.getDatabaseName());
}
Also used : DatabaseConnection(org.pentaho.database.model.DatabaseConnection) Test(org.junit.Test)

Aggregations

DatabaseConnection (org.pentaho.database.model.DatabaseConnection)56 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)48 Test (org.junit.Test)36 HashMap (java.util.HashMap)10 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)7 DatabaseType (org.pentaho.database.model.DatabaseType)6 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)6 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)6 ArrayList (java.util.ArrayList)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IDatabaseType (org.pentaho.database.model.IDatabaseType)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 Response (javax.ws.rs.core.Response)4 List (java.util.List)3 LinkedList (java.util.LinkedList)2 Mockito.anyString (org.mockito.Mockito.anyString)2 DatabaseAccessType (org.pentaho.database.model.DatabaseAccessType)2 PartitionDatabaseMeta (org.pentaho.database.model.PartitionDatabaseMeta)2 Category (org.pentaho.metadata.model.Category)2