From be09f31fe097b71b274186fcd879eed0dab113cf Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Mon, 11 Mar 2013 16:52:32 -0700 Subject: [PATCH] throw exception when you create or update null message. --- .../ChunkedGoalStateDeserializer.java | 16 +++--- .../XmlGoalStateDeserializer.java | 16 +++--- .../queue/implementation/QueueRestProxy.java | 14 ++++-- .../queue/QueueServiceIntegrationTest.java | 49 ++++++++++++++++--- 4 files changed, 67 insertions(+), 28 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/ChunkedGoalStateDeserializer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/ChunkedGoalStateDeserializer.java index 38ed6c4a4812c..9d592a94327db 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/ChunkedGoalStateDeserializer.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/ChunkedGoalStateDeserializer.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.microsoft.windowsazure.serviceruntime; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/XmlGoalStateDeserializer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/XmlGoalStateDeserializer.java index 700e9e33d1863..688e5dfc6ef5f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/XmlGoalStateDeserializer.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/serviceruntime/XmlGoalStateDeserializer.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.microsoft.windowsazure.serviceruntime; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java index 5f3c663c37db3..454f51e44c9d7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java @@ -87,7 +87,8 @@ public QueueRestProxy(HttpURLConnectionClient channel, ServiceFilter[] filters, public QueueContract withFilter(ServiceFilter filter) { ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); newFilters[filters.length] = filter; - return new QueueRestProxy(this.channel, newFilters, this.accountName, this.url, this.sharedKeyFilter, this.dateMapper); + return new QueueRestProxy(this.channel, newFilters, this.accountName, this.url, this.sharedKeyFilter, + this.dateMapper); } private void ThrowIfError(ClientResponse r) { @@ -261,7 +262,10 @@ public void createMessage(String queue, String messageText) throws ServiceExcept @Override public void createMessage(String queue, String messageText, CreateMessageOptions options) throws ServiceException { if (queue == null) - throw new NullPointerException(); + throw new NullPointerException("queue"); + if (messageText == null) { + throw new NullPointerException("messageText"); + } WebResource webResource = getResource(options).path(queue).path("messages"); webResource = addOptionalQueryParam(webResource, "visibilitytimeout", options.getVisibilityTimeoutInSeconds()); @@ -286,9 +290,11 @@ public UpdateMessageResult updateMessage(String queue, String messageId, String public UpdateMessageResult updateMessage(String queue, String messageId, String popReceipt, String messageText, int visibilityTimeoutInSeconds, QueueServiceOptions options) throws ServiceException { if (queue == null) - throw new NullPointerException(); + throw new NullPointerException("queue"); if (messageId == null) - throw new NullPointerException(); + throw new NullPointerException("messageId"); + if (messageText == null) + throw new NullPointerException("messageText"); WebResource webResource = getResource(options).path(queue).path("messages").path(messageId); webResource = addOptionalQueryParam(webResource, "popreceipt", popReceipt); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java index 0380a7be8942e..ecfeb03a02596 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.microsoft.windowsazure.services.queue; @@ -25,7 +25,9 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import com.microsoft.windowsazure.services.core.Configuration; import com.microsoft.windowsazure.services.queue.models.CreateQueueOptions; @@ -58,6 +60,9 @@ public class QueueServiceIntegrationTest extends IntegrationTestBase { private static String[] creatableQueues; private static String[] testQueues; + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @BeforeClass public static void setup() throws Exception { // Setup container names array (list of container names used by @@ -315,6 +320,17 @@ public void createMessageWorks() throws Exception { // Assert } + @Test + public void createNullMessageException() throws Exception { + // Arrange + Configuration config = createConfiguration(); + QueueContract service = QueueService.create(config); + + // Act + expectedException.expect(NullPointerException.class); + service.createMessage(TEST_QUEUE_FOR_MESSAGES, null); + } + @Test public void listMessagesWorks() throws Exception { // Arrange @@ -508,6 +524,23 @@ public void deleteMessageWorks() throws Exception { assertEquals(3, result2.getQueueMessages().size()); } + @Test + public void updateNullMessageException() throws Exception { + // Arrange + Configuration config = createConfiguration(); + QueueContract service = QueueService.create(config); + String messageId = "messageId"; + + String popReceipt = "popReceipt"; + String messageText = null; + int visibilityTimeoutInSeconds = 10; + + // Act + expectedException.expect(NullPointerException.class); + service.updateMessage(TEST_QUEUE_FOR_MESSAGES_8, messageId, popReceipt, messageText, visibilityTimeoutInSeconds); + + } + @Test public void updateMessageWorks() throws Exception { // Arrange