2828
2929package org .opennms .web .rest .v1 ;
3030
31+ import static org .junit .Assert .assertEquals ;
3132import static org .junit .Assert .assertTrue ;
3233
34+ import javax .ws .rs .core .MediaType ;
35+
3336import org .junit .Test ;
3437import org .junit .runner .RunWith ;
3538import org .opennms .core .test .MockLogAppender ;
3639import org .opennms .core .test .OpenNMSJUnit4ClassRunner ;
3740import org .opennms .core .test .db .annotations .JUnitTemporaryDatabase ;
3841import org .opennms .core .test .rest .AbstractSpringJerseyRestTestCase ;
42+ import org .opennms .core .xml .JaxbUtils ;
3943import 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 ;
4047import org .opennms .test .JUnitConfigurationEnvironment ;
4148import org .springframework .beans .factory .annotation .Autowired ;
49+ import org .springframework .mock .web .MockHttpServletResponse ;
4250import org .springframework .test .context .ContextConfiguration ;
4351import org .springframework .test .context .web .WebAppConfiguration ;
4452import 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