diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java index fdce616e6d084..8c881ec5c4a64 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java @@ -3,7 +3,6 @@ import java.util.Map; import com.microsoft.windowsazure.configuration.builder.Builder; -import com.microsoft.windowsazure.services.serviceBus.client.MessagingClient; import com.microsoft.windowsazure.services.serviceBus.implementation.BrokerPropertiesMapper; import com.microsoft.windowsazure.services.serviceBus.implementation.EntryModelProvider; import com.microsoft.windowsazure.services.serviceBus.implementation.MarshallerProvider; @@ -20,7 +19,6 @@ public void register(Builder.Registry registry) { registry.add(ServiceBusService.class); registry.add(ServiceBusExceptionProcessor.class); registry.add(ServiceBusRestProxy.class); - registry.add(MessagingClient.class); // alter jersey client config for serviceBus registry.alter(ClientConfig.class, new Builder.Alteration() { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusContract.java index 47eb5fd88e797..e1ddae8f9b8a4 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusContract.java @@ -2,57 +2,76 @@ import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.http.ServiceFilter; -import com.microsoft.windowsazure.services.serviceBus.implementation.Entry; -import com.microsoft.windowsazure.services.serviceBus.implementation.Feed; +import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListRulesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.Message; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.Rule; +import com.microsoft.windowsazure.services.serviceBus.models.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public interface ServiceBusContract { ServiceBusContract withFilter(ServiceFilter filter); void sendQueueMessage(String queueName, Message message) throws ServiceException; - Message receiveQueueMessage(String queueName) throws ServiceException; + ReceiveQueueMessageResult receiveQueueMessage(String queueName) throws ServiceException; - Message receiveQueueMessage(String queueName, ReceiveMessageOptions options) throws ServiceException; + ReceiveQueueMessageResult receiveQueueMessage(String queueName, ReceiveMessageOptions options) throws ServiceException; void sendTopicMessage(String topicName, Message message) throws ServiceException; - Message receiveSubscriptionMessage(String topicName, String subscriptionName) throws ServiceException; + ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName) throws ServiceException; - Message receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) throws ServiceException; + ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) + throws ServiceException; void unlockMessage(Message message) throws ServiceException; void deleteMessage(Message message) throws ServiceException; - Queue createQueue(Queue queue) throws ServiceException; + CreateQueueResult createQueue(Queue queue) throws ServiceException; void deleteQueue(String queueName) throws ServiceException; - Queue getQueue(String queueName) throws ServiceException; + GetQueueResult getQueue(String queueName) throws ServiceException; ListQueuesResult listQueues() throws ServiceException; - Topic createTopic(Topic topic) throws ServiceException; + CreateTopicResult createTopic(Topic topic) throws ServiceException; void deleteTopic(String topicName) throws ServiceException; - Topic getTopic(String topicName) throws ServiceException; + GetTopicResult getTopic(String topicName) throws ServiceException; ListTopicsResult listTopics() throws ServiceException; - void addSubscription(String topicName, String subscriptionName, Entry subscription) throws ServiceException; + CreateSubscriptionResult createSubscription(String topicName, Subscription subscription) throws ServiceException; - void removeSubscription(String topicName, String subscriptionName) throws ServiceException; + void deleteSubscription(String topicName, String subscriptionName) throws ServiceException; - Entry getSubscription(String topicName, String subscriptionName) throws ServiceException; + GetSubscriptionResult getSubscription(String topicName, String subscriptionName) throws ServiceException; - Feed getSubscriptions(String topicName) throws ServiceException; + ListSubscriptionsResult listSubscriptions(String topicName) throws ServiceException; - void addRule(String topicName, String subscriptionName, String ruleName, Entry rule) throws ServiceException; + CreateRuleResult createRule(String topicName, String subscriptionName, Rule rule) throws ServiceException; - void removeRule(String topicName, String subscriptionName, String ruleName) throws ServiceException; + void deleteRule(String topicName, String subscriptionName, String ruleName) throws ServiceException; - Entry getRule(String topicName, String subscriptionName, String ruleName) throws ServiceException; + GetRuleResult getRule(String topicName, String subscriptionName, String ruleName) throws ServiceException; - Feed getRules(String topicName, String subscriptionName) throws ServiceException; + ListRulesResult listRules(String topicName, String subscriptionName) throws ServiceException; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusService.java index eb7abe5d47473..b28c40c1cbc00 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusService.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusService.java @@ -2,11 +2,29 @@ import javax.inject.Inject; -import com.microsoft.windowsazure.services.serviceBus.implementation.Entry; -import com.microsoft.windowsazure.services.serviceBus.implementation.Feed; import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.configuration.Configuration; import com.microsoft.windowsazure.http.ServiceFilter; +import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListRulesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.Message; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.Rule; +import com.microsoft.windowsazure.services.serviceBus.models.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public class ServiceBusService implements ServiceBusContract { final ServiceBusContract next; @@ -41,12 +59,12 @@ public void sendQueueMessage(String queueName, Message message) next.sendQueueMessage(queueName, message); } - public Message receiveQueueMessage(String queueName) + public ReceiveQueueMessageResult receiveQueueMessage(String queueName) throws ServiceException { return next.receiveQueueMessage(queueName); } - public Message receiveQueueMessage(String queueName, + public ReceiveQueueMessageResult receiveQueueMessage(String queueName, ReceiveMessageOptions options) throws ServiceException { return next.receiveQueueMessage(queueName, options); } @@ -56,12 +74,12 @@ public void sendTopicMessage(String topicName, Message message) next.sendTopicMessage(topicName, message); } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName) throws ServiceException { return next.receiveSubscriptionMessage(topicName, subscriptionName); } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) throws ServiceException { return next.receiveSubscriptionMessage(topicName, subscriptionName, @@ -76,7 +94,7 @@ public void deleteMessage(Message message) throws ServiceException { next.deleteMessage(message); } - public Queue createQueue(Queue queue) throws ServiceException { + public CreateQueueResult createQueue(Queue queue) throws ServiceException { return next.createQueue(queue); } @@ -84,7 +102,7 @@ public void deleteQueue(String queueName) throws ServiceException { next.deleteQueue(queueName); } - public Queue getQueue(String queueName) throws ServiceException { + public GetQueueResult getQueue(String queueName) throws ServiceException { return next.getQueue(queueName); } @@ -92,7 +110,7 @@ public ListQueuesResult listQueues() throws ServiceException { return next.listQueues(); } - public Topic createTopic(Topic topic) throws ServiceException { + public CreateTopicResult createTopic(Topic topic) throws ServiceException { return next.createTopic(topic); } @@ -100,7 +118,7 @@ public void deleteTopic(String topicName) throws ServiceException { next.deleteTopic(topicName); } - public Topic getTopic(String topicName) throws ServiceException { + public GetTopicResult getTopic(String topicName) throws ServiceException { return next.getTopic(topicName); } @@ -108,42 +126,41 @@ public ListTopicsResult listTopics() throws ServiceException { return next.listTopics(); } - public void addSubscription(String topicName, String subscriptionName, - Entry subscription) throws ServiceException { - next.addSubscription(topicName, subscriptionName, subscription); + public CreateSubscriptionResult createSubscription(String topicName, Subscription subscription) throws ServiceException { + return next.createSubscription(topicName, subscription); } - public void removeSubscription(String topicName, String subscriptionName) + public void deleteSubscription(String topicName, String subscriptionName) throws ServiceException { - next.removeSubscription(topicName, subscriptionName); + next.deleteSubscription(topicName, subscriptionName); } - public Entry getSubscription(String topicName, String subscriptionName) + public GetSubscriptionResult getSubscription(String topicName, String subscriptionName) throws ServiceException { return next.getSubscription(topicName, subscriptionName); } - public Feed getSubscriptions(String topicName) throws ServiceException { - return next.getSubscriptions(topicName); + public ListSubscriptionsResult listSubscriptions(String topicName) throws ServiceException { + return next.listSubscriptions(topicName); } - public void addRule(String topicName, String subscriptionName, - String ruleName, Entry rule) throws ServiceException { - next.addRule(topicName, subscriptionName, ruleName, rule); + public CreateRuleResult createRule(String topicName, String subscriptionName, + Rule rule) throws ServiceException { + return next.createRule(topicName, subscriptionName, rule); } - public void removeRule(String topicName, String subscriptionName, + public void deleteRule(String topicName, String subscriptionName, String ruleName) throws ServiceException { - next.removeRule(topicName, subscriptionName, ruleName); + next.deleteRule(topicName, subscriptionName, ruleName); } - public Entry getRule(String topicName, String subscriptionName, + public GetRuleResult getRule(String topicName, String subscriptionName, String ruleName) throws ServiceException { return next.getRule(topicName, subscriptionName, ruleName); } - public Feed getRules(String topicName, String subscriptionName) + public ListRulesResult listRules(String topicName, String subscriptionName) throws ServiceException { - return next.getRules(topicName, subscriptionName); + return next.listRules(topicName, subscriptionName); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Topic.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Topic.java deleted file mode 100644 index af9b38bf36caa..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Topic.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.microsoft.windowsazure.services.serviceBus; - -import javax.ws.rs.core.MediaType; - -import com.microsoft.windowsazure.services.serviceBus.implementation.Content; -import com.microsoft.windowsazure.services.serviceBus.implementation.Entry; -import com.microsoft.windowsazure.services.serviceBus.implementation.EntryModel; -import com.microsoft.windowsazure.services.serviceBus.implementation.TopicDescription; - -public class Topic extends EntryModel { - public Topic() { - super(new Entry(), new TopicDescription()); - getEntry().setContent(new Content()); - getEntry().getContent().setType(MediaType.APPLICATION_XML); - getEntry().getContent().setTopicDescription(getModel()); - } - - public Topic(Entry entry) { - super(entry, entry.getContent().getTopicDescription()); - } - - public String getName() { - return getEntry().getTitle(); - } - - public Topic setName(String value) { - getEntry().setTitle(value); - return this; - } -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java index 4c7e9c147493c..295909d50d110 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java @@ -1,6 +1,8 @@ package com.microsoft.windowsazure.services.serviceBus; import com.microsoft.windowsazure.ServiceException; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public class Util { public static Iterable iterateQueues(ServiceBusContract service) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageReceiver.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageReceiver.java deleted file mode 100644 index 96268b4d29721..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageReceiver.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.microsoft.windowsazure.services.serviceBus.client; - -import com.microsoft.windowsazure.ServiceException; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.ReceiveMessageOptions; - -public interface MessageReceiver { - Message receiveMessage() throws ServiceException; - - Message receiveMessage(ReceiveMessageOptions options) throws ServiceException; - - void unlockMessage(Message message) throws ServiceException; - - void deleteMessage(Message message) throws ServiceException; -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageSender.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageSender.java deleted file mode 100644 index 13de652bc2368..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageSender.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.microsoft.windowsazure.services.serviceBus.client; - -import com.microsoft.windowsazure.ServiceException; -import com.microsoft.windowsazure.services.serviceBus.Message; - -public interface MessageSender { - void sendMessage(Message message) throws ServiceException; -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageTransceiver.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageTransceiver.java deleted file mode 100644 index dcc2c17029dad..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageTransceiver.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.microsoft.windowsazure.services.serviceBus.client; - -public interface MessageTransceiver extends MessageSender, MessageReceiver { - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClient.java deleted file mode 100644 index c52c650e206e1..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClient.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.microsoft.windowsazure.services.serviceBus.client; - -import javax.inject.Inject; - -import com.microsoft.windowsazure.ServiceException; -import com.microsoft.windowsazure.configuration.Configuration; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.ReceiveMessageOptions; -import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; - -public class MessagingClient { - private ServiceBusContract service; - - public MessagingClient() throws Exception { - this.setService(Configuration.load().create(ServiceBusContract.class)); - } - - public MessagingClient(String profile) throws Exception { - this.setService(Configuration.load().create(profile, ServiceBusContract.class)); - } - - public MessagingClient(Configuration configuration) throws Exception { - this.setService(configuration.create(ServiceBusContract.class)); - } - - public MessagingClient(String profile, Configuration configuration) throws Exception { - this.setService(configuration.create(profile, ServiceBusContract.class)); - } - - @Inject - public MessagingClient(ServiceBusContract service) { - this.setService(service); - } - - public void setService(ServiceBusContract service) { - this.service = service; - } - - public ServiceBusContract getService() { - return service; - } - - public MessageTransceiver openQueue(String queueName) { - final String queue = queueName; - return new MessageTransceiver() { - - public void sendMessage(Message message) throws ServiceException { - service.sendQueueMessage(queue, message); - } - - public Message receiveMessage() throws ServiceException { - return receiveMessage(ReceiveMessageOptions.DEFAULT); - } - - public Message receiveMessage(ReceiveMessageOptions options) - throws ServiceException { - return service.receiveQueueMessage(queue, options); - } - - public void unlockMessage(Message message) throws ServiceException { - service.unlockMessage(message); - } - - public void deleteMessage(Message message) - throws ServiceException { - service.deleteMessage(message); - } - }; - } - - public MessageSender openTopic(String topicName) { - final String topic = topicName; - return new MessageSender() { - public void sendMessage(Message message) throws ServiceException { - service.sendQueueMessage(topic, message); - } - }; - } - - public MessageReceiver openSubscription(String topicName, String subscriptionName) { - final String topic = topicName; - final String subscription = subscriptionName; - return new MessageReceiver() { - - public Message receiveMessage() throws ServiceException { - return receiveMessage(ReceiveMessageOptions.DEFAULT); - } - - public Message receiveMessage(ReceiveMessageOptions options) - throws ServiceException { - return service.receiveSubscriptionMessage(topic, subscription, options); - } - - public void unlockMessage(Message message) throws ServiceException { - service.unlockMessage(message); - } - - public void deleteMessage(Message message) - throws ServiceException { - service.deleteMessage(message); - } - }; - } -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusExceptionProcessor.java index 215c8a43455b2..9694977e2a062 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusExceptionProcessor.java @@ -7,13 +7,27 @@ import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.http.ServiceFilter; -import com.microsoft.windowsazure.services.serviceBus.ListQueuesResult; -import com.microsoft.windowsazure.services.serviceBus.ListTopicsResult; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.Queue; -import com.microsoft.windowsazure.services.serviceBus.ReceiveMessageOptions; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; -import com.microsoft.windowsazure.services.serviceBus.Topic; +import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListRulesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.Message; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.Rule; +import com.microsoft.windowsazure.services.serviceBus.models.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; import com.microsoft.windowsazure.utils.ServiceExceptionFactory; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.UniformInterfaceException; @@ -54,7 +68,7 @@ public void sendQueueMessage(String path, Message message) } } - public Message receiveQueueMessage(String queueName) + public ReceiveQueueMessageResult receiveQueueMessage(String queueName) throws ServiceException { try { return next.receiveQueueMessage(queueName); @@ -67,7 +81,7 @@ public Message receiveQueueMessage(String queueName) } } - public Message receiveQueueMessage(String queueName, + public ReceiveQueueMessageResult receiveQueueMessage(String queueName, ReceiveMessageOptions options) throws ServiceException { try { return next.receiveQueueMessage(queueName, options); @@ -93,7 +107,7 @@ public void sendTopicMessage(String path, Message message) } } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName) throws ServiceException { try { return next.receiveSubscriptionMessage(topicName, @@ -107,7 +121,7 @@ public Message receiveSubscriptionMessage(String topicName, } } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) throws ServiceException { try { @@ -146,7 +160,7 @@ public void deleteMessage(Message message) throws ServiceException { } } - public Queue createQueue(Queue queue) throws ServiceException { + public CreateQueueResult createQueue(Queue queue) throws ServiceException { try { return next.createQueue(queue); } @@ -170,7 +184,7 @@ public void deleteQueue(String queuePath) throws ServiceException { } } - public Queue getQueue(String queuePath) throws ServiceException { + public GetQueueResult getQueue(String queuePath) throws ServiceException { try { return next.getQueue(queuePath); } @@ -194,7 +208,7 @@ public ListQueuesResult listQueues() throws ServiceException { } } - public Topic createTopic(Topic topic) throws ServiceException { + public CreateTopicResult createTopic(Topic topic) throws ServiceException { try { return next.createTopic(topic); } @@ -218,7 +232,7 @@ public void deleteTopic(String topicPath) throws ServiceException { } } - public Topic getTopic(String topicPath) throws ServiceException { + public GetTopicResult getTopic(String topicPath) throws ServiceException { try { return next.getTopic(topicPath); } @@ -242,10 +256,9 @@ public ListTopicsResult listTopics() throws ServiceException { } } - public void addSubscription(String topicPath, String subscriptionName, - Entry subscription) throws ServiceException { + public CreateSubscriptionResult createSubscription(String topicPath, Subscription subscription) throws ServiceException { try { - next.addSubscription(topicPath, subscriptionName, subscription); + return next.createSubscription(topicPath, subscription); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -255,10 +268,10 @@ public void addSubscription(String topicPath, String subscriptionName, } } - public void removeSubscription(String topicPath, String subscriptionName) + public void deleteSubscription(String topicPath, String subscriptionName) throws ServiceException { try { - next.removeSubscription(topicPath, subscriptionName); + next.deleteSubscription(topicPath, subscriptionName); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -268,7 +281,7 @@ public void removeSubscription(String topicPath, String subscriptionName) } } - public Entry getSubscription(String topicPath, String subscriptionName) + public GetSubscriptionResult getSubscription(String topicPath, String subscriptionName) throws ServiceException { try { return next.getSubscription(topicPath, subscriptionName); @@ -281,9 +294,9 @@ public Entry getSubscription(String topicPath, String subscriptionName) } } - public Feed getSubscriptions(String topicPath) throws ServiceException { + public ListSubscriptionsResult listSubscriptions(String topicPath) throws ServiceException { try { - return next.getSubscriptions(topicPath); + return next.listSubscriptions(topicPath); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -293,10 +306,10 @@ public Feed getSubscriptions(String topicPath) throws ServiceException { } } - public void addRule(String topicPath, String subscriptionName, - String ruleName, Entry rule) throws ServiceException { + public CreateRuleResult createRule(String topicPath, String subscriptionName, + Rule rule) throws ServiceException { try { - next.addRule(topicPath, subscriptionName, ruleName, rule); + return next.createRule(topicPath, subscriptionName, rule); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -306,10 +319,10 @@ public void addRule(String topicPath, String subscriptionName, } } - public void removeRule(String topicPath, String subscriptionName, + public void deleteRule(String topicPath, String subscriptionName, String ruleName) throws ServiceException { try { - next.removeRule(topicPath, subscriptionName, ruleName); + next.deleteRule(topicPath, subscriptionName, ruleName); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -319,7 +332,7 @@ public void removeRule(String topicPath, String subscriptionName, } } - public Entry getRule(String topicPath, String subscriptionName, + public GetRuleResult getRule(String topicPath, String subscriptionName, String ruleName) throws ServiceException { try { return next.getRule(topicPath, subscriptionName, ruleName); @@ -332,10 +345,10 @@ public Entry getRule(String topicPath, String subscriptionName, } } - public Feed getRules(String topicPath, String subscriptionName) + public ListRulesResult listRules(String topicPath, String subscriptionName) throws ServiceException { try { - return next.getRules(topicPath, subscriptionName); + return next.listRules(topicPath, subscriptionName); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java index 8f307f999ae15..f4c11d9f2b53a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java @@ -15,13 +15,27 @@ import com.microsoft.windowsazure.auth.wrap.WrapFilter; import com.microsoft.windowsazure.http.ClientFilterAdapter; import com.microsoft.windowsazure.http.ServiceFilter; -import com.microsoft.windowsazure.services.serviceBus.ListQueuesResult; -import com.microsoft.windowsazure.services.serviceBus.ListTopicsResult; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.Queue; -import com.microsoft.windowsazure.services.serviceBus.ReceiveMessageOptions; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; -import com.microsoft.windowsazure.services.serviceBus.Topic; +import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetQueueResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetRuleResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListRulesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.Message; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.Rule; +import com.microsoft.windowsazure.services.serviceBus.models.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; @@ -103,18 +117,23 @@ public void sendQueueMessage(String path, Message message) throws ServiceExcepti sendMessage(path, message); } - public Message receiveQueueMessage(String queueName) + public ReceiveQueueMessageResult receiveQueueMessage(String queueName) throws ServiceException { return receiveQueueMessage(queueName, ReceiveMessageOptions.DEFAULT); } - public Message receiveQueueMessage(String queuePath, ReceiveMessageOptions options) throws ServiceException { + public ReceiveQueueMessageResult receiveQueueMessage(String queuePath, ReceiveMessageOptions options) throws ServiceException { WebResource resource = getResource() .path(queuePath) .path("messages") .path("head"); + Message message = receiveMessage(options, resource); + return new ReceiveQueueMessageResult(message); + } + + private Message receiveMessage(ReceiveMessageOptions options, WebResource resource) { if (options.getTimeout() != null) { resource = resource.queryParam("timeout", Integer.toString(options.getTimeout())); } @@ -135,36 +154,42 @@ else if (options.isPeekLock()) { MediaType contentType = clientResult.getType(); Date date = clientResult.getResponseDate(); - Message result = new Message(); + Message message = new Message(); if (brokerProperties != null) { - result.setProperties(mapper.fromString(brokerProperties)); + message.setProperties(mapper.fromString(brokerProperties)); } if (contentType != null) { - result.setContentType(contentType.toString()); + message.setContentType(contentType.toString()); } if (location != null) { - result.getProperties().setLockLocation(location); + message.getProperties().setLockLocation(location); } - result.setDate(date); - result.setBody(clientResult.getEntityInputStream()); - return result; + message.setDate(date); + message.setBody(clientResult.getEntityInputStream()); + return message; } public void sendTopicMessage(String topicName, Message message) throws ServiceException { sendMessage(topicName, message); } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName) throws ServiceException { - // TODO Auto-generated method stub - return null; + return receiveSubscriptionMessage(topicName, subscriptionName, ReceiveMessageOptions.DEFAULT); } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) throws ServiceException { - // TODO Auto-generated method stub - return null; + WebResource resource = getResource() + .path(topicName) + .path("subscriptions") + .path(subscriptionName) + .path("messages") + .path("head"); + + Message message = receiveMessage(options, resource); + return new ReceiveSubscriptionMessageResult(message); } public void unlockMessage(Message message) throws ServiceException { @@ -179,11 +204,11 @@ public void deleteMessage(Message message) throws ServiceException { .delete(); } - public Queue createQueue(Queue entry) throws ServiceException { - return getResource() + public CreateQueueResult createQueue(Queue entry) throws ServiceException { + return new CreateQueueResult(getResource() .path(entry.getName()) - .type("application/atom+xml")//;type=entry;charset=utf-8") - .put(Queue.class, entry); + .type("application/atom+xml;type=entry;charset=utf-8") + .put(Queue.class, entry)); } public void deleteQueue(String queuePath) throws ServiceException { @@ -192,10 +217,10 @@ public void deleteQueue(String queuePath) throws ServiceException { .delete(); } - public Queue getQueue(String queuePath) throws ServiceException { - return getResource() + public GetQueueResult getQueue(String queuePath) throws ServiceException { + return new GetQueueResult(getResource() .path(queuePath) - .get(Queue.class); + .get(Queue.class)); } public ListQueuesResult listQueues() throws ServiceException { @@ -211,11 +236,11 @@ public ListQueuesResult listQueues() throws ServiceException { return result; } - public Topic createTopic(Topic entry) throws ServiceException { - return getResource() + public CreateTopicResult createTopic(Topic entry) throws ServiceException { + return new CreateTopicResult(getResource() .path(entry.getName()) - .type("application/atom+xml")//;type=entry;charset=utf-8") - .put(Topic.class, entry); + .type("application/atom+xml;type=entry;charset=utf-8") + .put(Topic.class, entry)); } public void deleteTopic(String TopicPath) throws ServiceException { @@ -224,10 +249,10 @@ public void deleteTopic(String TopicPath) throws ServiceException { .delete(); } - public Topic getTopic(String TopicPath) throws ServiceException { - return getResource() + public GetTopicResult getTopic(String TopicPath) throws ServiceException { + return new GetTopicResult(getResource() .path(TopicPath) - .get(Topic.class); + .get(Topic.class)); } public ListTopicsResult listTopics() throws ServiceException { @@ -243,48 +268,93 @@ public ListTopicsResult listTopics() throws ServiceException { return result; } - public void addSubscription(String topicPath, String subscriptionName, - Entry subscription) { - // TODO Auto-generated method stub - + public CreateSubscriptionResult createSubscription(String topicPath, Subscription subscription) { + return new CreateSubscriptionResult(getResource() + .path(topicPath) + .path("subscriptions") + .path(subscription.getName()) + .type("application/atom+xml;type=entry;charset=utf-8") + .put(Subscription.class, subscription)); } - public void removeSubscription(String topicPath, String subscriptionName) { - // TODO Auto-generated method stub - + public void deleteSubscription(String topicPath, String subscriptionName) { + getResource() + .path(topicPath) + .path("subscriptions") + .path(subscriptionName) + .delete(); } - public Entry getSubscription(String topicPath, String subscriptionName) { - // TODO Auto-generated method stub - return null; + public GetSubscriptionResult getSubscription(String topicPath, String subscriptionName) { + return new GetSubscriptionResult(getResource() + .path(topicPath) + .path("subscriptions") + .path(subscriptionName) + .get(Subscription.class)); } - public Feed getSubscriptions(String topicPath) { - // TODO Auto-generated method stub - return null; + public ListSubscriptionsResult listSubscriptions(String topicPath) { + Feed feed = getResource() + .path(topicPath) + .path("subscriptions") + .get(Feed.class); + ArrayList list = new ArrayList(); + for (Entry entry : feed.getEntries()) { + list.add(new Subscription(entry)); + } + ListSubscriptionsResult result = new ListSubscriptionsResult(); + result.setItems(list); + return result; } - public void addRule(String topicPath, String subscriptionName, - String ruleName, Entry rule) { - // TODO Auto-generated method stub - + public CreateRuleResult createRule(String topicPath, String subscriptionName, + Rule rule) { + return new CreateRuleResult(getResource() + .path(topicPath) + .path("subscriptions") + .path(subscriptionName) + .path("rules") + .path(rule.getName()) + .type("application/atom+xml;type=entry;charset=utf-8") + .put(Rule.class, rule)); } - public void removeRule(String topicPath, String subscriptionName, + public void deleteRule(String topicPath, String subscriptionName, String ruleName) { - // TODO Auto-generated method stub - + getResource() + .path(topicPath) + .path("subscriptions") + .path(subscriptionName) + .path("rules") + .path(ruleName) + .delete(); } - public Entry getRule(String topicPath, String subscriptionName, + public GetRuleResult getRule(String topicPath, String subscriptionName, String ruleName) { - // TODO Auto-generated method stub - return null; + return new GetRuleResult(getResource() + .path(topicPath) + .path("subscriptions") + .path(subscriptionName) + .path("rules") + .path(ruleName) + .get(Rule.class)); } - public Feed getRules(String topicPath, String subscriptionName) { - // TODO Auto-generated method stub - return null; + public ListRulesResult listRules(String topicPath, String subscriptionName) { + Feed feed = getResource() + .path(topicPath) + .path("subscriptions") + .path(subscriptionName) + .path("rules") + .get(Feed.class); + ArrayList list = new ArrayList(); + for (Entry entry : feed.getEntries()) { + list.add(new Rule(entry)); + } + ListRulesResult result = new ListRulesResult(); + result.setItems(list); + return result; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateQueueResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateQueueResult.java new file mode 100644 index 0000000000000..85107629fb02f --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateQueueResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class CreateQueueResult { + + private Queue value; + + public CreateQueueResult(Queue value) { + this.setValue(value); + } + + public void setValue(Queue value) { + this.value = value; + } + + public Queue getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateRuleResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateRuleResult.java new file mode 100644 index 0000000000000..114e189b22a3b --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateRuleResult.java @@ -0,0 +1,19 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +public class CreateRuleResult { + + private Rule value; + + public CreateRuleResult(Rule value) { + this.setValue(value); + } + + public void setValue(Rule value) { + this.value = value; + } + + public Rule getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateSubscriptionResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateSubscriptionResult.java new file mode 100644 index 0000000000000..3b74257241380 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateSubscriptionResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class CreateSubscriptionResult { + + private Subscription value; + + public CreateSubscriptionResult(Subscription value) { + this.setValue(value); + } + + public void setValue(Subscription value) { + this.value = value; + } + + public Subscription getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateTopicResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateTopicResult.java new file mode 100644 index 0000000000000..10192e3e454a2 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateTopicResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class CreateTopicResult { + + private Topic value; + + public CreateTopicResult(Topic value) { + this.setValue(value); + } + + public void setValue(Topic value) { + this.value = value; + } + + public Topic getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetQueueResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetQueueResult.java new file mode 100644 index 0000000000000..005b5a5a8c1f0 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetQueueResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class GetQueueResult { + + private Queue value; + + public GetQueueResult(Queue value) { + this.setValue(value); + } + + public void setValue(Queue value) { + this.value = value; + } + + public Queue getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetRuleResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetRuleResult.java new file mode 100644 index 0000000000000..d4d49839298a0 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetRuleResult.java @@ -0,0 +1,19 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +public class GetRuleResult { + + private Rule value; + + public GetRuleResult(Rule value) { + this.setValue(value); + } + + public void setValue(Rule value) { + this.value = value; + } + + public Rule getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetSubscriptionResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetSubscriptionResult.java new file mode 100644 index 0000000000000..4e28a6137f1ca --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetSubscriptionResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class GetSubscriptionResult { + + private Subscription value; + + public GetSubscriptionResult(Subscription value) { + this.setValue(value); + } + + public void setValue(Subscription value) { + this.value = value; + } + + public Subscription getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetTopicResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetTopicResult.java new file mode 100644 index 0000000000000..5c6a0af54619c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetTopicResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class GetTopicResult { + + private Topic value; + + public GetTopicResult(Topic value) { + this.setValue(value); + } + + public void setValue(Topic value) { + this.value = value; + } + + public Topic getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListQueuesResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java similarity index 66% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListQueuesResult.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java index a6af5fd05c4ed..cfe755389d9ad 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListQueuesResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java @@ -1,12 +1,13 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import java.util.List; + public class ListQueuesResult { private List items; - List getItems() { + public List getItems() { return items; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListRulesResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListRulesResult.java new file mode 100644 index 0000000000000..8917fc0b04111 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListRulesResult.java @@ -0,0 +1,17 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import java.util.List; + +public class ListRulesResult { + + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListSubscriptionsResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListSubscriptionsResult.java new file mode 100644 index 0000000000000..4624ba154806e --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListSubscriptionsResult.java @@ -0,0 +1,17 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import java.util.List; + + +public class ListSubscriptionsResult { + + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListTopicsResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java similarity index 66% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListTopicsResult.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java index 25476ebc85b1b..5d3047674426e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListTopicsResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java @@ -1,12 +1,13 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import java.util.List; + public class ListTopicsResult { private List items; - List getItems() { + public List getItems() { return items; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Message.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Message.java similarity index 99% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Message.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Message.java index 59a4455191c8d..d0a82299965de 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Message.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Message.java @@ -1,4 +1,4 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Queue.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Queue.java similarity index 98% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Queue.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Queue.java index 39dc2d42bae13..2bfb8506fe2b0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Queue.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Queue.java @@ -1,4 +1,4 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import javax.ws.rs.core.MediaType; import javax.xml.datatype.Duration; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ReceiveMessageOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveMessageOptions.java similarity index 94% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ReceiveMessageOptions.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveMessageOptions.java index f78b77f11083c..f9bda855f4ea9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ReceiveMessageOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveMessageOptions.java @@ -1,4 +1,5 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; + public class ReceiveMessageOptions { Integer timeout; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ReceiveMode.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveMode.java similarity index 51% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ReceiveMode.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveMode.java index 10ae6c5130440..195c2fa8ad7c6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ReceiveMode.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveMode.java @@ -1,4 +1,4 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; public enum ReceiveMode { PEEK_LOCK, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveQueueMessageResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveQueueMessageResult.java new file mode 100644 index 0000000000000..5e6e31989fbc7 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveQueueMessageResult.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + + +public class ReceiveQueueMessageResult { + + private Message value; + + public ReceiveQueueMessageResult(Message value) { + this.setValue(value); + } + + public void setValue(Message value) { + this.value = value; + } + + public Message getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveSubscriptionMessageResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveSubscriptionMessageResult.java new file mode 100644 index 0000000000000..3666750e431eb --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveSubscriptionMessageResult.java @@ -0,0 +1,19 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +public class ReceiveSubscriptionMessageResult { + + private Message value; + + public ReceiveSubscriptionMessageResult(Message value) { + this.setValue(value); + } + + public void setValue(Message value) { + this.value = value; + } + + public Message getValue() { + return value; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Rule.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Rule.java new file mode 100644 index 0000000000000..20f696d7730e3 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Rule.java @@ -0,0 +1,57 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import javax.ws.rs.core.MediaType; + +import com.microsoft.windowsazure.services.serviceBus.implementation.Content; +import com.microsoft.windowsazure.services.serviceBus.implementation.Entry; +import com.microsoft.windowsazure.services.serviceBus.implementation.EntryModel; +import com.microsoft.windowsazure.services.serviceBus.implementation.Filter; +import com.microsoft.windowsazure.services.serviceBus.implementation.RuleAction; +import com.microsoft.windowsazure.services.serviceBus.implementation.RuleDescription; + +public class Rule extends EntryModel { + + public Rule() { + super(new Entry(), new RuleDescription()); + getEntry().setContent(new Content()); + getEntry().getContent().setType(MediaType.APPLICATION_XML); + getEntry().getContent().setRuleDescription(getModel()); + } + + public Rule(Entry entry) { + super(entry, entry.getContent().getRuleDescription()); + } + + public Rule(String name) { + this(); + setName(name); + } + + public String getName() { + return getEntry().getTitle(); + } + + public Rule setName(String value) { + getEntry().setTitle(value); + return this; + } + + public Filter getFilter() { + return getModel().getFilter(); + } + + public Rule setFilter(Filter value) { + getModel().setFilter(value); + return this; + } + + public RuleAction getAction() { + return getModel().getAction(); + } + + public Rule setAction(RuleAction value) { + getModel().setAction(value); + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Subscription.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Subscription.java similarity index 98% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Subscription.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Subscription.java index 70df4b1eee7da..5076f7f350b88 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Subscription.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Subscription.java @@ -1,4 +1,4 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import javax.ws.rs.core.MediaType; import javax.xml.datatype.Duration; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Topic.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Topic.java new file mode 100644 index 0000000000000..c8b08f1d585ad --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Topic.java @@ -0,0 +1,86 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import javax.ws.rs.core.MediaType; +import javax.xml.datatype.Duration; + +import com.microsoft.windowsazure.services.serviceBus.implementation.Content; +import com.microsoft.windowsazure.services.serviceBus.implementation.Entry; +import com.microsoft.windowsazure.services.serviceBus.implementation.EntryModel; +import com.microsoft.windowsazure.services.serviceBus.implementation.TopicDescription; + +public class Topic extends EntryModel { + public Topic() { + super(new Entry(), new TopicDescription()); + getEntry().setContent(new Content()); + getEntry().getContent().setType(MediaType.APPLICATION_XML); + getEntry().getContent().setTopicDescription(getModel()); + } + + public Topic(Entry entry) { + super(entry, entry.getContent().getTopicDescription()); + } + + public Topic(String name) { + this(); + setName(name); + } + + public String getName() { + return getEntry().getTitle(); + } + + public Topic setName(String value) { + getEntry().setTitle(value); + return this; + } + + public Duration getDefaultMessageTimeToLive() { + return getModel().getDefaultMessageTimeToLive(); + } + + public Topic setDefaultMessageTimeToLive(Duration value) { + getModel().setDefaultMessageTimeToLive(value); + return this; + } + + public Long getMaxSizeInMegabytes() { + return getModel().getMaxSizeInMegabytes(); + } + + public Topic setMaxSizeInMegabytes(Long value) { + getModel().setMaxSizeInMegabytes(value); + return this; + } + + public Boolean isRequiresDuplicateDetection() { + return getModel().isRequiresDuplicateDetection(); + } + + public Topic setRequiresDuplicateDetection(Boolean value) { + getModel().setRequiresDuplicateDetection(value); + return this; + } + + public Duration getDuplicateDetectionHistoryTimeWindow() { + return getModel().getDuplicateDetectionHistoryTimeWindow(); + } + + public Topic setDuplicateDetectionHistoryTimeWindow(Duration value) { + getModel().setDuplicateDetectionHistoryTimeWindow(value); + return this; + } + + public Boolean isEnableBatchedOperations() { + return getModel().isEnableBatchedOperations(); + } + + public Topic setEnableBatchedOperations(Boolean value) { + getModel().setEnableBatchedOperations(value); + return this; + } + + public Long getSizeInBytes() { + return getModel().getSizeInBytes(); + } + +} diff --git a/microsoft-azure-api/src/main/resources/servicebus-atom.xsd b/microsoft-azure-api/src/main/resources/servicebus-atom.xsd index 6b319fbb89fb2..b8387023a54be 100644 --- a/microsoft-azure-api/src/main/resources/servicebus-atom.xsd +++ b/microsoft-azure-api/src/main/resources/servicebus-atom.xsd @@ -30,6 +30,7 @@ + diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/IntegrationTestBase.java index 1ad04051f637c..0dbc7fbb6fceb 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/IntegrationTestBase.java @@ -6,11 +6,11 @@ import org.junit.BeforeClass; import com.microsoft.windowsazure.configuration.Configuration; -import com.microsoft.windowsazure.services.serviceBus.Queue; -import com.microsoft.windowsazure.services.serviceBus.ReceiveMessageOptions; import com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; -import com.microsoft.windowsazure.services.serviceBus.Topic; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public abstract class IntegrationTestBase { protected Configuration createConfiguration() { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index 8903f7b66cfaf..0f47e6e3b9ee4 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java @@ -15,13 +15,16 @@ import com.microsoft.windowsazure.http.ServiceFilter; import com.microsoft.windowsazure.http.ServiceFilter.Request; import com.microsoft.windowsazure.http.ServiceFilter.Response; -import com.microsoft.windowsazure.services.serviceBus.ListQueuesResult; -import com.microsoft.windowsazure.services.serviceBus.ListTopicsResult; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.Queue; -import com.microsoft.windowsazure.services.serviceBus.ReceiveMessageOptions; -import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; -import com.microsoft.windowsazure.services.serviceBus.Topic; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListRulesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.Message; +import com.microsoft.windowsazure.services.serviceBus.models.Queue; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.Rule; +import com.microsoft.windowsazure.services.serviceBus.models.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public class ServiceBusIntegrationTest extends IntegrationTestBase { @@ -42,7 +45,7 @@ public void fetchQueueAndListQueuesWorks() throws Exception { // Arrange // Act - Queue entry = service.getQueue("TestAlpha"); + Queue entry = service.getQueue("TestAlpha").getValue(); ListQueuesResult feed = service.listQueues(); // Assert @@ -56,7 +59,7 @@ public void createQueueWorks() throws Exception { // Act Queue queue = new Queue("TestCreateQueueWorks").setMaxSizeInMegabytes(1024L); - Queue saved = service.createQueue(queue); + Queue saved = service.createQueue(queue).getValue(); // Assert assertNotNull(saved); @@ -94,7 +97,7 @@ public void receiveMessageWorks() throws Exception { service.sendQueueMessage(queueName, new Message("Hello World")); // Act - Message message = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS); + Message message = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS).getValue(); byte[] data = new byte[100]; int size = message.getBody().read(data); @@ -111,7 +114,7 @@ public void peekLockMessageWorks() throws Exception { service.sendQueueMessage(queueName, new Message("Hello Again")); // Act - Message message = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS); + Message message = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS).getValue(); // Assert byte[] data = new byte[100]; @@ -126,7 +129,7 @@ public void peekLockedMessageCanBeCompleted() throws Exception { String queueName = "TestPeekLockedMessageCanBeCompleted"; service.createQueue(new Queue(queueName)); service.sendQueueMessage(queueName, new Message("Hello Again")); - Message message = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS); + Message message = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS).getValue(); // Act String lockToken = message.getLockToken(); @@ -147,14 +150,14 @@ public void peekLockedMessageCanBeUnlocked() throws Exception { String queueName = "TestPeekLockedMessageCanBeUnlocked"; service.createQueue(new Queue(queueName)); service.sendQueueMessage(queueName, new Message("Hello Again")); - Message peekedMessage = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS); + Message peekedMessage = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS).getValue(); // Act String lockToken = peekedMessage.getLockToken(); Date lockedUntil = peekedMessage.getLockedUntilUtc(); service.unlockMessage(peekedMessage); - Message receivedMessage = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS); + Message receivedMessage = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS).getValue(); // Assert assertNotNull(lockToken); @@ -169,14 +172,14 @@ public void peekLockedMessageCanBeDeleted() throws Exception { String queueName = "TestPeekLockedMessageCanBeDeleted"; service.createQueue(new Queue(queueName)); service.sendQueueMessage(queueName, new Message("Hello Again")); - Message peekedMessage = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS); + Message peekedMessage = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS).getValue(); // Act String lockToken = peekedMessage.getLockToken(); Date lockedUntil = peekedMessage.getLockedUntilUtc(); service.deleteMessage(peekedMessage); - Message receivedMessage = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS); + Message receivedMessage = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS).getValue(); // Assert assertNotNull(lockToken); @@ -195,7 +198,7 @@ public void contentTypePassesThrough() throws Exception { service.sendQueueMessage(queueName, new Message("Hello Again").setContentType("text/xml")); - Message message = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS); + Message message = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS).getValue(); // Assert assertNotNull(message); @@ -208,9 +211,9 @@ public void topicCanBeCreatedListedFetchedAndDeleted() throws ServiceException { String topicName = "TestTopicCanBeCreatedListedFetchedAndDeleted"; // Act - Topic created = service.createTopic(new Topic().setName(topicName)); + Topic created = service.createTopic(new Topic().setName(topicName)).getValue(); ListTopicsResult listed = service.listTopics(); - Topic fetched = service.getTopic(topicName); + Topic fetched = service.getTopic(topicName).getValue(); service.deleteTopic(topicName); ListTopicsResult listed2 = service.listTopics(); @@ -239,11 +242,171 @@ public Response handle(Request request, Next next) { }); // Act - Queue created = filtered.createQueue(new Queue("TestFilterCanSeeAndChangeRequestOrResponse")); + Queue created = filtered.createQueue(new Queue("TestFilterCanSeeAndChangeRequestOrResponse")).getValue(); // Assert assertNotNull(created); assertEquals(1, requests.size()); assertEquals(1, responses.size()); } + + @Test + public void subscriptionsCanBeCreatedOnTopics() throws Exception { + // Arrange + String topicName = "TestSubscriptionsCanBeCreatedOnTopics"; + service.createTopic(new Topic(topicName)); + + // Act + Subscription created = service.createSubscription(topicName, new Subscription("MySubscription")).getValue(); + + // Assert + assertNotNull(created); + assertEquals("MySubscription", created.getName()); + } + + @Test + public void subscriptionsCanBeListed() throws Exception { + // Arrange + String topicName = "TestSubscriptionsCanBeListed"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("MySubscription2")); + + // Act + ListSubscriptionsResult result = service.listSubscriptions(topicName); + + // Assert + assertNotNull(result); + assertEquals(1, result.getItems().size()); + assertEquals("MySubscription2", result.getItems().get(0).getName()); + } + + @Test + public void subscriptionsDetailsMayBeFetched() throws Exception { + // Arrange + String topicName = "TestSubscriptionsDetailsMayBeFetched"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("MySubscription3")); + + // Act + Subscription result = service.getSubscription(topicName, "MySubscription3").getValue(); + + // Assert + assertNotNull(result); + assertEquals("MySubscription3", result.getName()); + } + + @Test + public void subscriptionsMayBeDeleted() throws Exception { + // Arrange + String topicName = "TestSubscriptionsMayBeDeleted"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("MySubscription4")); + service.createSubscription(topicName, new Subscription("MySubscription5")); + + // Act + service.deleteSubscription(topicName, "MySubscription4"); + + // Assert + ListSubscriptionsResult result = service.listSubscriptions(topicName); + assertNotNull(result); + assertEquals(1, result.getItems().size()); + assertEquals("MySubscription5", result.getItems().get(0).getName()); + } + + @Test + public void subscriptionWillReceiveMessage() throws Exception { + // Arrange + String topicName = "TestSubscriptionWillReceiveMessage"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("sub")); + service.sendTopicMessage(topicName, new Message("

Testing subscription

").setContentType("text/html")); + + // Act + Message message = service.receiveSubscriptionMessage(topicName, "sub", RECEIVE_AND_DELETE_5_SECONDS).getValue(); + + // Assert + assertNotNull(message); + + byte[] data = new byte[100]; + int size = message.getBody().read(data); + assertEquals("

Testing subscription

", new String(data, 0, size)); + assertEquals("text/html", message.getContentType()); + } + + @Test + public void rulesCanBeCreatedOnSubscriptions() throws Exception { + // Arrange + String topicName = "TestrulesCanBeCreatedOnSubscriptions"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("sub")); + + // Act + Rule created = service.createRule(topicName, "sub", new Rule("MyRule1")).getValue(); + + // Assert + assertNotNull(created); + assertEquals("MyRule1", created.getName()); + } + + @Test + public void rulesCanBeListedAndDefaultRuleIsPrecreated() throws Exception { + // Arrange + String topicName = "TestrulesCanBeListedAndDefaultRuleIsPrecreated"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("sub")); + service.createRule(topicName, "sub", new Rule("MyRule2")); + + // Act + ListRulesResult result = service.listRules(topicName, "sub"); + + // Assert + assertNotNull(result); + assertEquals(2, result.getItems().size()); + Rule rule0 = result.getItems().get(0); + Rule rule1 = result.getItems().get(1); + if (rule0.getName() == "MyRule2") { + Rule swap = rule1; + rule1 = rule0; + rule0 = swap; + } + + assertEquals("$Default", rule0.getName()); + assertEquals("MyRule2", rule1.getName()); + assertNotNull(result.getItems().get(0).getModel()); + } + + @Test + public void ruleDetailsMayBeFetched() throws Exception { + // Arrange + String topicName = "TestruleDetailsMayBeFetched"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("sub")); + + // Act + Rule result = service.getRule(topicName, "sub", "$Default").getValue(); + + // Assert + assertNotNull(result); + assertEquals("$Default", result.getName()); + } + + @Test + public void rulesMayBeDeleted() throws Exception { + // Arrange + String topicName = "TestRulesMayBeDeleted"; + service.createTopic(new Topic(topicName)); + service.createSubscription(topicName, new Subscription("sub")); + service.createRule(topicName, "sub", new Rule("MyRule4")); + service.createRule(topicName, "sub", new Rule("MyRule5")); + + // Act + service.deleteRule(topicName, "sub", "MyRule5"); + service.deleteRule(topicName, "sub", "$Default"); + + // Assert + ListRulesResult result = service.listRules(topicName, "sub"); + assertNotNull(result); + assertEquals(1, result.getItems().size()); + assertEquals("MyRule4", result.getItems().get(0).getName()); + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClientIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClientIntegrationTest.java deleted file mode 100644 index 02b2ad454002d..0000000000000 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClientIntegrationTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.microsoft.windowsazure.services.serviceBus.client; - -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -import com.microsoft.windowsazure.services.serviceBus.IntegrationTestBase; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.client.MessageReceiver; -import com.microsoft.windowsazure.services.serviceBus.client.MessageSender; -import com.microsoft.windowsazure.services.serviceBus.client.MessageTransceiver; -import com.microsoft.windowsazure.services.serviceBus.client.MessagingClient; - -public class MessagingClientIntegrationTest extends IntegrationTestBase { - - private MessagingClient messaging; - - @Before - public void createClient() throws Exception { - messaging = createConfiguration().create(MessagingClient.class); - } - - @Test - public void queueWillSendAndReceiveMessages() throws Exception { - // Arrange - MessageTransceiver port = messaging.openQueue("TestAlpha"); - Message messageOut = new Message("queueWillSendAndReceiveMessages"); - - // Act - port.sendMessage(messageOut); - Message messageIn = port.receiveMessage(); - - // Assert - assertNotSame(messageOut, messageIn); - - byte[] data = new byte[100]; - int size = messageIn.getBody().read(data); - assertEquals(31, size); - assertEquals("queueWillSendAndReceiveMessages", new String(data, 0, size)); - } - - @Test - public void queueIsSenderAndReceiver() throws Exception { - // Arrange - MessageSender sender = messaging.openQueue("TestAlpha"); - MessageReceiver receiver = messaging.openQueue("TestAlpha"); - Message messageOut = new Message("queueIsSenderAndReceiver"); - - // Act - sender.sendMessage(messageOut); - Message messageIn = receiver.receiveMessage(); - - // Assert - assertNotSame(messageOut, messageIn); - - byte[] data = new byte[100]; - int size = messageIn.getBody().read(data); - assertEquals(24, size); - assertEquals("queueIsSenderAndReceiver", new String(data, 0, size)); - } - - @Test - public void clientMayBeCreatedDirectly() throws Exception { - // Arrange - - // Act - MessagingClient mc = new MessagingClient(createConfiguration()); - mc.openQueue("TestAlpha").sendMessage(new Message("clientMayBeCreatedDirectly")); - - // Assert - } - -}