Skip to content

Commit eb2543b

Browse files
Jesse WhiteBenjamin Reed
authored andcommitted
NMS-6404: Test the event publishing via REST.
1 parent d48680f commit eb2543b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

opennms-webapp-rest/src/test/java/org/opennms/web/rest/v1/EventRestServiceIT.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@
2828

2929
package org.opennms.web.rest.v1;
3030

31+
import static org.junit.Assert.assertEquals;
3132
import static org.junit.Assert.assertTrue;
3233

34+
import javax.ws.rs.core.MediaType;
35+
3336
import org.junit.Test;
3437
import org.junit.runner.RunWith;
3538
import org.opennms.core.test.MockLogAppender;
3639
import org.opennms.core.test.OpenNMSJUnit4ClassRunner;
3740
import org.opennms.core.test.db.annotations.JUnitTemporaryDatabase;
3841
import org.opennms.core.test.rest.AbstractSpringJerseyRestTestCase;
42+
import org.opennms.core.xml.JaxbUtils;
3943
import org.opennms.netmgt.dao.DatabasePopulator;
44+
import org.opennms.netmgt.dao.mock.EventAnticipator;
45+
import org.opennms.netmgt.dao.mock.MockEventIpcManager;
46+
import org.opennms.netmgt.xml.event.Event;
4047
import org.opennms.test.JUnitConfigurationEnvironment;
4148
import org.springframework.beans.factory.annotation.Autowired;
49+
import org.springframework.mock.web.MockHttpServletResponse;
4250
import org.springframework.test.context.ContextConfiguration;
4351
import org.springframework.test.context.web.WebAppConfiguration;
4452
import org.springframework.transaction.annotation.Transactional;
@@ -65,6 +73,9 @@ public class EventRestServiceIT extends AbstractSpringJerseyRestTestCase {
6573
@Autowired
6674
private DatabasePopulator m_databasePopulator;
6775

76+
@Autowired
77+
private MockEventIpcManager m_eventMgr;
78+
6879
@Override
6980
protected void afterServletStart() {
7081
MockLogAppender.setupLogging(true, "DEBUG");
@@ -81,4 +92,24 @@ public void testBetween() throws Exception {
8192
xml = sendRequest(GET, "/events/between", parseParamData("end=2010-01-01T01:00:00Z"), 200);
8293
assertTrue(xml.contains("totalCount=\"0\""));
8394
}
95+
96+
@Test
97+
public void canPublishEventToBus() throws Exception {
98+
// Create some test event
99+
Event e = new Event();
100+
e.setUei("some.uei");
101+
e.setHost("from-some-host");
102+
103+
// Setup the anticipator
104+
EventAnticipator anticipator = m_eventMgr.getEventAnticipator();
105+
anticipator.anticipateEvent(e);
106+
107+
// POST the event to the REST API
108+
MockHttpServletResponse response = sendData(POST, MediaType.APPLICATION_XML, "/events", JaxbUtils.marshal(e));
109+
110+
// Verify
111+
assertEquals(200, response.getStatus());
112+
m_eventMgr.finishProcessingEvents();
113+
anticipator.verifyAnticipated(1000, 0, 0, 0, 0);
114+
}
84115
}

0 commit comments

Comments
 (0)