Permalink
Browse files

Fixing Test API when creating Camel Test massages

  • Loading branch information...
atooni committed Oct 1, 2018
1 parent a84dcfd commit 8c6d42cc4593a51860c33a984f5872c4832db3bc
@@ -1,6 +1,7 @@
package blended.testsupport;
import blended.util.FileHelper;
import org.apache.camel.CamelContext;
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultMessage;
import org.slf4j.Logger;
@@ -19,11 +20,14 @@
public class XMLMessageFactory implements MessageFactory {
private final String resourceName;
private final CamelContext camelContext;
private final static Logger LOGGER = LoggerFactory.getLogger(XMLMessageFactory.class);
private final static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
public XMLMessageFactory(String fileName) {
public XMLMessageFactory(CamelContext context, String fileName) {
this.camelContext = context;
this.resourceName = fileName;
}
@@ -39,7 +43,7 @@ public Message createBinaryMessage() throws Exception {
private Message createMessage(final boolean binary) throws Exception {
final Message result = new DefaultMessage();
final Message result = new DefaultMessage(camelContext);
LOGGER.debug("Creating message from file [{}]", resourceName);
Document doc = readMessageFile();
@@ -104,8 +104,8 @@ trait CamelTestSupport {
private[CamelTestSupport] def createMessageFromXML(message: String, binary: Boolean)(implicit context: CamelContext) : Option[CamelMessage] = {
try {
binary match {
case true => Some(camelMessage(new XMLMessageFactory(message).createBinaryMessage()))
case false => Some(camelMessage(new XMLMessageFactory(message).createTextMessage()))
case true => Some(camelMessage(new XMLMessageFactory(context, message).createBinaryMessage()))
case false => Some(camelMessage(new XMLMessageFactory(context, message).createTextMessage()))
}
} catch {
case e: Exception => None
@@ -1,6 +1,8 @@
package blended.testsupport;
import org.apache.camel.CamelContext;
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.Assert;
import org.junit.Test;
@@ -11,7 +13,9 @@
@Test
public void createMessageTest() throws Exception{
Message msg = new XMLMessageFactory(FILE).createTextMessage();
CamelContext ctxt = new DefaultCamelContext();
Message msg = new XMLMessageFactory(ctxt, FILE).createTextMessage();
Assert.assertNotNull(msg);
Assert.assertTrue(msg.getHeaders().size() > 0);
@@ -10,6 +10,8 @@ object BlendedTestsupport extends ProjectFactory {
Dependencies.akkaActor,
Dependencies.akkaTestkit,
Dependencies.akkaCamel,
Dependencies.camelCore,
Dependencies.camelJms,
Dependencies.scalatest,
Dependencies.junit
)

0 comments on commit 8c6d42c

Please sign in to comment.