View Javadoc

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