View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.transformer.TransformerException;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  import org.mule.transport.NullPayload;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertSame;
20  import static org.mockito.Mockito.mock;
21  import static org.mockito.Mockito.when;
22  
23  public class CxfOutboundMessageProcessorPayloadTestCase extends AbstractMuleContextTestCase
24  {
25      private CxfOutboundMessageProcessor cxfMP;
26      private CxfConfiguration configuration;
27  
28      @Override
29      protected void doSetUp() throws Exception
30      {
31          super.doSetUp();
32  
33          configuration = new CxfConfiguration();
34          configuration.setMuleContext(muleContext);
35          configuration.initialise();
36          cxfMP = new CxfOutboundMessageProcessor(null);
37      }
38  
39      @Test
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      @Test
52      public void testGetArgs_withArrayAsPayload() throws Exception
53      {
54          Object[] payload = new Object[4];
55  
56          Object[] args = callGetArgsWithPayload(payload);
57  
58          assertSame(payload, args);
59      }
60  
61      @Test
62      public void testGetArgs_withNullPayloadAsPayload() throws Exception
63      {
64          Object payload = NullPayload.getInstance();
65  
66          Object[] args = callGetArgsWithPayload(payload);
67  
68          assertNotNull(args);
69          assertEquals(1, args.length);
70          assertSame(payload, args[0]);
71      }
72  
73      private Object[] callGetArgsWithPayload(Object payload) throws TransformerException
74      {
75          MuleEvent muleEvent = mock(MuleEvent.class);
76          MuleMessage muleMessage = mock(MuleMessage.class);
77          
78          when(muleEvent.getMessage()).thenReturn(muleMessage);
79          when(muleEvent.getMessage().getPayload()).thenReturn(payload);
80          when(muleMessage.getPayload()).thenReturn(payload);
81  
82          Object[] args = cxfMP.getArgs(muleEvent);
83          return args;
84      }
85  
86  }
87