use of org.apache.cxf.ws.eventing.integration.notificationapi.EarthquakeEvent in project cxf by apache.
the class NotificationTest method withFilter2.
/**
* We request only to receive notifications about earthquakes in Russia with Richter scale equal to 3.5
* and there will be one fire in Canada and one earthquake in Russia. We should
* receive only one notification.
*/
@Test
public void withFilter2() throws IOException {
NotificatorService service = createNotificatorService();
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
subscribe.setExpires(exp);
EndpointReferenceType eventSinkERT = new EndpointReferenceType();
AttributedURIType eventSinkAddr = new AttributedURIType();
String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
eventSinkAddr.setValue(url);
eventSinkERT.setAddress(eventSinkAddr);
subscribe.setDelivery(new DeliveryType());
subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));
subscribe.setFilter(new FilterType());
subscribe.getFilter().getContent().add("//*[local-name()='earthquake']/location[text()='Russia']/" + "../richterScale[contains(text(),'3.5')]");
eventSourceClient.subscribeOp(subscribe);
Server eventSinkServer = createEventSink(url);
TestingEventSinkImpl.RECEIVED_FIRES.set(0);
TestingEventSinkImpl.RECEIVED_EARTHQUAKES.set(0);
service.start();
Emitter emitter = new EmitterImpl(service);
emitter.dispatch(new FireEvent("Canada", 8));
emitter.dispatch(new EarthquakeEvent(3.5f, "Russia"));
for (int i = 0; i < 10; i++) {
if (TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get() == 1) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
eventSinkServer.stop();
if (TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get() != 1) {
Assert.fail("TestingEventSinkImpl should have received 1 earthquake event but received " + TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get());
}
if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 0) {
Assert.fail("TestingEventSinkImpl should have not received a fire event" + TestingEventSinkImpl.RECEIVED_FIRES.get());
}
}
Aggregations