-
Notifications
You must be signed in to change notification settings - Fork 202
Validate empty string attributes #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...esting-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/MessageAttributesTests.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package org.elasticmq.rest.sqs | ||
|
|
||
| import com.amazonaws.services.sqs.model._ | ||
| import org.scalatest.OptionValues | ||
| import org.scalatest.matchers.should.Matchers | ||
|
|
||
| import scala.jdk.CollectionConverters.{ListHasAsScala, MapHasAsJava} | ||
|
|
||
| class MessageAttributesTests extends SqsClientServerCommunication with Matchers with OptionValues { | ||
|
|
||
| test("Sending message with empty attribute value and String data type should result in error") { | ||
| val queueUrl = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl | ||
|
|
||
| val ex = the[AmazonSQSException] thrownBy client.sendMessage( | ||
| new SendMessageRequest(queueUrl, "Message 1") | ||
| .addMessageAttributesEntry("attribute1", new MessageAttributeValue().withStringValue("").withDataType("String")) | ||
| ) | ||
|
|
||
| ex.getMessage should include("Attribute 'attribute1' must contain a non-empty value of type 'String") | ||
| } | ||
|
|
||
| test("Sending message with empty attribute value and Number data type should result in error") { | ||
| val queueUrl = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl | ||
|
|
||
| val ex = the[AmazonSQSException] thrownBy client.sendMessage( | ||
| new SendMessageRequest(queueUrl, "Message 1") | ||
| .addMessageAttributesEntry("attribute1", new MessageAttributeValue().withStringValue("").withDataType("Number")) | ||
| ) | ||
|
|
||
| ex.getMessage should include("Attribute 'attribute1' must contain a non-empty value of type 'Number") | ||
| } | ||
|
|
||
| test("Sending message with empty attribute type should result in error") { | ||
| val queueUrl = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl | ||
|
|
||
| val ex = the[AmazonSQSException] thrownBy client.sendMessage( | ||
| new SendMessageRequest(queueUrl, "Message 1") | ||
| .addMessageAttributesEntry("attribute1", new MessageAttributeValue().withStringValue("value").withDataType("")) | ||
| ) | ||
|
|
||
| ex.getMessage should include("Attribute 'attribute1' must contain a non-empty attribute type") | ||
| } | ||
|
|
||
| test( | ||
| "Sending message in batch should result in accepting only those messages that do not have empty message attributes" | ||
| ) { | ||
| val queueUrl = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl | ||
|
|
||
| val resp = client.sendMessageBatch( | ||
| new SendMessageBatchRequest(queueUrl).withEntries( | ||
| new SendMessageBatchRequestEntry("1", "Message 1").withMessageAttributes( | ||
| Map( | ||
| "attribute1" -> new MessageAttributeValue().withStringValue("value1").withDataType("String") | ||
| ).asJava | ||
| ), | ||
| new SendMessageBatchRequestEntry("2", "Message 2").withMessageAttributes( | ||
| Map( | ||
| "attribute1" -> new MessageAttributeValue().withStringValue("").withDataType("String") | ||
| ).asJava | ||
| ), | ||
| new SendMessageBatchRequestEntry("3", "Message 3").withMessageAttributes( | ||
| Map( | ||
| "attribute1" -> new MessageAttributeValue().withStringValue("value1").withDataType("String") | ||
| ).asJava | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| resp.getSuccessful should have size 2 | ||
|
|
||
| val receiveMessageResponse = | ||
| client.receiveMessage(new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(3)) | ||
| receiveMessageResponse.getMessages.asScala should have size 2 | ||
| receiveMessageResponse.getMessages.asScala | ||
| .map(message => message.getBody) | ||
| .foreach(messageBody => { | ||
| messageBody should (be("Message 1") or be("Message 3")) | ||
| }) | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be name-value, as that's the usual order? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have changed it to name-value order :)