Search in sources :

Example 1 with DbNotifierDataSourceFactory

use of org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory in project opennms by OpenNMS.

the class TestLoadDbNotifierDataSourceFactory method testLoadFromProperties.

@Test
public void testLoadFromProperties() {
    System.out.println("start of testLoadFromProperties");
    DbNotifierDataSourceFactory dsConfig = new DbNotifierDataSourceFactory();
    dsConfig.setDataBaseName("testdataBaseName");
    dsConfig.setUserName("testuserName");
    dsConfig.setPassWord("testpassWord");
    dsConfig.setHostname("localhost");
    dsConfig.setPort("5432");
    dsConfig.init();
    assertEquals("testdataBaseName", dsConfig.getDataBaseName());
    assertEquals("testuserName", dsConfig.getUserName());
    assertEquals("testpassWord", dsConfig.getPassWord());
    assertEquals("localhost", dsConfig.getHostname());
    assertEquals("5432", dsConfig.getPort());
    PGDataSource pgds = dsConfig.getPGDataSource();
    assertNotNull(pgds);
    System.out.println("end of testLoadFromProperties");
}
Also used : PGDataSource(com.impossibl.postgres.jdbc.PGDataSource) DbNotifierDataSourceFactory(org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory) Test(org.junit.Test)

Example 2 with DbNotifierDataSourceFactory

use of org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory in project opennms by OpenNMS.

the class TestLoadDbNotifierDataSourceFactory method testLoadFromXML.

@Test
public void testLoadFromXML() {
    System.out.println("start of testLoadFromXML");
    DbNotifierDataSourceFactory dsConfig = new DbNotifierDataSourceFactory();
    String fileUri = null;
    fileUri = "./src/test/resources/opennms-datasources.xml";
    dsConfig.setDataSourceFileUri(fileUri);
    dsConfig.init();
    assertEquals("opennms", dsConfig.getDataBaseName());
    assertEquals("opennms", dsConfig.getUserName());
    assertEquals("opennms", dsConfig.getPassWord());
    assertEquals("localhost", dsConfig.getHostname());
    assertEquals("5432", dsConfig.getPort());
    PGDataSource pgds = dsConfig.getPGDataSource();
    assertNotNull(pgds);
    System.out.println("end of testLoadFromXML");
}
Also used : PGDataSource(com.impossibl.postgres.jdbc.PGDataSource) DbNotifierDataSourceFactory(org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory) Test(org.junit.Test)

Example 3 with DbNotifierDataSourceFactory

use of org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory in project opennms by OpenNMS.

the class DbChangeNotifierTest method test1.

@Test
public void test1() {
    System.out.println("Starting DbChangeNotifierTest test1");
    DbNotifierDataSourceFactory dsFactory = new DbNotifierDataSourceFactory();
    dsFactory.setDataBaseName("opennms");
    dsFactory.setUserName("opennms");
    dsFactory.setPassWord("opennms");
    dsFactory.setHostname("localhost");
    dsFactory.setPort("5432");
    // TODO remove
    // PGDataSource pgDataSource = new PGDataSource();
    // 
    // pgDataSource.setHost("localhost");
    // pgDataSource.setPort(5432);
    // pgDataSource.setDatabase("opennms");
    // pgDataSource.setUser("opennms");
    // pgDataSource.setPassword("opennms");
    DatabaseChangeNotifier dbChangeNotifier = null;
    try {
        System.out.println("DbChangeNotifierTest creating connection - this is quite slow");
        List<String> paramList = new ArrayList<>();
        paramList.add(DatabaseChangeNotifier.NOTIFY_EVENT_CHANGES);
        paramList.add(DatabaseChangeNotifier.NOTIFY_ALARM_CHANGES);
        dbChangeNotifier = new DatabaseChangeNotifier(dsFactory, paramList);
        DbNotificationClientQueueImpl dbNotificationQueueClient = new DbNotificationClientQueueImpl();
        Map<String, NotificationClient> channelHandlingClients = new HashMap<String, NotificationClient>();
        // channelHandlingClients.put("opennms_alarm_changes", new VerySimpleNotificationClient());
        AlarmChangeNotificationClient alarmChangeNotificationClient = new AlarmChangeNotificationClient();
        channelHandlingClients.put("opennms_alarm_changes", alarmChangeNotificationClient);
        dbNotificationQueueClient.setChannelHandlingClients(channelHandlingClients);
        dbNotificationQueueClient.setDatabaseChangeNotifier(dbChangeNotifier);
        dbNotificationQueueClient.init();
        System.out.println("DbChangeNotifierTest initialising connection");
        dbChangeNotifier.init();
        System.out.println("DbChangeNotifierTest waiting for messages or until timeout");
        try {
            // wait for interrupt or time out
            Thread.sleep(50000);
        } catch (InterruptedException e) {
        }
        System.out.println("DbChangeNotifierTest shutting down");
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        System.out.println("DbChangeNotifierTest destroying connection");
        try {
            if (dbChangeNotifier != null) {
                dbChangeNotifier.destroy();
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    System.out.println("End of DbChangeNotifierTest test1");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DbNotifierDataSourceFactory(org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory) DatabaseChangeNotifier(org.opennms.plugins.dbnotifier.DatabaseChangeNotifier) DbNotificationClientQueueImpl(org.opennms.plugins.dbnotifier.DbNotificationClientQueueImpl) NotificationClient(org.opennms.plugins.dbnotifier.NotificationClient) AlarmChangeNotificationClient(org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient) AlarmChangeNotificationClient(org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DbNotifierDataSourceFactory (org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory)3 PGDataSource (com.impossibl.postgres.jdbc.PGDataSource)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DatabaseChangeNotifier (org.opennms.plugins.dbnotifier.DatabaseChangeNotifier)1 DbNotificationClientQueueImpl (org.opennms.plugins.dbnotifier.DbNotificationClientQueueImpl)1 NotificationClient (org.opennms.plugins.dbnotifier.NotificationClient)1 AlarmChangeNotificationClient (org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient)1