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");
}
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");
}
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");
}
Aggregations