From ab43525988def0fec74aa9b09a3737552bc24d22 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Fri, 11 Nov 2011 13:59:39 -0800 Subject: [PATCH 1/8] Adding delegate methods to Topic --- .../services/serviceBus/Topic.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) 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 index af9b38bf36caa..38ca9a1100cae 100644 --- 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 @@ -1,6 +1,7 @@ package com.microsoft.windowsazure.services.serviceBus; 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; @@ -19,6 +20,11 @@ public Topic(Entry entry) { super(entry, entry.getContent().getTopicDescription()); } + public Topic(String name) { + this(); + setName(name); + } + public String getName() { return getEntry().getTitle(); } @@ -27,4 +33,54 @@ 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(); + } + } From 455dded713c5120c112e613c48aa6e25eb74e40f Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 12:24:52 -0800 Subject: [PATCH 2/8] Building out REST operations over Subscription entry --- .../serviceBus/ListSubscriptionsResult.java | 16 +++++ .../serviceBus/ServiceBusContract.java | 8 +-- .../serviceBus/ServiceBusService.java | 19 +++-- .../ServiceBusExceptionProcessor.java | 17 ++--- .../implementation/ServiceBusRestProxy.java | 48 +++++++++---- .../serviceBus/ServiceBusIntegrationTest.java | 71 +++++++++++++++++-- 6 files changed, 136 insertions(+), 43 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListSubscriptionsResult.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListSubscriptionsResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListSubscriptionsResult.java new file mode 100644 index 0000000000000..263321fbe4a01 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListSubscriptionsResult.java @@ -0,0 +1,16 @@ +package com.microsoft.windowsazure.services.serviceBus; + +import java.util.List; + +public class ListSubscriptionsResult { + + private List items; + + 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/ServiceBusContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusContract.java index 47eb5fd88e797..529fa605161d1 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 @@ -40,13 +40,13 @@ public interface ServiceBusContract { ListTopicsResult listTopics() throws ServiceException; - void addSubscription(String topicName, String subscriptionName, Entry subscription) throws ServiceException; + Subscription 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; + Subscription 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; 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..0bc16bfd2e59c 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,11 @@ 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.implementation.Entry; +import com.microsoft.windowsazure.services.serviceBus.implementation.Feed; public class ServiceBusService implements ServiceBusContract { final ServiceBusContract next; @@ -108,23 +108,22 @@ 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 Subscription 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 Subscription 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, 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..c22e6c42067b1 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 @@ -8,11 +8,13 @@ import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.http.ServiceFilter; import com.microsoft.windowsazure.services.serviceBus.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.ListSubscriptionsResult; 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.Subscription; import com.microsoft.windowsazure.services.serviceBus.Topic; import com.microsoft.windowsazure.utils.ServiceExceptionFactory; import com.sun.jersey.api.client.ClientHandlerException; @@ -242,10 +244,9 @@ public ListTopicsResult listTopics() throws ServiceException { } } - public void addSubscription(String topicPath, String subscriptionName, - Entry subscription) throws ServiceException { + public Subscription 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 +256,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 +269,7 @@ public void removeSubscription(String topicPath, String subscriptionName) } } - public Entry getSubscription(String topicPath, String subscriptionName) + public Subscription getSubscription(String topicPath, String subscriptionName) throws ServiceException { try { return next.getSubscription(topicPath, subscriptionName); @@ -281,9 +282,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)); 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..0c1e11848d833 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 @@ -16,11 +16,13 @@ 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.ListSubscriptionsResult; 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.Subscription; import com.microsoft.windowsazure.services.serviceBus.Topic; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; @@ -214,7 +216,7 @@ public ListQueuesResult listQueues() throws ServiceException { public Topic createTopic(Topic entry) throws ServiceException { return getResource() .path(entry.getName()) - .type("application/atom+xml")//;type=entry;charset=utf-8") + .type("application/atom+xml;type=entry;charset=utf-8") .put(Topic.class, entry); } @@ -243,25 +245,43 @@ public ListTopicsResult listTopics() throws ServiceException { return result; } - public void addSubscription(String topicPath, String subscriptionName, - Entry subscription) { - // TODO Auto-generated method stub - + public Subscription createSubscription(String topicPath, Subscription subscription) { + return 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 Subscription getSubscription(String topicPath, String subscriptionName) { + return 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, 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..65739474223f7 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,6 @@ 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; public class ServiceBusIntegrationTest extends IntegrationTestBase { @@ -246,4 +239,68 @@ public Response handle(Request request, Next next) { 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")); + + // 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"); + + // 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()); + + } } From 6b2c865560f524ec1c0ddbc7f7d4143c55db27ba Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 12:28:17 -0800 Subject: [PATCH 3/8] Removing stateful messaging client This code is better as a sample --- .../services/serviceBus/Exports.java | 2 - .../serviceBus/client/MessageReceiver.java | 15 --- .../serviceBus/client/MessageSender.java | 8 -- .../serviceBus/client/MessageTransceiver.java | 5 - .../serviceBus/client/MessagingClient.java | 104 ------------------ .../MessagingClientIntegrationTest.java | 74 ------------- 6 files changed, 208 deletions(-) delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageReceiver.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageSender.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessageTransceiver.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClient.java delete mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/client/MessagingClientIntegrationTest.java 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/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/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 - } - -} From b61ffc436c7051d62d2230540e1dcbc48eff3041 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 14:15:10 -0800 Subject: [PATCH 4/8] Refactoring ServiceBusContract methods for review notes Standardizes result DTO class conventions Introduces serviceBus.models package for results and options --- .../serviceBus/ServiceBusContract.java | 33 +++++--- .../serviceBus/ServiceBusService.java | 32 +++++--- .../ServiceBusExceptionProcessor.java | 36 +++++---- .../implementation/ServiceBusRestProxy.java | 76 ++++++++++--------- .../serviceBus/models/CreateQueueResult.java | 21 +++++ .../models/CreateSubscriptionResult.java | 21 +++++ .../serviceBus/models/CreateTopicResult.java | 21 +++++ .../serviceBus/models/GetQueueResult.java | 21 +++++ .../models/GetSubscriptionResult.java | 21 +++++ .../serviceBus/models/GetTopicResult.java | 21 +++++ .../{ => models}/ListQueuesResult.java | 6 +- .../{ => models}/ListSubscriptionsResult.java | 6 +- .../{ => models}/ListTopicsResult.java | 6 +- .../{ => models}/ReceiveMessageOptions.java | 3 +- .../serviceBus/{ => models}/ReceiveMode.java | 2 +- .../models/ReceiveQueueMessageResult.java | 21 +++++ .../ReceiveSubscriptionMessageResult.java | 5 ++ .../serviceBus/IntegrationTestBase.java | 2 +- .../serviceBus/ServiceBusIntegrationTest.java | 35 +++++---- 19 files changed, 296 insertions(+), 93 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateQueueResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateSubscriptionResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateTopicResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetQueueResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetSubscriptionResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetTopicResult.java rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/ListQueuesResult.java (55%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/ListSubscriptionsResult.java (55%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/ListTopicsResult.java (55%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/ReceiveMessageOptions.java (94%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/ReceiveMode.java (51%) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveQueueMessageResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveSubscriptionMessageResult.java 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 529fa605161d1..7c530fac5b4f8 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 @@ -4,47 +4,60 @@ 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.CreateSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetQueueResult; +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.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult; 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; - Subscription createSubscription(String topicName, Subscription subscription) throws ServiceException; + CreateSubscriptionResult createSubscription(String topicName, Subscription subscription) throws ServiceException; void deleteSubscription(String topicName, String subscriptionName) throws ServiceException; - Subscription getSubscription(String topicName, String subscriptionName) throws ServiceException; + GetSubscriptionResult getSubscription(String topicName, String subscriptionName) throws ServiceException; ListSubscriptionsResult listSubscriptions(String topicName) 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 0bc16bfd2e59c..fb7863908b173 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 @@ -7,6 +7,18 @@ 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.CreateSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetQueueResult; +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.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult; public class ServiceBusService implements ServiceBusContract { final ServiceBusContract next; @@ -41,12 +53,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 +68,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 +88,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 +96,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 +104,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 +112,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,7 +120,7 @@ public ListTopicsResult listTopics() throws ServiceException { return next.listTopics(); } - public Subscription createSubscription(String topicName, Subscription subscription) throws ServiceException { + public CreateSubscriptionResult createSubscription(String topicName, Subscription subscription) throws ServiceException { return next.createSubscription(topicName, subscription); } @@ -117,7 +129,7 @@ public void deleteSubscription(String topicName, String subscriptionName) next.deleteSubscription(topicName, subscriptionName); } - public Subscription getSubscription(String topicName, String subscriptionName) + public GetSubscriptionResult getSubscription(String topicName, String subscriptionName) throws ServiceException { return next.getSubscription(topicName, subscriptionName); } 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 c22e6c42067b1..e6b0272e02ce7 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,15 +7,23 @@ import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.http.ServiceFilter; -import com.microsoft.windowsazure.services.serviceBus.ListQueuesResult; -import com.microsoft.windowsazure.services.serviceBus.ListSubscriptionsResult; -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.Subscription; import com.microsoft.windowsazure.services.serviceBus.Topic; +import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; +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.GetSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +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.utils.ServiceExceptionFactory; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.UniformInterfaceException; @@ -56,7 +64,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); @@ -69,7 +77,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); @@ -95,7 +103,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, @@ -109,7 +117,7 @@ public Message receiveSubscriptionMessage(String topicName, } } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) throws ServiceException { try { @@ -148,7 +156,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); } @@ -172,7 +180,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); } @@ -196,7 +204,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); } @@ -220,7 +228,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); } @@ -244,7 +252,7 @@ public ListTopicsResult listTopics() throws ServiceException { } } - public Subscription createSubscription(String topicPath, Subscription subscription) throws ServiceException { + public CreateSubscriptionResult createSubscription(String topicPath, Subscription subscription) throws ServiceException { try { return next.createSubscription(topicPath, subscription); } @@ -269,7 +277,7 @@ public void deleteSubscription(String topicPath, String subscriptionName) } } - public Subscription getSubscription(String topicPath, String subscriptionName) + public GetSubscriptionResult getSubscription(String topicPath, String subscriptionName) throws ServiceException { try { return next.getSubscription(topicPath, subscriptionName); 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 0c1e11848d833..f7f6d13181b4d 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,15 +15,23 @@ 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.ListSubscriptionsResult; -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.Subscription; import com.microsoft.windowsazure.services.serviceBus.Topic; +import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; +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.GetSubscriptionResult; +import com.microsoft.windowsazure.services.serviceBus.models.GetTopicResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +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.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; @@ -105,12 +113,12 @@ 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) @@ -137,32 +145,32 @@ 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 new ReceiveQueueMessageResult(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; } - public Message receiveSubscriptionMessage(String topicName, + public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName, ReceiveMessageOptions options) throws ServiceException { // TODO Auto-generated method stub @@ -181,11 +189,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 { @@ -194,10 +202,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 { @@ -213,11 +221,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); + .put(Topic.class, entry)); } public void deleteTopic(String TopicPath) throws ServiceException { @@ -226,10 +234,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 { @@ -245,13 +253,13 @@ public ListTopicsResult listTopics() throws ServiceException { return result; } - public Subscription createSubscription(String topicPath, Subscription subscription) { - return getResource() + 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); + .put(Subscription.class, subscription)); } public void deleteSubscription(String topicPath, String subscriptionName) { @@ -262,12 +270,12 @@ public void deleteSubscription(String topicPath, String subscriptionName) { .delete(); } - public Subscription getSubscription(String topicPath, String subscriptionName) { - return getResource() + public GetSubscriptionResult getSubscription(String topicPath, String subscriptionName) { + return new GetSubscriptionResult(getResource() .path(topicPath) .path("subscriptions") .path(subscriptionName) - .get(Subscription.class); + .get(Subscription.class)); } public ListSubscriptionsResult listSubscriptions(String topicPath) { 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..f8eaa0349f6f3 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateQueueResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Queue; + +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/CreateSubscriptionResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateSubscriptionResult.java new file mode 100644 index 0000000000000..1e600e6e02214 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateSubscriptionResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Subscription; + +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..0e5cf9a04505f --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateTopicResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Topic; + +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..fd6032caf3334 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetQueueResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Queue; + +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/GetSubscriptionResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetSubscriptionResult.java new file mode 100644 index 0000000000000..fd3f4ad17260e --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetSubscriptionResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Subscription; + +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..eea050fc6c222 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetTopicResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Topic; + +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 55% 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..6b2c4812ebcc7 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,14 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import java.util.List; +import com.microsoft.windowsazure.services.serviceBus.Queue; + 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/ListSubscriptionsResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListSubscriptionsResult.java similarity index 55% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListSubscriptionsResult.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListSubscriptionsResult.java index 263321fbe4a01..4fa900852cc9f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/ListSubscriptionsResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListSubscriptionsResult.java @@ -1,12 +1,14 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import java.util.List; +import com.microsoft.windowsazure.services.serviceBus.Subscription; + public class ListSubscriptionsResult { private List items; - List getItems() { + public List getItems() { return 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 55% 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..64d3b468e8ea4 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,14 @@ -package com.microsoft.windowsazure.services.serviceBus; +package com.microsoft.windowsazure.services.serviceBus.models; import java.util.List; +import com.microsoft.windowsazure.services.serviceBus.Topic; + 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/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..d7a6fb03c6ff1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveQueueMessageResult.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +import com.microsoft.windowsazure.services.serviceBus.Message; + +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..f886781c427ab --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveSubscriptionMessageResult.java @@ -0,0 +1,5 @@ +package com.microsoft.windowsazure.services.serviceBus.models; + +public class ReceiveSubscriptionMessageResult { + +} 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..d5a1a1bd2d579 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 @@ -7,10 +7,10 @@ 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.ReceiveMessageOptions; 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 65739474223f7..d40a38dfbff14 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,6 +15,10 @@ 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.models.ListQueuesResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListSubscriptionsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; public class ServiceBusIntegrationTest extends IntegrationTestBase { @@ -35,7 +39,7 @@ public void fetchQueueAndListQueuesWorks() throws Exception { // Arrange // Act - Queue entry = service.getQueue("TestAlpha"); + Queue entry = service.getQueue("TestAlpha").getValue(); ListQueuesResult feed = service.listQueues(); // Assert @@ -49,7 +53,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); @@ -87,7 +91,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); @@ -104,7 +108,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]; @@ -119,7 +123,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(); @@ -140,14 +144,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); @@ -162,14 +166,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); @@ -188,7 +192,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); @@ -201,9 +205,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(); @@ -232,7 +236,7 @@ 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); @@ -247,7 +251,7 @@ public void subscriptionsCanBeCreatedOnTopics() throws Exception { service.createTopic(new Topic(topicName)); // Act - Subscription created = service.createSubscription(topicName, new Subscription("MySubscription")); + Subscription created = service.createSubscription(topicName, new Subscription("MySubscription")).getValue(); // Assert assertNotNull(created); @@ -278,7 +282,7 @@ public void subscriptionsDetailsMayBeFetched() throws Exception { service.createSubscription(topicName, new Subscription("MySubscription3")); // Act - Subscription result = service.getSubscription(topicName, "MySubscription3"); + Subscription result = service.getSubscription(topicName, "MySubscription3").getValue(); // Assert assertNotNull(result); @@ -301,6 +305,5 @@ public void subscriptionsMayBeDeleted() throws Exception { assertNotNull(result); assertEquals(1, result.getItems().size()); assertEquals("MySubscription5", result.getItems().get(0).getName()); - } } From 656fe6c364d71ba5d6fa094bfa0b37021fcdc1b4 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 14:54:43 -0800 Subject: [PATCH 5/8] Moving domain objects into models package --- .../services/serviceBus/ServiceBusContract.java | 4 ++++ .../services/serviceBus/ServiceBusService.java | 4 ++++ .../microsoft/windowsazure/services/serviceBus/Util.java | 2 ++ .../implementation/ServiceBusExceptionProcessor.java | 8 ++++---- .../serviceBus/implementation/ServiceBusRestProxy.java | 8 ++++---- .../services/serviceBus/models/CreateQueueResult.java | 1 - .../serviceBus/models/CreateSubscriptionResult.java | 1 - .../services/serviceBus/models/CreateTopicResult.java | 1 - .../services/serviceBus/models/GetQueueResult.java | 1 - .../services/serviceBus/models/GetSubscriptionResult.java | 1 - .../services/serviceBus/models/GetTopicResult.java | 1 - .../services/serviceBus/models/ListQueuesResult.java | 1 - .../serviceBus/models/ListSubscriptionsResult.java | 1 - .../services/serviceBus/models/ListTopicsResult.java | 1 - .../services/serviceBus/{ => models}/Message.java | 2 +- .../services/serviceBus/{ => models}/Queue.java | 2 +- .../serviceBus/models/ReceiveQueueMessageResult.java | 1 - .../services/serviceBus/{ => models}/Subscription.java | 2 +- .../services/serviceBus/{ => models}/Topic.java | 2 +- .../services/serviceBus/IntegrationTestBase.java | 4 ++-- .../services/serviceBus/ServiceBusIntegrationTest.java | 4 ++++ 21 files changed, 28 insertions(+), 24 deletions(-) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/Message.java (99%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/Queue.java (98%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/Subscription.java (98%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/{ => models}/Topic.java (97%) 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 7c530fac5b4f8..dc7f0deeade1b 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 @@ -13,9 +13,13 @@ import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; 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.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public interface ServiceBusContract { ServiceBusContract withFilter(ServiceFilter filter); 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 fb7863908b173..45ee452ffeaec 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 @@ -16,9 +16,13 @@ import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; 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.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public class ServiceBusService implements ServiceBusContract { final ServiceBusContract next; 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/implementation/ServiceBusExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusExceptionProcessor.java index e6b0272e02ce7..4a9fb4b6a4f93 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,11 +7,7 @@ import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.http.ServiceFilter; -import com.microsoft.windowsazure.services.serviceBus.Message; -import com.microsoft.windowsazure.services.serviceBus.Queue; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; -import com.microsoft.windowsazure.services.serviceBus.Subscription; -import com.microsoft.windowsazure.services.serviceBus.Topic; import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; import com.microsoft.windowsazure.services.serviceBus.models.CreateSubscriptionResult; import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; @@ -21,9 +17,13 @@ import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; 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.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; 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 f7f6d13181b4d..8bd0946c9f997 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,11 +15,7 @@ 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.Message; -import com.microsoft.windowsazure.services.serviceBus.Queue; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; -import com.microsoft.windowsazure.services.serviceBus.Subscription; -import com.microsoft.windowsazure.services.serviceBus.Topic; import com.microsoft.windowsazure.services.serviceBus.models.CreateQueueResult; import com.microsoft.windowsazure.services.serviceBus.models.CreateSubscriptionResult; import com.microsoft.windowsazure.services.serviceBus.models.CreateTopicResult; @@ -29,9 +25,13 @@ import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; 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.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; 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 index f8eaa0349f6f3..85107629fb02f 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Queue; public class CreateQueueResult { 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 index 1e600e6e02214..3b74257241380 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Subscription; public class CreateSubscriptionResult { 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 index 0e5cf9a04505f..10192e3e454a2 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Topic; public class CreateTopicResult { 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 index fd6032caf3334..005b5a5a8c1f0 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Queue; public class GetQueueResult { 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 index fd3f4ad17260e..4e28a6137f1ca 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Subscription; public class GetSubscriptionResult { 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 index eea050fc6c222..5c6a0af54619c 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Topic; public class GetTopicResult { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java index 6b2c4812ebcc7..cfe755389d9ad 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListQueuesResult.java @@ -2,7 +2,6 @@ import java.util.List; -import com.microsoft.windowsazure.services.serviceBus.Queue; public class ListQueuesResult { 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 index 4fa900852cc9f..4624ba154806e 100644 --- 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 @@ -2,7 +2,6 @@ import java.util.List; -import com.microsoft.windowsazure.services.serviceBus.Subscription; public class ListSubscriptionsResult { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java index 64d3b468e8ea4..5d3047674426e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListTopicsResult.java @@ -2,7 +2,6 @@ import java.util.List; -import com.microsoft.windowsazure.services.serviceBus.Topic; public class ListTopicsResult { 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/models/ReceiveQueueMessageResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ReceiveQueueMessageResult.java index d7a6fb03c6ff1..5e6e31989fbc7 100644 --- 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 @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.serviceBus.models; -import com.microsoft.windowsazure.services.serviceBus.Message; public class ReceiveQueueMessageResult { 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/Topic.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Topic.java similarity index 97% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Topic.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Topic.java index 38ca9a1100cae..c8b08f1d585ad 100644 --- 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/models/Topic.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/test/java/com/microsoft/windowsazure/services/serviceBus/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/IntegrationTestBase.java index d5a1a1bd2d579..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.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 d40a38dfbff14..2c3066e692746 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 @@ -18,7 +18,11 @@ import com.microsoft.windowsazure.services.serviceBus.models.ListQueuesResult; 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.Subscription; +import com.microsoft.windowsazure.services.serviceBus.models.Topic; public class ServiceBusIntegrationTest extends IntegrationTestBase { From 25f0aedbcb65e3df105827d8de1b7399aead4c85 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 15:16:03 -0800 Subject: [PATCH 6/8] Implementing receiveMessage operation for subscription --- .../implementation/ServiceBusRestProxy.java | 21 ++++++++++++++----- .../ReceiveSubscriptionMessageResult.java | 14 +++++++++++++ .../serviceBus/ServiceBusIntegrationTest.java | 20 ++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) 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 8bd0946c9f997..78ebd91a7194c 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 @@ -125,6 +125,11 @@ public ReceiveQueueMessageResult receiveQueueMessage(String queuePath, ReceiveMe .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())); } @@ -157,7 +162,7 @@ else if (options.isPeekLock()) { } message.setDate(date); message.setBody(clientResult.getEntityInputStream()); - return new ReceiveQueueMessageResult(message); + return message; } public void sendTopicMessage(String topicName, Message message) throws ServiceException { @@ -166,15 +171,21 @@ public void sendTopicMessage(String topicName, Message message) throws ServiceEx public ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, String subscriptionName) throws ServiceException { - // TODO Auto-generated method stub - return null; + return receiveSubscriptionMessage(topicName, subscriptionName, ReceiveMessageOptions.DEFAULT); } 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 { 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 index f886781c427ab..3666750e431eb 100644 --- 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 @@ -2,4 +2,18 @@ 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/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index 2c3066e692746..fd8f891c91b48 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 @@ -310,4 +310,24 @@ public void subscriptionsMayBeDeleted() throws Exception { 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()); + } } From 8793eb1d3fdf1e8cc4b66badb00a9e6044a3ddb8 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 15:54:41 -0800 Subject: [PATCH 7/8] Implementing rule entity methods --- .../serviceBus/ServiceBusContract.java | 14 ++-- .../serviceBus/ServiceBusService.java | 22 +++--- .../ServiceBusExceptionProcessor.java | 20 +++-- .../implementation/ServiceBusRestProxy.java | 57 ++++++++++--- .../serviceBus/models/CreateRuleResult.java | 19 +++++ .../serviceBus/models/GetRuleResult.java | 19 +++++ .../serviceBus/models/ListRulesResult.java | 17 ++++ .../services/serviceBus/models/Rule.java | 36 +++++++++ .../src/main/resources/servicebus-atom.xsd | 1 + .../serviceBus/ServiceBusIntegrationTest.java | 79 +++++++++++++++++++ 10 files changed, 247 insertions(+), 37 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/CreateRuleResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/GetRuleResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/ListRulesResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Rule.java 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 dc7f0deeade1b..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,15 +2,16 @@ 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; @@ -18,6 +19,7 @@ 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; @@ -65,11 +67,11 @@ ReceiveSubscriptionMessageResult receiveSubscriptionMessage(String topicName, St 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 45ee452ffeaec..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 @@ -5,15 +5,16 @@ import com.microsoft.windowsazure.ServiceException; import com.microsoft.windowsazure.configuration.Configuration; 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; @@ -21,6 +22,7 @@ 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; @@ -142,23 +144,23 @@ public ListSubscriptionsResult listSubscriptions(String topicName) throws Servic 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/implementation/ServiceBusExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusExceptionProcessor.java index 4a9fb4b6a4f93..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 @@ -9,12 +9,15 @@ import com.microsoft.windowsazure.http.ServiceFilter; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; 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; @@ -22,6 +25,7 @@ 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; @@ -302,10 +306,10 @@ public ListSubscriptionsResult listSubscriptions(String topicPath) throws Servic } } - 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)); @@ -315,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)); @@ -328,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); @@ -341,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 78ebd91a7194c..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 @@ -17,12 +17,15 @@ import com.microsoft.windowsazure.http.ServiceFilter; import com.microsoft.windowsazure.services.serviceBus.ServiceBusContract; 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; @@ -30,6 +33,7 @@ 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; @@ -303,27 +307,54 @@ public ListSubscriptionsResult listSubscriptions(String topicPath) { 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/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/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/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/Rule.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Rule.java new file mode 100644 index 0000000000000..a78a721f601c1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/Rule.java @@ -0,0 +1,36 @@ +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.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; + } +} 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/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index fd8f891c91b48..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 @@ -16,11 +16,13 @@ import com.microsoft.windowsazure.http.ServiceFilter.Request; import com.microsoft.windowsazure.http.ServiceFilter.Response; 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; @@ -330,4 +332,81 @@ public void subscriptionWillReceiveMessage() throws Exception { 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()); + } } From af4f094d5bc1de9ea72be1fb61fd7ec8ee12a275 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 14 Nov 2011 15:57:48 -0800 Subject: [PATCH 8/8] Adding delegate methods from Rule to RuleDescription --- .../services/serviceBus/models/Rule.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 index a78a721f601c1..20f696d7730e3 100644 --- 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 @@ -5,6 +5,8 @@ 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 { @@ -33,4 +35,23 @@ 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; + } + }