Search in sources :

Example 1 with AuditConnection

use of org.pentaho.platform.engine.services.audit.AuditConnection in project pentaho-platform by pentaho.

the class AuditConnectionTest method testAuditConnectionNoConfigFile.

public void testAuditConnectionNoConfigFile() {
    startTest();
    // We want to test what happens when the config file can't be found
    SOLUTION_PATH = "";
    AuditConnection auditConnection = new AuditConnection();
    // make sure we get a datasource from the object factory
    auditConnection.setUseNewDatasourceService(true);
    auditConnection.initialize();
    MockDataSourceService.setThrowExceptionOnGetConnection(false);
    try {
        Connection connection = auditConnection.getAuditConnection();
        // $NON-NLS-1$
        System.out.println("Audit Connection Is  " + connection);
        DataSource datasource = auditConnection.getAuditDatasource();
        // $NON-NLS-1$
        System.out.println("Datasource Is  " + datasource);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        finishTest();
    }
}
Also used : AuditConnection(org.pentaho.platform.engine.services.audit.AuditConnection) Connection(java.sql.Connection) AuditConnection(org.pentaho.platform.engine.services.audit.AuditConnection) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Example 2 with AuditConnection

use of org.pentaho.platform.engine.services.audit.AuditConnection in project pentaho-platform by pentaho.

the class AuditConnectionTest method testAuditConnection_cannot_establish_connection.

public void testAuditConnection_cannot_establish_connection() {
    startTest();
    try {
        // Load mock object factory with mock datasource service that produces null datasources
        StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
        factory.init("src/test/resources/solution/system/pentahoObjects.datasourceservice.null.spring.xml", null);
        PentahoSystem.registerObjectFactory(factory);
        AuditConnection auditConnection = new AuditConnection();
        // make sure we get a datasource from the object factory
        auditConnection.setUseNewDatasourceService(true);
        auditConnection.initialize();
        MockDataSourceService.setThrowExceptionOnGetConnection(true);
        auditConnection.getAuditConnection();
        fail("Expected exception when no audit connection could be established");
    } catch (SQLException ex) {
        ex.printStackTrace();
        assertTrue("Expected AUDSQLENT.ERROR_0001", ex.getMessage().contains("AUDSQLENT.ERROR_0001"));
    } finally {
        finishTest();
    }
}
Also used : SQLException(java.sql.SQLException) AuditConnection(org.pentaho.platform.engine.services.audit.AuditConnection) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 3 with AuditConnection

use of org.pentaho.platform.engine.services.audit.AuditConnection in project pentaho-platform by pentaho.

the class AuditConnectionTest method testAuditConnection.

public void testAuditConnection() {
    startTest();
    AuditConnection auditConnection = new AuditConnection();
    // make sure we get a datasource from the object factory
    auditConnection.setUseNewDatasourceService(true);
    auditConnection.initialize();
    MockDataSourceService.setThrowExceptionOnGetConnection(false);
    try {
        Connection connection = auditConnection.getAuditConnection();
        // $NON-NLS-1$
        System.out.println("Audit Connection Is  " + connection);
        DataSource datasource = auditConnection.getAuditDatasource();
        // $NON-NLS-1$
        System.out.println("Datasource Is  " + datasource);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        finishTest();
    }
}
Also used : AuditConnection(org.pentaho.platform.engine.services.audit.AuditConnection) Connection(java.sql.Connection) AuditConnection(org.pentaho.platform.engine.services.audit.AuditConnection) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Aggregations

SQLException (java.sql.SQLException)3 AuditConnection (org.pentaho.platform.engine.services.audit.AuditConnection)3 Connection (java.sql.Connection)2 DataSource (javax.sql.DataSource)2 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)1