Package com.consol.citrus.message

Examples of com.consol.citrus.message.Message


                "</TestMessage>");
    }

    @Test
    public void testTranslateFromMappingFile() throws Exception {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage><Text name=\"\">Hello World!</Text><OtherText>No changes</OtherText></TestMessage>");

        context.setVariable("newText", "Hello!");

        NodeMappingDataDictionary dictionary = new NodeMappingDataDictionary();
        dictionary.setMappingFile(new ClassPathResource("mapping.properties", DataDictionary.class));
        dictionary.afterPropertiesSet();

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage>" + System.getProperty("line.separator") +
                "   <Text name=\"newName\">Hello!</Text>" + System.getProperty("line.separator") +
                "   <OtherText>No changes</OtherText>" + System.getProperty("line.separator") +
                "</TestMessage>");
    }
View Full Code Here


                "</TestMessage>");
    }

    @Test
    public void testTranslateWithNestedAndEmptyElements() {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage><Text><value></value></Text><OtherText></OtherText></TestMessage>");

        Map<String, String> mappings = new HashMap<String, String>();
        mappings.put("TestMessage.Text.value", "Hello!");

        NodeMappingDataDictionary dictionary = new NodeMappingDataDictionary();
        dictionary.setMappings(mappings);

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage>" + System.getProperty("line.separator") +
                "   <Text>" + System.getProperty("line.separator") +
                "      <value>Hello!</value>" + System.getProperty("line.separator") +
                "   </Text>" + System.getProperty("line.separator") +
                "   <OtherText/>" + System.getProperty("line.separator") +
                "</TestMessage>");
View Full Code Here

    @Override
    protected Message handleMessageInternal(Message request) {
        log.info("Forwarding request to jms destination ...");

        TestContext context = getTestContext();
        Message replyMessage = null;
        try {
            producer.send(request, context);
            if (endpointConfiguration.getCorrelator() != null) {
                replyMessage = producer.receive(endpointConfiguration.getCorrelator().getCorrelationKey(request), context, endpointConfiguration.getTimeout());
            } else {
View Full Code Here

*/
public class XpathMappingDataDictionaryTest extends AbstractTestNGUnitTest {

    @Test
    public void testTranslate() throws Exception {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage><Text>Hello World!</Text><OtherText name=\"foo\">No changes</OtherText></TestMessage>");

        Map<String, String> mappings = new HashMap<String, String>();
        mappings.put("//TestMessage/Text", "Hello!");
        mappings.put("//@name", "bar");

        XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
        dictionary.setMappings(mappings);

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage>" + System.getProperty("line.separator") +
                "   <Text>Hello!</Text>" + System.getProperty("line.separator") +
                "   <OtherText name=\"bar\">No changes</OtherText>" + System.getProperty("line.separator") +
                "</TestMessage>");
    }
View Full Code Here

                "</TestMessage>");
    }

    @Test
    public void testTranslateWithNamespaceLookup() throws Exception {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http://www.foo.bar\"><ns1:Text>Hello World!</ns1:Text><ns1:OtherText name=\"foo\">No changes</ns1:OtherText></ns1:TestMessage>");

        Map<String, String> mappings = new HashMap<String, String>();
        mappings.put("//ns1:TestMessage/ns1:Text", "Hello!");
        mappings.put("//@name", "bar");

        XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
        dictionary.setMappings(mappings);

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http://www.foo.bar\">" + System.getProperty("line.separator") +
                "   <ns1:Text>Hello!</ns1:Text>" + System.getProperty("line.separator") +
                "   <ns1:OtherText name=\"bar\">No changes</ns1:OtherText>" + System.getProperty("line.separator") +
                "</ns1:TestMessage>");
    }
View Full Code Here

                "</ns1:TestMessage>");
    }

    @Test
    public void testTranslateWithNamespaceBuilder() throws Exception {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http://www.foo.bar\"><ns1:Text>Hello World!</ns1:Text><ns1:OtherText name=\"foo\">No changes</ns1:OtherText></ns1:TestMessage>");

        Map<String, String> mappings = new HashMap<String, String>();
        mappings.put("//foo:TestMessage/foo:Text", "Hello!");
        mappings.put("//@name", "bar");

        XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
        dictionary.setMappings(mappings);

        NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder();
        Map<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("foo", "http://www.foo.bar");
        namespaceContextBuilder.setNamespaceMappings(namespaces);
        dictionary.setNamespaceContextBuilder(namespaceContextBuilder);

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http://www.foo.bar\">" + System.getProperty("line.separator") +
                "   <ns1:Text>Hello!</ns1:Text>" + System.getProperty("line.separator") +
                "   <ns1:OtherText name=\"bar\">No changes</ns1:OtherText>" + System.getProperty("line.separator") +
                "</ns1:TestMessage>");
    }
View Full Code Here

                "</ns1:TestMessage>");
    }

    @Test
    public void testTranslateWithVariables() throws Exception {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage><Text>Hello World!</Text><OtherText name=\"foo\">No changes</OtherText></TestMessage>");

        Map<String, String> mappings = new HashMap<String, String>();
        mappings.put("//TestMessage/Text", "${hello}");
        mappings.put("//@name", "bar");

        context.setVariable("hello", "Hello!");

        XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
        dictionary.setMappings(mappings);

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage>" + System.getProperty("line.separator") +
                "   <Text>Hello!</Text>" + System.getProperty("line.separator") +
                "   <OtherText name=\"bar\">No changes</OtherText>" + System.getProperty("line.separator") +
                "</TestMessage>");
    }
View Full Code Here

                "</TestMessage>");
    }

    @Test
    public void testTranslateFromMappingFile() throws Exception {
        Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage><Text>Hello World!</Text><OtherText name=\"foo\">No changes</OtherText></TestMessage>");

        XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
        dictionary.setMappingFile(new ClassPathResource("xpathmapping.properties", DataDictionary.class));
        dictionary.afterPropertiesSet();

        Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
        Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestMessage>" + System.getProperty("line.separator") +
                "   <Text>Hello!</Text>" + System.getProperty("line.separator") +
                "   <OtherText name=\"bar\">GoodBye!</OtherText>" + System.getProperty("line.separator") +
                "</TestMessage>");
    }
View Full Code Here

            if (jmsReplyMessage == null) {
                throw new ActionTimeoutException("Reply timed out after " +
                        endpointConfiguration.getTimeout() + "ms. Did not receive reply message on reply destination");
            }

            Message responseMessage = endpointConfiguration.getMessageConverter().convertInbound(jmsReplyMessage, endpointConfiguration);

            log.info("Received reply message on destination: '{}'", replyToDestination);

            onInboundMessage(responseMessage, context);
View Full Code Here

    }

    @Override
    public Message receive(String selector, TestContext context, long timeout) {
        long timeLeft = timeout;
        Message message = findReplyMessage(selector);

        while (message == null && timeLeft > 0) {
            timeLeft -= endpointConfiguration.getPollingInterval();

            if (RETRY_LOG.isDebugEnabled()) {
View Full Code Here

TOP

Related Classes of com.consol.citrus.message.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.