View Javadoc

1   /*
2    * $Id: CxfOutboundMessageProcessorTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
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.junit4.AbstractMuleContextTestCase;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  
26  public class CxfOutboundMessageProcessorTestCase extends AbstractMuleContextTestCase
27  {
28      String msg = 
29          "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>" +
30              "<ns1:echo xmlns:ns1=\"http://simple.component.api.mule.org/\">" +
31                  "<ns1:return>hello</ns1:return>" +
32              "</ns1:echo>" +
33          "</soap:Body></soap:Envelope>";
34  
35      boolean gotEvent = false;
36      Object payload;
37      
38      @Test
39      public void testOutbound() throws Exception
40      {
41          CxfConfiguration config = new CxfConfiguration();
42          config.setMuleContext(muleContext);
43          config.initialise();
44          
45          // Build a CXF MessageProcessor
46          SimpleClientMessageProcessorBuilder builder = new SimpleClientMessageProcessorBuilder();
47          builder.setConfiguration(config);
48          builder.setServiceClass(EchoService.class);
49          builder.setOperation("echo");
50          builder.setMuleContext(muleContext);
51          
52          CxfOutboundMessageProcessor processor = builder.build();
53          
54          MessageProcessor messageProcessor = new MessageProcessor()
55          {
56              public MuleEvent process(MuleEvent event) throws MuleException
57              {
58                  payload = event.getMessage().getPayload();
59                  try
60                  {
61                      System.out.println(event.getMessage().getPayloadAsString());
62                  }
63                  catch (Exception e)
64                  {
65                      e.printStackTrace();
66                  }
67                  
68                  event.getMessage().setPayload(msg);
69                  gotEvent = true;
70                  return event;
71              }
72          };
73          processor.setListener(messageProcessor);
74          
75          MuleEvent event = getTestEvent("hello", getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE));
76          MuleEvent response = processor.process(event);
77          
78          Object payload = response.getMessage().getPayload();
79          assertTrue(payload instanceof String);
80          assertEquals("hello", payload);
81          assertTrue(gotEvent);
82      }
83  
84  }