@Test public void testPull() throws Exception { ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName)); ClientResponse<?> response = request.head(); response.releaseConnection(); Assert.assertEquals(200, response.getStatus()); Link consumers = MessageTestBase.getLinkByTitle( manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions"); System.out.println("pull: " + consumers); response = consumers .request() .formParameter("autoAck", "true") .formParameter("selector", "MyTag = '1'") .post(); response.releaseConnection(); Link consumeOne = MessageTestBase.getLinkByTitle( manager.getQueueManager().getLinkStrategy(), response, "consume-next"); System.out.println("consumeOne: " + consumeOne); response = consumers .request() .formParameter("autoAck", "true") .formParameter("selector", "MyTag = '2'") .post(); response.releaseConnection(); Link consumeTwo = MessageTestBase.getLinkByTitle( manager.getQueueManager().getLinkStrategy(), response, "consume-next"); System.out.println("consumeTwo: " + consumeTwo); // test that Accept header is used to set content-type { Order order = new Order(); order.setName("1"); order.setAmount("$5.00"); publish(topicName, order, null, "1"); order.setName("2"); publish(topicName, order, null, "2"); order.setName("3"); publish(topicName, order, null, "2"); order.setName("4"); publish(topicName, order, null, "1"); order.setName("5"); publish(topicName, order, null, "1"); order.setName("6"); publish(topicName, order, null, "1"); { order.setName("1"); consumeOne = consumeOrder(order, consumeOne); order.setName("2"); consumeTwo = consumeOrder(order, consumeTwo); order.setName("3"); consumeTwo = consumeOrder(order, consumeTwo); order.setName("4"); consumeOne = consumeOrder(order, consumeOne); order.setName("5"); consumeOne = consumeOrder(order, consumeOne); order.setName("6"); consumeOne = consumeOrder(order, consumeOne); } } }
@Test public void testPush() throws Exception { server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(PushReceiver.class); ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName)); ClientResponse<?> response = request.head(); response.releaseConnection(); Assert.assertEquals(200, response.getStatus()); Link consumers = MessageTestBase.getLinkByTitle( manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions"); System.out.println("push: " + consumers); PushTopicRegistration oneReg = new PushTopicRegistration(); oneReg.setDurable(false); XmlLink target = new XmlLink(); target.setMethod("post"); target.setHref(generateURL("/push/one")); target.setType("application/xml"); oneReg.setTarget(target); oneReg.setSelector("MyTag = '1'"); response = consumers.request().body("application/xml", oneReg).post(); response.releaseConnection(); Link oneSubscription = response.getLocation(); PushTopicRegistration twoReg = new PushTopicRegistration(); twoReg.setDurable(false); target = new XmlLink(); target.setMethod("post"); target.setHref(generateURL("/push/two")); target.setType("application/xml"); twoReg.setTarget(target); twoReg.setSelector("MyTag = '2'"); response = consumers.request().body("application/xml", twoReg).post(); response.releaseConnection(); Link twoSubscription = response.getLocation(); Order order = new Order(); order.setName("1"); order.setAmount("$5.00"); publish(topicName, order, null, "1"); Thread.sleep(200); Assert.assertEquals(order, PushReceiver.oneOrder); order.setName("2"); publish(topicName, order, null, "2"); Thread.sleep(200); Assert.assertEquals(order, PushReceiver.twoOrder); order.setName("3"); publish(topicName, order, null, "2"); Thread.sleep(200); Assert.assertEquals(order, PushReceiver.twoOrder); order.setName("4"); publish(topicName, order, null, "1"); Thread.sleep(200); Assert.assertEquals(order, PushReceiver.oneOrder); order.setName("5"); publish(topicName, order, null, "1"); Thread.sleep(200); Assert.assertEquals(order, PushReceiver.oneOrder); order.setName("6"); publish(topicName, order, null, "1"); Thread.sleep(200); Assert.assertEquals(order, PushReceiver.oneOrder); response = oneSubscription.request().delete(); response.releaseConnection(); response = twoSubscription.request().delete(); response.releaseConnection(); }