Search in sources :

Example 6 with DaoTestConfigBean

use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.

the class ConnectionFactoryIT method testMarshalDataSourceFromConfig.

public void testMarshalDataSourceFromConfig() throws Exception {
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    AtomikosDataSourceFactory factory1 = null;
    AtomikosDataSourceFactory factory2 = null;
    try {
        factory1 = makeFactory("opennms");
        factory1.setUniqueResourceName("opennms");
        factory2 = makeFactory("opennms2");
        factory2.setUniqueResourceName("opennms2");
        Connection conn = null;
        Statement s = null;
        try {
            conn = factory2.getConnection();
            s = conn.createStatement();
            s.execute("select * from pg_proc");
        } finally {
            if (s != null) {
                s.close();
            }
            if (conn != null) {
                conn.close();
            }
        }
    } finally {
        Throwable t1 = null;
        Throwable t2 = null;
        if (factory1 != null) {
            try {
                factory1.close();
                factory1 = null;
            } catch (Throwable e1) {
                t1 = e1;
            }
        }
        if (factory2 != null) {
            try {
                factory2.close();
                factory2 = null;
            } catch (Throwable e2) {
                t2 = e2;
            }
        }
        if (t1 != null || t2 != null) {
            StringBuffer message = new StringBuffer();
            message.append("Could not successfully close both C3P0 factories.  Future tests might fail.");
            Throwable choice;
            if (t1 != null) {
                message.append("  First factory failed with: " + t1.getMessage() + "; see stack back trace.");
                choice = t1;
                if (t2 != null) {
                    System.err.println("  Both factories failed to close.  See stderr for second stack back trace.");
                    t2.printStackTrace(System.err);
                }
            } else {
                choice = t2;
            }
            AssertionError e = new AssertionError(message.toString());
            e.initCause(choice);
            throw e;
        }
    }
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 7 with DaoTestConfigBean

use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.

the class HttpRemotingContextIT method testLoadContext.

public void testLoadContext() throws Throwable {
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockDatabase db = new MockDatabase(true);
    DataSourceFactory.setInstance(db);
    servletContext = new MockServletContext("file:src/main/webapp");
    servletContext.addInitParameter("contextConfigLocation", "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " + "classpath:/META-INF/opennms/applicationContext-soa.xml " + "classpath:/META-INF/opennms/applicationContext-mockDao.xml " + "classpath*:/META-INF/opennms/component-service.xml " + "classpath*:/META-INF/opennms/component-dao.xml " + // Contexts within this project
    "/WEB-INF/applicationContext-common.xml " + "/WEB-INF/applicationContext-serviceRegistryRemoting.xml " + "/WEB-INF/applicationContext-spring-security.xml " + "/WEB-INF/applicationContext-svclayer.xml ");
    servletContext.addInitParameter("parentContextKey", "daoContext");
    ServletContextEvent e = new ServletContextEvent(servletContext);
    contextListener = new ContextLoaderListener();
    contextListener.contextInitialized(e);
    servletContext.setContextPath(contextPath);
    servletConfig = new MockServletConfig(servletContext, "dispatcher");
    servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
    servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
    try {
        MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
        filter = new OpenSessionInViewFilter();
        filter.init(filterConfig);
    } catch (ServletException se) {
        throw se.getRootCause();
    }
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) OpenSessionInViewFilter(org.springframework.orm.hibernate3.support.OpenSessionInViewFilter) ServletException(javax.servlet.ServletException) MockDatabase(org.opennms.core.test.db.MockDatabase) MockServletConfig(org.springframework.mock.web.MockServletConfig) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) MockServletContext(org.springframework.mock.web.MockServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Example 8 with DaoTestConfigBean

use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.

the class InstallerIpLikeTest method setUp.

@Before
public void setUp() {
    System.setProperty("skip-native", "true");
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.setRelativeHomeDirectory("target/test-classes");
    System.setProperty("install.dir", "target/test-classes");
    System.setProperty("install.etc.dir", "target/test-classes/etc");
    bean.afterPropertiesSet();
    m_installer = new Installer();
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) Before(org.junit.Before)

Example 9 with DaoTestConfigBean

use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.

the class SyslogdConfigFactoryIT method setUp.

@Before
public void setUp() throws Exception {
    DaoTestConfigBean daoTestConfig = new DaoTestConfigBean();
    daoTestConfig.setRelativeHomeDirectory("src/test/resources");
    daoTestConfig.afterPropertiesSet();
    MockNetwork network = new MockNetwork();
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    m_factory = new SyslogdConfigFactory(ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-configuration.xml"));
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockDatabase(org.opennms.core.test.db.MockDatabase) Before(org.junit.Before)

Example 10 with DaoTestConfigBean

use of org.opennms.test.DaoTestConfigBean in project opennms by OpenNMS.

the class NotificationsITCase method setUp.

protected void setUp() throws Exception {
    MockUtil.println("################# Running Test ################");
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockLogAppender.setupLogging();
    m_network = createMockNetwork();
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_notifdConfig = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    m_notifdConfig.setNextNotifIdSql(m_db.getNextNotifIdSql());
    m_notifdConfig.setNextUserNotifIdSql(m_db.getNextUserNotifIdSql());
    m_groupManager = createGroupManager();
    m_userManager = createUserManager(m_groupManager);
    m_destinationPathManager = new MockDestinationPathManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "destination-paths.xml"));
    m_notificationCommandManger = new MockNotificationCommandManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notification-commands.xml"));
    m_notificationManager = new MockNotificationManager(m_notifdConfig, m_db, ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifications.xml"));
    m_pollOutagesConfigManager = new MockPollerConfig(m_network);
    m_anticipator = new NotificationAnticipator();
    MockNotificationStrategy.setAnticipator(m_anticipator);
    m_notifd.setConfigManager(m_notifdConfig);
    m_eventProcessor.setEventManager(m_eventMgr);
    m_eventProcessor.setNotifdConfigManager(m_notifdConfig);
    m_eventProcessor.setGroupManager(m_groupManager);
    m_eventProcessor.setUserManager(m_userManager);
    m_eventProcessor.setDestinationPathManager(m_destinationPathManager);
    m_eventProcessor.setNotificationCommandManager(m_notificationCommandManger);
    m_eventProcessor.setNotificationManager(m_notificationManager);
    m_eventProcessor.setPollOutagesConfigManager(m_pollOutagesConfigManager);
    m_notifd.init();
    m_notifd.start();
    //        Date downDate = new Date();
    //        anticipateNotificationsForGroup("node 2 down.", "All services are down on node 2.", "InitialGroup", downDate, 0);
    //    
    //        //bring node down now
    //        m_eventMgr.sendEventToListeners(m_network.getNode(2).createDownEvent(downDate));
    //    
    //        m_anticipator.waitForAnticipated(2000);
    //        
    //        m_anticipator.reset();
    MockUtil.println("################ Finish Setup ################");
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) MockDestinationPathManager(org.opennms.netmgt.config.mock.MockDestinationPathManager) MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) NotificationAnticipator(org.opennms.netmgt.mock.NotificationAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) MockNotificationCommandManager(org.opennms.netmgt.config.mock.MockNotificationCommandManager)

Aggregations

DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)10 Before (org.junit.Before)6 MockDatabase (org.opennms.core.test.db.MockDatabase)4 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 ServletException (javax.servlet.ServletException)2 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)2 MockNetwork (org.opennms.netmgt.mock.MockNetwork)2 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)2 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)2 MockServletConfig (org.springframework.mock.web.MockServletConfig)2 OpenSessionInViewFilter (org.springframework.orm.hibernate3.support.OpenSessionInViewFilter)2 SQLException (java.sql.SQLException)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 CXFServlet (org.apache.cxf.transport.servlet.CXFServlet)1 MockDestinationPathManager (org.opennms.netmgt.config.mock.MockDestinationPathManager)1 MockNotifdConfigManager (org.opennms.netmgt.config.mock.MockNotifdConfigManager)1 MockNotificationCommandManager (org.opennms.netmgt.config.mock.MockNotificationCommandManager)1 MockNotificationManager (org.opennms.netmgt.config.mock.MockNotificationManager)1 NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)1