Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test map messages

  • Loading branch information...
commit ef06433c2174e714866087aa79b73c1db249f952 1 parent f8ddcf1
@jeffbrown jeffbrown authored
View
4 grails-app/controllers/org/grails/rabbitmq/test/MessageController.groovy
@@ -9,6 +9,10 @@ class MessageController {
rabbitSend 'foo', "Message: ${msg}"
+ def messageMap = [msgBody: msg, msgTime: new Date()]
+
+ rabbitSend 'foo', messageMap
+
redirect action: index
}
}
View
7 grails-app/services/org/grails/rabbitmq/test/DemoService.groovy
@@ -6,4 +6,11 @@ class DemoService {
void handleMessage(String textMessage) {
println "Received Message: ${textMessage}"
}
+
+ void handleMessage(Map mapMessage) {
+ println "Received Map Message..."
+ mapMessage?.each { key, val ->
+ println " ${key}: ${val}"
+ }
+ }
}
View
24 test/integration/org/grails/rabbitmq/test/MessageControllerTests.groovy
@@ -8,21 +8,33 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate
class MessageControllerTests extends ControllerUnitTestCase {
void testRabbitSendCallsConvertAndSend() {
- def queueName
- def messageSent
+ def stringMessageQueueName
+ def stringMessage
+
+ def mapMessageQueueName
+ def mapMessage
mockParams.msg = 'Hello World'
def mockTemplate = new MockFor(RabbitTemplate)
mockTemplate.demand.convertAndSend { String queue, String message ->
- queueName = queue
- messageSent = message
+ stringMessageQueueName = queue
+ stringMessage = message
+ }
+ mockTemplate.demand.convertAndSend { String queue, Map message ->
+ mapMessage = message
+ mapMessageQueueName = queue
}
mockTemplate.use {
controller.sendMessage()
}
- assertEquals 'Message: Hello World', messageSent
- assertEquals 'foo', queueName
+ assertEquals 'Message: Hello World', stringMessage
+ assertEquals 'foo', stringMessageQueueName
+
+ assertEquals 'foo', mapMessageQueueName
+ assertEquals 2, mapMessage?.size()
+ assertEquals 'Hello World', mapMessage.msgBody
+ assertTrue mapMessage.msgTime instanceof Date
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.