Search in sources :

Example 1 with HibernateDaoFactory

use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.

the class DiscoveryIT method canDiscoverRemoteNodes.

@Test
public void canDiscoverRemoteNodes() throws ClientProtocolException, IOException {
    Date startOfTest = new Date();
    final String tomcatIp = minionSystem.getContainerInfo(ContainerAlias.TOMCAT).networkSettings().ipAddress();
    final InetSocketAddress opennmsHttp = minionSystem.getServiceAddress(ContainerAlias.OPENNMS, 8980);
    final HttpHost opennmsHttpHost = new HttpHost(opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort());
    HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(// Ignore the 302 response to the POST
    new LaxRedirectStrategy()).build();
    Executor executor = Executor.newInstance(instance).auth(opennmsHttpHost, "admin", "admin").authPreemptive(opennmsHttpHost);
    // Configure Discovery with the specific address of our Tomcat server
    // No REST endpoint is currently available to configure the Discovery daemon
    // so we resort to POSTin nasty form data
    executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=AddSpecific", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("specificipaddress", tomcatIp).add("specifictimeout", "2000").add("specificretries", "1").add("initialsleeptime", "30000").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
    executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=SaveAndRestart", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("initialsleeptime", "1").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
    InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
    Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).toCriteria();
    await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Executor(org.apache.http.client.fluent.Executor) EventDao(org.opennms.netmgt.dao.api.EventDao) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) Criteria(org.opennms.core.criteria.Criteria) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) Date(java.util.Date) Test(org.junit.Test)

Example 2 with HibernateDaoFactory

use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.

the class MinionHeartBeatIT method minionHeartBeatTestForLastUpdated.

@Test
public void minionHeartBeatTestForLastUpdated() {
    Date startOfTest = new Date();
    InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    MinionDao minionDao = daoFactory.getDao(MinionDaoHibernate.class);
    NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
    // The heartbeat runs every minute so if we miss the first one, poll long enough
    // to catch the next one
    await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(minionDao, new CriteriaBuilder(OnmsMinion.class).ge("lastUpdated", startOfTest).toCriteria()), greaterThan(0));
    await().atMost(180, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("foreignSource", "Minions").eq("foreignId", "00000000-0000-0000-0000-000000ddba11").toCriteria()), equalTo(1));
    Assert.assertEquals("MINION", nodeDao.get("Minions:00000000-0000-0000-0000-000000ddba11").getLocation().getLocationName());
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) MinionDao(org.opennms.netmgt.dao.api.MinionDao) Date(java.util.Date) Test(org.junit.Test)

Example 3 with HibernateDaoFactory

use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.

the class AbstractSyslogTestCase method getDaoFactory.

protected HibernateDaoFactory getDaoFactory() {
    if (m_daoFactory == null) {
        // Connect to the postgresql container
        final InetSocketAddress pgsql = testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
        m_daoFactory = new HibernateDaoFactory(pgsql);
    }
    return m_daoFactory;
}
Also used : HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) InetSocketAddress(java.net.InetSocketAddress)

Example 4 with HibernateDaoFactory

use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.

the class TrapIT method canReceiveTraps.

@Test
public void canReceiveTraps() throws Exception {
    Date startOfTest = new Date();
    final InetSocketAddress trapAddr = minionSystem.getServiceAddress(ContainerAlias.MINION, 1162, "udp");
    // Connect to the postgresql container
    InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
    // Parsing the message correctly relies on the customized syslogd-configuration.xml that is part of the OpenNMS image
    Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/generic/traps/SNMP_Warm_Start").ge("eventTime", startOfTest).toCriteria();
    // Send traps to the Minion listener until one makes it through
    await().atMost(5, MINUTES).pollInterval(30, SECONDS).pollDelay(0, SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            sendTrap(trapAddr);
            try {
                await().atMost(30, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThanOrEqualTo(1));
            } catch (final Exception e) {
                return false;
            }
            return true;
        }
    });
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) InetSocketAddress(java.net.InetSocketAddress) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test)

Example 5 with HibernateDaoFactory

use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.

the class StatisticsReportsIT method hasReportLinkThatMatchDescription.

@Test
public void hasReportLinkThatMatchDescription() throws Exception {
    Date startOfTest = new Date();
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(getPostgresService());
    ResourceReferenceDao resourceReferenceDao = daoFactory.getDao(ResourceReferenceDaoHibernate.class);
    StatisticsReportDao statisticsReportDao = daoFactory.getDao(StatisticsReportDaoHibernate.class);
    StatisticsReport report = new StatisticsReport();
    report.setName("Top10_Response_Hourly");
    report.setDescription("Hourly Top 10 responses across all nodes");
    report.setStartDate(new Date());
    report.setEndDate(new Date());
    report.setJobStartedDate(new Date());
    report.setJobCompletedDate(new Date());
    report.setPurgeDate(new Date());
    ResourceReference resource = new ResourceReference();
    resource.setResourceId("node1");
    resourceReferenceDao.save(resource);
    StatisticsReportData data = new StatisticsReportData();
    data.setReport(report);
    data.setResource(resource);
    data.setValue(4.0);
    report.addData(data);
    statisticsReportDao.save(report);
    await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(statisticsReportDao, new CriteriaBuilder(StatisticsReport.class).ge("startDate", startOfTest).toCriteria()), notNullValue());
    m_driver.navigate().refresh();
    assertNotNull(findElementByLink("Hourly Top 10 responses across all nodes"));
}
Also used : StatisticsReportDao(org.opennms.netmgt.dao.api.StatisticsReportDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) ResourceReferenceDao(org.opennms.netmgt.dao.api.ResourceReferenceDao) ResourceReference(org.opennms.netmgt.model.ResourceReference) Date(java.util.Date) Test(org.junit.Test)

Aggregations

HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)9 InetSocketAddress (java.net.InetSocketAddress)7 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)6 Test (org.junit.Test)5 Date (java.util.Date)4 Criteria (org.opennms.core.criteria.Criteria)3 EventDao (org.opennms.netmgt.dao.api.EventDao)3 NodeDao (org.opennms.netmgt.dao.api.NodeDao)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 ArrayList (java.util.ArrayList)2 HttpHost (org.apache.http.HttpHost)1 HttpClient (org.apache.http.client.HttpClient)1 Executor (org.apache.http.client.fluent.Executor)1 LaxRedirectStrategy (org.apache.http.impl.client.LaxRedirectStrategy)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 AssetRecordDao (org.opennms.netmgt.dao.api.AssetRecordDao)1 MinionDao (org.opennms.netmgt.dao.api.MinionDao)1 ResourceReferenceDao (org.opennms.netmgt.dao.api.ResourceReferenceDao)1 StatisticsReportDao (org.opennms.netmgt.dao.api.StatisticsReportDao)1