View Javadoc

1   /*
2    * $Id: EndpointBindsToCorrectWdslPortTestCase.java 22491 2011-07-21 10:04:30Z claude.mamo $
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.functional;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.api.processor.MessageProcessor;
17  import org.mule.api.service.Service;
18  import org.mule.construct.Flow;
19  import org.mule.endpoint.DefaultInboundEndpoint;
20  import org.mule.module.cxf.CxfInboundMessageProcessor;
21  import org.mule.module.cxf.config.FlowConfiguringMessageProcessor;
22  import org.mule.service.ServiceCompositeMessageSource;
23  import org.mule.tck.AbstractServiceAndFlowTestCase;
24  import org.mule.tck.junit4.rule.DynamicPort;
25  
26  import java.util.Arrays;
27  import java.util.Collection;
28  import java.util.List;
29  
30  import org.apache.cxf.endpoint.Server;
31  import org.apache.cxf.service.model.EndpointInfo;
32  import org.junit.Rule;
33  import org.junit.Test;
34  import org.junit.runners.Parameterized.Parameters;
35  
36  public class EndpointBindsToCorrectWdslPortTestCase extends AbstractServiceAndFlowTestCase
37  {
38  
39      @Rule
40      public DynamicPort dynamicPort = new DynamicPort("port1");
41  
42      public EndpointBindsToCorrectWdslPortTestCase(ConfigVariant variant, String configResources)
43      {
44          super(variant, configResources);
45      }
46  
47      @Parameters
48      public static Collection<Object[]> parameters()
49      {
50          return Arrays.asList(new Object[][]{
51              {ConfigVariant.SERVICE, "org/mule/module/cxf/functional/endpoint-binds-to-correct-wdsl-port-service.xml"},
52              {ConfigVariant.FLOW, "org/mule/module/cxf/functional/endpoint-binds-to-correct-wdsl-port-flow.xml"}
53          });
54      }      
55  
56      @Test
57      public void testThatTheCorrectSoapPortIsChosen() throws Exception
58      {
59          DefaultInboundEndpoint inboundEndpoint;
60          
61          if (variant.equals(ConfigVariant.FLOW))
62          {
63              final Flow flow = muleContext.getRegistry().lookupObject("CXFProxyService");
64              inboundEndpoint = (DefaultInboundEndpoint) flow.getMessageSource();                        
65          }
66          else
67          {
68              final Service service = muleContext.getRegistry().lookupService("CXFProxyService");
69              ServiceCompositeMessageSource messageSource = (ServiceCompositeMessageSource) service.getMessageSource();
70  
71              List<InboundEndpoint> endpoints = messageSource.getEndpoints();
72              inboundEndpoint = (DefaultInboundEndpoint) endpoints.get(0);            
73          }               
74          
75          List<MessageProcessor> processors = inboundEndpoint.getMessageProcessors();
76          FlowConfiguringMessageProcessor wrapper = (FlowConfiguringMessageProcessor) processors.get(0);
77          CxfInboundMessageProcessor cxfProcessor = (CxfInboundMessageProcessor) wrapper.getWrappedMessageProcessor();
78          Server server = cxfProcessor.getServer();
79          EndpointInfo endpointInfo = server.getEndpoint().getEndpointInfo();
80  
81          assertEquals(
82              "The local part of the endpoing name must be the one supplied as the endpointName parameter on the cxf:inbound-endpoint",
83              "ListsSoap", endpointInfo.getName().getLocalPart());
84      }
85  
86  }