Search in sources :

Example 91 with JUnitTemporaryDatabase

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

the class NodeRestServiceIT method testNode.

@Test
@JUnitTemporaryDatabase
public void testNode() throws Exception {
    // Testing POST
    createNode();
    String url = "/nodes";
    // Testing GET Collection
    String xml = sendRequest(GET, url, 200);
    assertTrue(xml.contains("Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0"));
    OnmsNodeList list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(1, list.size());
    assertEquals(xml, "TestMachine0", list.get(0).getLabel());
    // Testing orderBy
    xml = sendRequest(GET, url, parseParamData("orderBy=sysObjectId"), 200);
    list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(1, list.size());
    assertEquals("TestMachine0", list.get(0).getLabel());
    // Add 4 more nodes
    for (m_nodeCounter = 1; m_nodeCounter < 5; m_nodeCounter++) {
        createNode();
    }
    // Testing limit/offset
    xml = sendRequest(GET, url, parseParamData("limit=3&offset=0&orderBy=label"), 200);
    list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(3, list.size());
    assertEquals(Integer.valueOf(3), list.getCount());
    assertEquals(Integer.valueOf(5), list.getTotalCount());
    assertEquals("TestMachine0", list.get(0).getLabel());
    assertEquals("TestMachine1", list.get(1).getLabel());
    assertEquals("TestMachine2", list.get(2).getLabel());
    // This filter should match
    xml = sendRequest(GET, url, parseParamData("comparator=like&label=%25Test%25"), 200);
    LOG.info(xml);
    list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(Integer.valueOf(5), list.getCount());
    assertEquals(Integer.valueOf(5), list.getTotalCount());
    // This filter should fail (return 0 results)
    xml = sendRequest(GET, url, parseParamData("comparator=like&label=%25DOES_NOT_MATCH%25"), 200);
    LOG.info(xml);
    list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(null, list.getCount());
    assertEquals(Integer.valueOf(0), list.getTotalCount());
    // Testing PUT
    url += "/1";
    sendPut(url, "sysContact=OpenNMS&assetRecord.manufacturer=Apple&assetRecord.operatingSystem=MacOSX Leopard", 204);
    // Testing GET Single Object
    xml = sendRequest(GET, url, 200);
    assertTrue(xml.contains("<sysContact>OpenNMS</sysContact>"));
    assertTrue(xml.contains("<operatingSystem>MacOSX Leopard</operatingSystem>"));
    // Testing DELETE
    m_mockEventIpcManager.getEventAnticipator().reset();
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.DELETE_NODE_EVENT_UEI, "Test").setNodeid(1).getEvent());
    sendRequest(DELETE, url, 204);
    m_mockEventIpcManager.getEventAnticipator().waitForAnticipated(10000);
    m_mockEventIpcManager.getEventAnticipator().verifyAnticipated();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNodeList(org.opennms.netmgt.model.OnmsNodeList) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 92 with JUnitTemporaryDatabase

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

the class NodeRestServiceIT method testSnmpInterfaceJson.

@Test
@JUnitTemporaryDatabase
public void testSnmpInterfaceJson() throws Exception {
    createSnmpInterface();
    String url = "/nodes/1/snmpinterfaces";
    final MockHttpServletRequest req = createRequest(m_context, GET, url);
    req.addHeader("Accept", MediaType.APPLICATION_JSON);
    req.addParameter("limit", "0");
    final String json = sendRequest(req, 200);
    assertNotNull(json);
    assertFalse(json.contains("The Owner"));
    JSONObject jo = new JSONObject(json);
    final JSONArray ja = jo.getJSONArray("snmpInterface");
    assertEquals(1, ja.length());
    jo = ja.getJSONObject(0);
    assertEquals(6, jo.getInt("ifIndex"));
    assertEquals(1, jo.getInt("ifOperStatus"));
    assertEquals("en1", jo.getString("ifDescr"));
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JSONArray(org.json.JSONArray) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 93 with JUnitTemporaryDatabase

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

the class OutageDaoIT method testGetMatchingOutages.

@Test
@JUnitTemporaryDatabase
public void testGetMatchingOutages() {
    m_transTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
            m_nodeDao.save(node);
            insertEntitiesAndOutage("172.16.1.1", "ICMP", node);
        }
    });
    /*
         * We need to flush and finish the transaction because JdbcFilterDao
         * gets its own connection from the DataSource and won't see our data
         * otherwise.
         */
    m_transTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            String[] svcs = new String[] { "ICMP" };
            ServiceSelector selector = new ServiceSelector("ipAddr IPLIKE 172.16.1.1", Arrays.asList(svcs));
            Collection<OnmsOutage> outages = m_outageDao.matchingCurrentOutages(selector);
            assertEquals("outage count", 1, outages.size());
        }
    });
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) TransactionStatus(org.springframework.transaction.TransactionStatus) Collection(java.util.Collection) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 94 with JUnitTemporaryDatabase

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

the class OutageDaoIT method testGetMatchingOutagesWithEmptyServiceList.

@Test
@JUnitTemporaryDatabase
public void testGetMatchingOutagesWithEmptyServiceList() {
    m_transTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
            m_nodeDao.save(node);
            insertEntitiesAndOutage("172.16.1.1", "ICMP", node);
        }
    });
    /*
         * We need to flush and finish the transaction because JdbcFilterDao
         * gets its own connection from the DataSource and won't see our data
         * otherwise.
         */
    m_transTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            ServiceSelector selector = new ServiceSelector("ipAddr IPLIKE 172.16.1.1", new ArrayList<String>(0));
            Collection<OnmsOutage> outages = m_outageDao.matchingCurrentOutages(selector);
            assertEquals(1, outages.size());
        }
    });
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) Collection(java.util.Collection) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 95 with JUnitTemporaryDatabase

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

the class HibernateCriteriaConverterIT method testNodeQuery.

@Test
@JUnitTemporaryDatabase
public void testNodeQuery() throws Exception {
    List<OnmsNode> nodes;
    // first, try with OnmsCriteria
    final OnmsCriteria crit = new OnmsCriteria(OnmsNode.class);
    crit.add(org.hibernate.criterion.Restrictions.isNotNull("id"));
    nodes = m_nodeDao.findMatching(crit);
    assertEquals(6, nodes.size());
    // then the same with the builder
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
    cb.isNotNull("id");
    nodes = m_nodeDao.findMatching(cb.toCriteria());
    assertEquals(6, nodes.size());
    cb.eq("label", "node1").join("ipInterfaces", "ipInterface").eq("ipInterface.ipAddress", "192.168.1.1");
    nodes = m_nodeDao.findMatching(cb.toCriteria());
    assertEquals(1, nodes.size());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)109 Test (org.junit.Test)105 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Date (java.util.Date)20 JSONObject (org.json.JSONObject)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 Transactional (org.springframework.transaction.annotation.Transactional)14 FileInputStream (java.io.FileInputStream)10 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)10 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)8 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)7 AlarmIdFilter (org.opennms.web.alarm.filter.AlarmIdFilter)7 HashMap (java.util.HashMap)6 OutageCriteria (org.opennms.web.outage.filter.OutageCriteria)6 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 JSONArray (org.json.JSONArray)4 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)4