//first some setup
reset();
TModel createKeyGenator = UDDIClerk.createKeyGenator("somebusiness", "A test key domain SubscriptionCallbackTest1", "SubscriptionCallbackTest1");
Assert.assertNotNull(createKeyGenator);
clerk.register(createKeyGenator);
logger.info("Registered tModel keygen: " + createKeyGenator.getTModelKey());
//setup the business to attach to
BusinessEntity be = new BusinessEntity();
be.setBusinessKey("uddi:somebusiness:somebusinesskey");
be.getName().add(new Name("somebusiness SubscriptionCallbackTest1", null));
be.setBusinessServices(new BusinessServices());
BusinessService bs = new BusinessService();
bs.setBusinessKey("uddi:somebusiness:somebusinesskey");
bs.setServiceKey("uddi:somebusiness:someservicekey");
bs.getName().add(new Name("service SubscriptionCallbackTest1", null));
be.getBusinessServices().getBusinessService().add(bs);
BusinessEntity register = clerk.register(be);
logger.info("Registered business keygen: " + register.getBusinessKey());
//start up our listener
BindingTemplate start = SubscriptionCallbackListener.start(manager, "default");
Assert.assertNotNull(start);
if (TckCommon.isDebug()) {
PrintUDDI<BindingTemplate> p = new PrintUDDI<BindingTemplate>();
logger.info(p.print(start));
}
//register for callbacks
SubscriptionCallbackListener.registerCallback(this);
Subscription sub = new Subscription();
sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000));
sub.setBindingKey(start.getBindingKey());
sub.setSubscriptionFilter(new SubscriptionFilter());
sub.getSubscriptionFilter().setFindBusiness(new FindBusiness());
sub.getSubscriptionFilter().getFindBusiness().setFindQualifiers(new FindQualifiers());
sub.getSubscriptionFilter().getFindBusiness().getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
sub.getSubscriptionFilter().getFindBusiness().getName().add(new Name(UDDIConstants.WILDCARD, null));
Subscription subscription = clerk.register(sub, clerk.getUDDINode().getApiNode());
if (TckCommon.isDebug()) {
PrintUDDI<Subscription> p2 = new PrintUDDI<Subscription>();
logger.info(p2.print(subscription));
}
Assert.assertNotNull(subscription);
Assert.assertNotNull(subscription.getBindingKey());
Assert.assertNotNull(subscription.getSubscriptionKey());
logger.info("Registered subscription key: " + (subscription.getSubscriptionKey()) + " bindingkey: " + subscription.getBindingKey());
//fetch the business just to verify binding registration
BusinessEntity businessDetail = clerk.getBusinessDetail("uddi:somebusiness:somebusinesskey");
Assert.assertNotNull(businessDetail);
Assert.assertNotNull(businessDetail.getBusinessKey());
Assert.assertNotNull(businessDetail.getBusinessServices());
Assert.assertNotNull(businessDetail.getBusinessServices().getBusinessService().get(0));
Assert.assertNotNull(businessDetail.getBusinessServices().getBusinessService().get(0).getBindingTemplates());
Assert.assertNotNull(businessDetail.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0));
if (TckCommon.isDebug()) {
PrintUDDI<BusinessEntity> p2 = new PrintUDDI<BusinessEntity>();
logger.info(p2.print(businessDetail));
}
//trigger the callback
BusinessEntity trigger = new BusinessEntity();
trigger.getName().add(new Name("somebusiness trigger SubscriptionCallbackTest1", null));
BusinessEntity triggered = clerk.register(trigger);
//wait up to 30 seconds or until we get something
long wait = TckPublisher.getSubscriptionTimeout();
while (wait > 0 && notifications == 0) {
Thread.sleep(1000);
System.out.print(".");
wait--;
}
logger.info("Callback check." + notifications);
//Thread.sleep(2000);
SubscriptionCallbackListener.stop(manager, "default", start.getBindingKey());
clerk.unRegisterSubscription(subscription.getSubscriptionKey());
clerk.unRegisterTModel(createKeyGenator.getTModelKey());
clerk.unRegisterBusiness(triggered.getBusinessKey());
clerk.unRegisterBusiness(businessDetail.getBusinessKey());
//verify
logger.info("Callback check." + notifications);