2012-01-19 14:38:44 +00:00
|
|
|
/**
|
2015-03-07 22:58:48 -08:00
|
|
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
2012-01-19 14:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.camel
|
|
|
|
|
|
2015-10-30 14:51:56 +13:00
|
|
|
import java.net.URL
|
|
|
|
|
import javax.activation.DataHandler
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.apache.camel.impl.{ DefaultExchange, DefaultMessage }
|
|
|
|
|
import akka.camel.TestSupport.SharedCamelSystem
|
2013-12-17 14:25:56 +01:00
|
|
|
import org.scalatest.Matchers
|
2013-08-19 12:06:17 +02:00
|
|
|
import org.scalatest.WordSpecLike
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
//TODO merge it with MessageScalaTest
|
2013-12-17 14:25:56 +01:00
|
|
|
class CamelMessageTest extends Matchers with WordSpecLike with SharedCamelSystem {
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2015-10-30 14:51:56 +13:00
|
|
|
"CamelMessage copyContent" must {
|
|
|
|
|
"create a new CamelMessage with additional headers, attachments and new body" in {
|
|
|
|
|
val attachment = new DataHandler(new URL("https://foo.bar"))
|
|
|
|
|
val message = new DefaultMessage
|
|
|
|
|
message.setBody("test")
|
|
|
|
|
message.setHeader("foo", "bar")
|
|
|
|
|
message.addAttachment("foo", attachment)
|
|
|
|
|
message.setExchange(new DefaultExchange(camel.context))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2015-10-30 14:51:56 +13:00
|
|
|
val attachmentToAdd = new DataHandler(new URL("https://another.url"))
|
|
|
|
|
CamelMessage.copyContent(new CamelMessage("body", Map("key" -> "baz"), Map("key" -> attachmentToAdd)), message)
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2015-10-30 14:51:56 +13:00
|
|
|
assert(message.getBody === "body")
|
|
|
|
|
assert(message.getHeader("foo") === "bar")
|
|
|
|
|
assert(message.getHeader("key") === "baz")
|
|
|
|
|
assert(message.getAttachment("key") === attachmentToAdd)
|
|
|
|
|
assert(message.getAttachment("foo") === attachment)
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
}
|