View Javadoc

1   /*
2    * $Id: AxisNamespaceHandlerTestCase.java 22431 2011-07-18 07:40:35Z 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.transport.soap.axis;
12  
13  import org.mule.api.endpoint.ImmutableEndpoint;
14  import org.mule.module.cxf.SoapConstants;
15  import org.mule.tck.junit4.FunctionalTestCase;
16  import org.mule.transport.soap.axis.mock.MockAxisServer;
17  import org.mule.transport.soap.axis.mock.MockProvider;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.axis.constants.Style;
23  import org.apache.axis.constants.Use;
24  import org.junit.Test;
25  
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.assertFalse;
28  import static org.junit.Assert.assertNotNull;
29  import static org.junit.Assert.assertTrue;
30  
31  public class AxisNamespaceHandlerTestCase extends FunctionalTestCase
32  {
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "axis-namespace-config.xml";
38      }
39  
40      @Test
41      public void testConfig()
42      {
43          AxisConnector connector =
44              (AxisConnector)muleContext.getRegistry().lookupConnector("axisConnector");
45          
46          assertNotNull(connector);
47          assertEquals("test-axis-config.wsdd", connector.getServerConfig());
48          assertEquals("test-axis-config.wsdd", connector.getClientConfig());
49          assertFalse(connector.isTreatMapAsNamedParams());
50          assertFalse(connector.isDoAutoTypes());
51          assertEquals(2, connector.getBeanTypes().size());
52          assertTrue(connector.getBeanTypes().contains("org.mule.tck.testmodels.fruit.Apple"));
53          assertTrue(connector.getBeanTypes().contains("org.mule.tck.testmodels.fruit.Banana"));
54          assertEquals(1, connector.getSupportedSchemes().size());
55          assertEquals("http", connector.getSupportedSchemes().get(0));
56      }
57  
58      @Test
59      public void testInjectedObjects()
60      {
61          AxisConnector connector =
62              (AxisConnector)muleContext.getRegistry().lookupConnector("axisConnector2");
63  
64          assertNotNull(connector);
65          assertEquals(MockAxisServer.class, connector.getAxis().getClass());
66          assertEquals(MockProvider.class, connector.getClientProvider().getClass());
67      }
68  
69      @Test
70      public void testEndpointProperties() throws Exception
71      {
72          ImmutableEndpoint endpoint =
73                  muleContext.getRegistry().lookupEndpointBuilder("endpoint").buildOutboundEndpoint();
74          Map props = endpoint.getProperties();
75          assertEquals("#[methodNamespace]#[method]", assertKey(props, SoapConstants.SOAP_ACTION_PROPERTY, String.class));
76          assertEquals("direct", assertKey(props, SoapConstants.SOAP_ACTION_PROPERTY_CAPS, String.class));
77          assertEquals("clientConfig", assertKey(props, "clientConfig", String.class));
78          assertEquals(Use.ENCODED_STR, assertKey(props, AxisConnector.USE, String.class));
79          assertEquals(Style.DOCUMENT_STR, assertKey(props, AxisConnector.STYLE, String.class));
80          assertEquals("value1", assertKey(props, "key1", String.class));
81          assertEquals("value2", assertKey(props, "key2", String.class));
82          Map options = (Map) assertKey(props, AxisMessageReceiver.AXIS_OPTIONS, Map.class);
83          assertEquals(10, options.size());
84          assertEquals("value1", assertKey(options, "key1", String.class));
85          assertEquals("value2", assertKey(options, "key2", String.class));
86          assertEquals("Application", assertKey(options, "scope", String.class));
87          assertEquals("echo,getdate", assertKey(options, "allowedMethods", String.class));
88          assertEquals("wsdlPortType", assertKey(options, "wsdlPortType", String.class));
89          assertEquals("wsdlServiceElement", assertKey(options, "wsdlServiceElement", String.class));
90          assertEquals("wsdlTargetNamespace", assertKey(options, "wsdlTargetNamespace", String.class));
91          assertEquals("wsdlInputSchema", assertKey(options, "wsdlInputSchema", String.class));
92          assertEquals("wsdlSoapActionMode", assertKey(options, "wsdlSoapActionMode", String.class));
93          assertEquals("extraClasses", assertKey(options, "extraClasses", String.class));
94          Map methods = (Map) assertKey(props, AxisConnector.SOAP_METHODS, Map.class);
95          List method1 = (List) assertKey(methods, "method1", List.class);
96          assertEquals(3, method1.size());
97          assertEquals("symbol;string;IN", method1.get(0));
98          assertEquals("GetQuoteResult;string;OUT", method1.get(1));
99          assertEquals("return;string", method1.get(2));
100         List method2 = (List) assertKey(methods, "method2", List.class);
101         assertEquals(2, method2.size());
102         assertEquals("param;string;IN", method2.get(0));
103         assertEquals("addedFromSpring;string;in", method2.get(1));
104         List interfaces = (List) assertKey(props, SoapConstants.SERVICE_INTERFACES, List.class);
105         assertEquals(2, interfaces.size());
106         assertEquals("class1", interfaces.get(0));
107         assertEquals("class2", interfaces.get(1));
108     }
109 
110     protected Object assertKey(Map props, String name, Class clazz)
111     {
112         assertNotNull(props);
113         assertTrue(name + " not in properties", props.containsKey(name));
114         Object value = props.get(name);
115         assertNotNull(name + " value null", value);
116         assertTrue(value.getClass() + " not subclass of " + clazz, clazz.isAssignableFrom(value.getClass()));
117         return value;
118     }
119 
120 }
121 
122