Search in sources :

Example 1 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class OpenNMSITCase method populateDatabase.

protected void populateDatabase() throws Exception {
    m_db = new MockDatabase();
    m_db.populate(m_network);
}
Also used : MockDatabase(org.opennms.core.test.db.MockDatabase)

Example 2 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class EventTranslatorIT method createMockDb.

private void createMockDb() throws Exception {
    m_db = new MockDatabase();
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
}
Also used : MockDatabase(org.opennms.core.test.db.MockDatabase)

Example 3 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class CollectdConfigFactoryIT method setUp.

@Before
public void setUp() throws Exception {
    MockNetwork network = new MockNetwork();
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    FilterDaoFactory.getInstance();
    InputStream in = ConfigurationTestUtils.getInputStreamForResource(this, "collectd-testdata.xml");
    try {
        m_factory = new CollectdConfigFactory(in, "localhost", false);
    } finally {
        in.close();
    }
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) InputStream(java.io.InputStream) MockDatabase(org.opennms.core.test.db.MockDatabase) Before(org.junit.Before)

Example 4 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class PollerConfigFactoryIT method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    MockLogAppender.setupLogging();
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/config/test-database-schema.xml")));
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    network.addNode(1, "Router");
    network.addInterface("192.168.1.1");
    network.addService("ICMP");
    network.addService("SMTP");
    network.addInterface("192.168.1.2");
    network.addService("ICMP");
    network.addService("SMTP");
    network.addNode(2, "Server");
    network.addInterface("192.168.1.3");
    network.addService("ICMP");
    network.addService("HTTP");
    network.addNode(3, "Firewall");
    network.addInterface("192.168.1.4");
    network.addService("SMTP");
    network.addService("HTTP");
    network.addInterface("192.168.1.5");
    network.addService("SMTP");
    network.addService("HTTP");
    network.addInterface("192.169.1.5");
    network.addService("SMTP");
    network.addService("HTTP");
    network.addNode(4, "TestNode121");
    network.addInterface("123.12.123.121");
    network.addService("HTTP");
    network.addNode(5, "TestNode122");
    network.addInterface("123.12.123.122");
    network.addService("HTTP");
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    // Make sure it gets *our* MockDatabase
    FilterDaoFactory.setInstance(null);
    FilterDaoFactory.getInstance();
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockDatabase(org.opennms.core.test.db.MockDatabase)

Example 5 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class AbstractSpringJerseyRestTestCase method setUp.

@Before
public void setUp() throws Throwable {
    beforeServletStart();
    setUser("admin", new String[] { "ROLE_ADMIN" });
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockDatabase db = new MockDatabase(true);
    DataSourceFactory.setInstance(db);
    XADataSourceFactory.setInstance(db);
    try {
        MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
        setFilter(new OpenSessionInViewFilter());
        getFilter().init(filterConfig);
        // Jersey
        /*
            setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
            getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
            getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.codehaus.jackson.jaxrs;org.opennms.web.rest;org.opennms.web.rest.config");
            getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
            getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
            setDispatcher(new SpringServlet());
            getDispatcher().init(getServletConfig());
            */
        // Apache CXF
        setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
        getServletConfig().addInitParameter("config-location", m_cxfContextPath);
        CXFServlet servlet = new CXFServlet();
        setDispatcher(servlet);
        getDispatcher().init(getServletConfig());
    } catch (ServletException se) {
        throw se.getRootCause();
    }
    afterServletStart();
    System.err.println("------------------------------------------------------------------------------");
}
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) CXFServlet(org.apache.cxf.transport.servlet.CXFServlet) MockFilterConfig(org.springframework.mock.web.MockFilterConfig) Before(org.junit.Before)

Aggregations

MockDatabase (org.opennms.core.test.db.MockDatabase)16 MockNetwork (org.opennms.netmgt.mock.MockNetwork)8 Before (org.junit.Before)5 InputStream (java.io.InputStream)4 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)4 HashMap (java.util.HashMap)3 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)3 GregorianCalendar (java.util.GregorianCalendar)2 ServletException (javax.servlet.ServletException)2 Test (org.junit.Test)2 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)2 MibObject (org.opennms.netmgt.config.datacollection.MibObject)2 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)2 MockCategoryFactory (org.opennms.netmgt.mock.MockCategoryFactory)2 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)2 MockServletConfig (org.springframework.mock.web.MockServletConfig)2 OpenSessionInViewFilter (org.springframework.orm.hibernate3.support.OpenSessionInViewFilter)2 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ServletContextEvent (javax.servlet.ServletContextEvent)1