@Test public void testSubscribe() throws IOException, JSONException, UnexpectedReplyTypeException { Subscription sub = new Subscription(); Endpoint end = sub.new Endpoint(); sub.setSubscriptionType(EndpointType.http); end.setMethod(HttpMethod.get); end.setUrl("http://www.example.com/"); Hashtable<String, String> headers = new Hashtable<String, String>(); headers.put("Content-Type", "application/x-www-form-urlencoded"); end.setHeaders(headers); end.setBody("Hello World!"); sub.setEndpoint(end); Topic topic = new Topic(); topic.setName("testSubscriptionTopic"); TopicResponse topResponse = client.getTopicClient().create(topic); assert (topResponse.getMessage().equalsIgnoreCase("Object created")); SubscriptionResponse subResponse = client.getTopicClient().subscribe(topic.getName(), sub); assert (subResponse.getMessage().equalsIgnoreCase("Object created")); }
@Test public void testDeleteSubscription() throws IOException, JSONException, UnexpectedReplyTypeException { Topic topic = new Topic(); topic.setName("testDeleteSubscription"); TopicResponse topicResponse = client.getTopicClient().create(topic); assert (topicResponse.getMessage().equals("Object created")); Subscription subscription = new Subscription(); Endpoint endpoint = subscription.new Endpoint(); endpoint.setMethod(HttpMethod.get); endpoint.setUrl("http://www.example.com/"); subscription.setEndpoint(endpoint); subscription.setSubscriptionType(EndpointType.http); SubscriptionResponse subscriptionResponse = client.getTopicClient().subscribe(topic.getName(), subscription); topicResponse = client.getTopicClient().deleteSubscription(topic.getName(), subscriptionResponse.getId()); assert (topicResponse.getMessage().equalsIgnoreCase("Object queued for deletion")); }
@Test public void testCreate() throws IOException, JSONException, UnexpectedReplyTypeException { Topic t = new Topic(); t.setName(topicName); t.setTags(new String[] {"java", "topic", "tags"}); TopicResponse response = client.getTopicClient().create(t); assert (response.getName().equalsIgnoreCase(topicName)); }
@Test public void testPostMessage() throws IOException, JSONException, UnexpectedReplyTypeException { Message topicMessage = new Message(); topicMessage.setBody("Bam!!! Right through your topic"); MessageResponse response = client.getTopicClient().postMessage(topicName, topicMessage); assert (response.getMessage().equalsIgnoreCase("Object created")); }
@Test public void testGetSubscriptions() throws IOException, JSONException, UnexpectedReplyTypeException { Topic topic = new Topic(); topic.setName("testGetSubscriptions"); client.getTopicClient().create(topic); Subscription subscription = new Subscription(); Endpoint endpoint = subscription.new Endpoint(); endpoint.setMethod(HttpMethod.get); endpoint.setUrl("http://www.example.com/"); subscription.setEndpoint(endpoint); subscription.setSubscriptionType(EndpointType.http); client.getTopicClient().subscribe(topic.getName(), subscription); SubscriptionResponse subResponse = client.getTopicClient().getSubscriptions(topic.getName()); assert (subResponse.getItems().length > 0); }
@Test public void testList() throws IOException, JSONException, UnexpectedReplyTypeException { Topic[] topics = client.getTopicClient().list(); assert (topics.length > 0); }
@Test public void testGetString() throws IOException, JSONException, UnexpectedReplyTypeException { Topic response = client.getTopicClient().get(topicName); assert (response.getName().equalsIgnoreCase(topicName)); }
@Test public void testDeleteStringBoolean() throws IOException, JSONException, UnexpectedReplyTypeException { TopicResponse response = client.getTopicClient().delete(topicName, true); assert (response.getMessage().equalsIgnoreCase("Object queued for deletion")); }