use of org.apache.cxf.ws.eventing.DeliveryType 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());
}
}
use of org.apache.cxf.ws.eventing.DeliveryType in project cxf by apache.
the class SubscriptionGrantingTest method testExpirationGrantingWithoutBestEffort.
/* */
/**
* specification:
* The expiration time MAY be either a specific time or a duration but MUST
* be of the same type as the wse:Expires element of the corresponding request.
* If the corresponding request did not contain a wse:Expires element, this
* element MUST be a duration (xs:duration).
*
* @throws IOException
*/
@Test
public void testExpirationGrantingWithoutBestEffort() throws IOException {
// we specify a xs:duration
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
subscribe.setExpires(exp);
DeliveryType delivery = new DeliveryType();
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
SubscribeResponse resp = eventSourceClient.subscribeOp(subscribe);
Assert.assertTrue("Specification requires that EventSource return a xs:duration " + "expirationType if a xs:duration was requested by client", DurationAndDateUtil.isDuration(resp.getGrantedExpires().getValue()));
// we specify a xs:dateTime
subscribe = new Subscribe();
exp = new ExpirationType();
XMLGregorianCalendar dateRequest = (XMLGregorianCalendar) DurationAndDateUtil.parseDurationOrTimestamp("2138-06-26T12:23:12.000-01:00");
exp.setValue(DurationAndDateUtil.convertToXMLString(dateRequest));
subscribe.setExpires(exp);
delivery = new DeliveryType();
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
resp = eventSourceClient.subscribeOp(subscribe);
Assert.assertTrue("Specification requires that EventSource return a " + "xs:dateTime expirationType if a xs:dateTime was requested by client", DurationAndDateUtil.isXMLGregorianCalendar(resp.getGrantedExpires().getValue()));
XMLGregorianCalendar returned = DurationAndDateUtil.parseXMLGregorianCalendar(resp.getGrantedExpires().getValue());
System.out.println("granted expiration: " + returned.normalize().toXMLFormat());
System.out.println("requested expiration: " + dateRequest.normalize().toXMLFormat());
Assert.assertTrue("Server should have returned exactly the same date as we requested", returned.equals(dateRequest));
// we don't specify anything
subscribe = new Subscribe();
delivery = new DeliveryType();
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
resp = eventSourceClient.subscribeOp(subscribe);
Assert.assertTrue("Specification requires that EventSource return a xs:duration " + "expirationType if no specific expirationType was requested by client", DurationAndDateUtil.isDuration(resp.getGrantedExpires().getValue()));
}
use of org.apache.cxf.ws.eventing.DeliveryType in project cxf by apache.
the class SubscriptionGrantingTest method cannotProcessFilter.
@Test
public void cannotProcessFilter() throws IOException {
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
DeliveryType delivery = new DeliveryType();
XMLGregorianCalendar dateRequest = (XMLGregorianCalendar) DurationAndDateUtil.parseDurationOrTimestamp("2138-06-26T12:23:12.000-01:00");
exp.setValue(DurationAndDateUtil.convertToXMLString(dateRequest));
exp.setBestEffort(true);
subscribe.setExpires(exp);
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
subscribe.setFilter(new FilterType());
subscribe.getFilter().getContent().add("@^5this-is-not-a-valid-xpath-expression!!!*-/");
try {
eventSourceClient.subscribeOp(subscribe);
} catch (SOAPFaultException ex) {
Assert.assertTrue(ex.getFault().getFaultCode().contains(CannotProcessFilter.LOCAL_PART));
Assert.assertTrue(ex.getFault().getTextContent().contains(CannotProcessFilter.REASON));
return;
}
Assert.fail("Event source should have sent a CannotProcessFilter fault");
}
use of org.apache.cxf.ws.eventing.DeliveryType in project cxf by apache.
the class SubscriptionManagementTest method renewWithDuration.
/**
* Tests the Renew operation, while specifying an xs:duration in the renew request,
* eg. the subscriber requests to prolong the subscription by a specific amount of time.
*/
@Test
public void renewWithDuration() throws IOException {
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(// 5 minutes
DurationAndDateUtil.parseDurationOrTimestamp("PT5M0S")));
subscribe.setExpires(exp);
DeliveryType delivery = new DeliveryType();
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
SubscribeResponse resp = eventSourceClient.subscribeOp(subscribe);
SubscriptionManagerEndpoint client = createSubscriptionManagerClient(resp.getSubscriptionManager().getReferenceParameters());
GetStatusResponse response = client.getStatusOp(new GetStatus());
String expirationBefore = response.getGrantedExpires().getValue();
System.out.println("EXPIRES before renew: " + expirationBefore);
Assert.assertTrue(expirationBefore.length() > 0);
Renew renewRequest = new Renew();
ExpirationType renewExp = new ExpirationType();
renewExp.setValue(DurationAndDateUtil.convertToXMLString(// 10 minutes
DurationAndDateUtil.parseDurationOrTimestamp("PT10M0S")));
renewRequest.setExpires(renewExp);
client.renewOp(renewRequest);
response = client.getStatusOp(new GetStatus());
String expirationAfter = response.getGrantedExpires().getValue();
System.out.println("EXPIRES after renew: " + expirationAfter);
Assert.assertFalse("Renew request should change the expiration time at least a bit", expirationAfter.equals(expirationBefore));
}
use of org.apache.cxf.ws.eventing.DeliveryType in project cxf by apache.
the class SubscriptionManagementTest method unsubscribeAndThenGetStatus.
/**
* Tries to create a subscription, then cancel it, then obtain its status.
* The last mentioned operation should fail.
*/
@Test
public void unsubscribeAndThenGetStatus() throws Exception {
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
subscribe.setExpires(exp);
DeliveryType delivery = new DeliveryType();
subscribe.setDelivery(delivery);
subscribe.getDelivery().getContent().add(createDummyNotifyTo());
SubscribeResponse subscribeResponse = eventSourceClient.subscribeOp(subscribe);
SubscriptionManagerEndpoint client = createSubscriptionManagerClient(subscribeResponse.getSubscriptionManager().getReferenceParameters());
UnsubscribeResponse unsubscribeResponse = client.unsubscribeOp(new Unsubscribe());
Assert.assertNotNull(unsubscribeResponse);
try {
client.getStatusOp(new GetStatus());
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
Assert.assertTrue(ex.getFault().getFaultCode().contains(UnknownSubscription.LOCAL_PART));
Assert.assertTrue(ex.getFault().getTextContent().contains(UnknownSubscription.REASON));
return;
}
Assert.fail("The subscription manager should have refused to send status of a cancelled subscription");
}
Aggregations