View Javadoc

1   /*
2    * $Id: CxfOutboundMessageProcessorPayloadTestCase.java 20320 2010-11-24 15:03:31Z dfeist $
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 static org.mockito.Mockito.mock;
14  import static org.mockito.Mockito.when;
15  
16  import org.mule.api.MuleEvent;
17  import org.mule.api.MuleMessage;
18  import org.mule.api.transformer.TransformerException;
19  import org.mule.module.cxf.CxfConfiguration;
20  import org.mule.module.cxf.CxfOutboundMessageProcessor;
21  import org.mule.tck.AbstractMuleTestCase;
22  import org.mule.transport.NullPayload;
23  
24  public class CxfOutboundMessageProcessorPayloadTestCase extends AbstractMuleTestCase
25  {
26      private CxfOutboundMessageProcessor cxfMP;
27      private CxfConfiguration configuration;
28  
29      @Override
30      protected void doSetUp() throws Exception
31      {
32          super.doSetUp();
33  
34          configuration = new CxfConfiguration();
35          configuration.setMuleContext(muleContext);
36          configuration.initialise();
37          cxfMP = new CxfOutboundMessageProcessor(null);
38      }
39  
40      public void testGetArgs_withObjectAsPayload() throws Exception
41      {
42          Object payload = new Object();
43  
44          Object[] args = callGetArgsWithPayload(payload);
45  
46          assertNotNull(args);
47          assertEquals(1, args.length);
48          assertSame(payload, args[0]);
49      }
50  
51      public void testGetArgs_withArrayAsPayload() throws Exception
52      {
53          Object[] payload = new Object[4];
54  
55          Object[] args = callGetArgsWithPayload(payload);
56  
57          assertSame(payload, args);
58      }
59  
60      public void testGetArgs_withNullPayloadAsPayload() throws Exception
61      {
62          Object payload = NullPayload.getInstance();
63  
64          Object[] args = callGetArgsWithPayload(payload);
65  
66          assertNotNull(args);
67          assertEquals(1, args.length);
68          assertSame(payload, args[0]);
69      }
70  
71      private Object[] callGetArgsWithPayload(Object payload) throws TransformerException
72      {
73          MuleEvent muleEvent = mock(MuleEvent.class);
74          MuleMessage muleMessage = mock(MuleMessage.class);
75          
76          when(muleEvent.getMessage()).thenReturn(muleMessage);
77          when(muleEvent.getMessage().getPayload()).thenReturn(payload);
78          when(muleMessage.getPayload()).thenReturn(payload);
79  
80          Object[] args = cxfMP.getArgs(muleEvent);
81          return args;
82      }
83  
84  }
85