View Javadoc

1   /*
2    * $Id: CxfOutboundMessageProcessorTestCase.java 19459 2010-09-08 18:30:04Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.MuleException;
16  import org.mule.api.component.simple.EchoService;
17  import org.mule.api.processor.MessageProcessor;
18  import org.mule.module.cxf.builder.SimpleClientMessageProcessorBuilder;
19  import org.mule.tck.AbstractMuleTestCase;
20  
21  public class CxfOutboundMessageProcessorTestCase extends AbstractMuleTestCase
22  {
23      String msg = 
24          "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>" +
25              "<ns1:echo xmlns:ns1=\"http://simple.component.api.mule.org/\">" +
26                  "<ns1:return>hello</ns1:return>" +
27              "</ns1:echo>" +
28          "</soap:Body></soap:Envelope>";
29  
30      boolean gotEvent = false;
31      Object payload;
32      
33      public void testOutbound() throws Exception
34      {
35          CxfConfiguration config = new CxfConfiguration();
36          config.setMuleContext(muleContext);
37          config.initialise();
38          
39          // Build a CXF MessageProcessor
40          SimpleClientMessageProcessorBuilder builder = new SimpleClientMessageProcessorBuilder();
41          builder.setConfiguration(config);
42          builder.setServiceClass(EchoService.class);
43          builder.setOperation("echo");
44          builder.setMuleContext(muleContext);
45          
46          CxfOutboundMessageProcessor processor = builder.build();
47          
48          MessageProcessor messageProcessor = new MessageProcessor()
49          {
50              public MuleEvent process(MuleEvent event) throws MuleException
51              {
52                  payload = event.getMessage().getPayload();
53                  try
54                  {
55                      System.out.println(event.getMessage().getPayloadAsString());
56                  }
57                  catch (Exception e)
58                  {
59                      e.printStackTrace();
60                  }
61                  
62                  event.getMessage().setPayload(msg);
63                  gotEvent = true;
64                  return event;
65              }
66          };
67          processor.setListener(messageProcessor);
68          
69          MuleEvent event = getTestEvent("hello", getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE));
70          MuleEvent response = processor.process(event);
71          
72          Object payload = response.getMessage().getPayload();
73          assertTrue(payload instanceof String);
74          assertEquals("hello", payload);
75          assertTrue(gotEvent);
76      }
77  
78  }