Search in sources :

Example 6 with HibernateDaoFactory

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

the class JtiTelemetryIT method sendnewSuspectEvent.

public static OnmsNode sendnewSuspectEvent(Executor executor, InetSocketAddress opennmsHttp, TestEnvironment m_testEnvironment, boolean isMinion, Date startOfTest) throws ClientProtocolException, IOException {
    Event minionEvent = new Event();
    minionEvent.setUei("uei.opennms.org/internal/discovery/newSuspect");
    minionEvent.setHost(SENDER_IP);
    minionEvent.setInterface(SENDER_IP);
    minionEvent.setInterfaceAddress(Inet4Address.getByName(SENDER_IP));
    minionEvent.setSource("system-test");
    minionEvent.setSeverity("4");
    if (isMinion) {
        Parm parm = new Parm();
        parm.setParmName("location");
        Value minion = new Value("MINION");
        parm.setValue(minion);
        List<Parm> parms = new ArrayList<>();
        parms.add(parm);
        minionEvent.setParmCollection(parms);
    }
    String xmlString = JaxbUtils.marshal(minionEvent);
    executor.execute(Request.Post(String.format("http://%s:%d/opennms/rest/events", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyString(xmlString, ContentType.APPLICATION_XML)).returnContent();
    InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
    NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
    Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).eq("ipAddr", Inet4Address.getByName(SENDER_IP)).toCriteria();
    await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
    final OnmsNode onmsNode = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("label", SENDER_IP).ge("createTime", startOfTest).toCriteria()), notNullValue());
    assertNotNull(onmsNode);
    if (isMinion) {
        assertThat(onmsNode.getLocation().getLocationName(), is("MINION"));
    }
    LOG.info(" New suspect event has been sent and node has been created for IP : {}", SENDER_IP);
    return onmsNode;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Parm(org.opennms.netmgt.xml.event.Parm) Criteria(org.opennms.core.criteria.Criteria) NodeDao(org.opennms.netmgt.dao.api.NodeDao) EventDao(org.opennms.netmgt.dao.api.EventDao) Value(org.opennms.netmgt.xml.event.Value) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Event(org.opennms.netmgt.xml.event.Event) OnmsEvent(org.opennms.netmgt.model.OnmsEvent)

Example 7 with HibernateDaoFactory

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

the class NxosTelemetryIT method addRequisition.

public static OnmsNode addRequisition(InetSocketAddress opennmsHttp, boolean isMinion, Date startOfTest) {
    RestClient client = new RestClient(opennmsHttp);
    Requisition requisition = new Requisition("telemetry");
    List<RequisitionInterface> interfaces = new ArrayList<>();
    RequisitionInterface requisitionInterface = new RequisitionInterface();
    requisitionInterface.setIpAddr("192.168.0.1");
    requisitionInterface.setManaged(true);
    requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
    interfaces.add(requisitionInterface);
    RequisitionNode node = new RequisitionNode();
    String label = "nexus9k";
    node.setNodeLabel(label);
    node.setForeignId("nxos");
    node.setInterfaces(interfaces);
    if (isMinion) {
        // For a requisition, foreignId needs to be unique, change foreignId
        node.setLocation("MINION");
        node.setForeignId("nexus9k");
        // Change label so that node matches with foreignId
        label = "nxos";
        node.setNodeLabel(label);
    }
    requisition.insertNode(node);
    client.addOrReplaceRequisition(requisition);
    client.importRequisition("telemetry");
    InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
    final OnmsNode onmsNode = await().atMost(3, MINUTES).pollInterval(30, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).ge("createTime", startOfTest).eq("label", label).toCriteria()), notNullValue());
    assertNotNull(onmsNode);
    return onmsNode;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) RestClient(org.opennms.smoketest.utils.RestClient) ArrayList(java.util.ArrayList) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 8 with HibernateDaoFactory

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

the class MinionHeartbeatOutageIT 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 9 with HibernateDaoFactory

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

the class AbstractNodeRestServiceTest method verifyCreationWithAssetRecord.

// See NMS-9855
@Test
public void verifyCreationWithAssetRecord() {
    final String node = "<node type=\"A\" label=\"TestMachine1\" foreignSource=\"SmokeTests\" foreignId=\"TestMachine1\">" + "<assetRecord>" + "<description>Right here, right now</description>" + "</assetRecord>" + "<labelSource>H</labelSource>" + "<sysContact>The Owner</sysContact>" + "<sysDescription>" + "Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun  9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386" + "</sysDescription>" + "<sysLocation>DevJam</sysLocation>" + "<sysName>TestMachine1</sysName>" + "<sysObjectId>.1.3.6.1.4.1.8072.3.2.255</sysObjectId>" + "<createTime>2011-09-24T07:12:46.421-04:00</createTime>" + "<lastCapsdPoll>2011-09-24T07:12:46.421-04:00</lastCapsdPoll>" + "</node>";
    given().body(node).contentType(ContentType.XML).post().then().assertThat().statusCode(201);
    // Verify that only one asset record has been created
    final HibernateDaoFactory daoFactory = new HibernateDaoFactory(getPostgresService());
    final AssetRecordDao dao = daoFactory.getDao(AssetRecordDaoHibernate.class);
    assertThat(dao.countAll(), is(1));
    // Ensure we can get nodes with asset records attached
    given().get().then().log().all().and().assertThat().statusCode(200);
}
Also used : HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) AssetRecordDao(org.opennms.netmgt.dao.api.AssetRecordDao) 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