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