View Javadoc

1   /*
2    * $Id: EndpointRetrievalMule2021TestCase.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.transport.soap.axis.issues;
12  
13  import static org.junit.Assert.assertFalse;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  import static org.junit.Assert.assertTrue;
17  
18  import org.mule.api.MuleException;
19  import org.mule.api.endpoint.EndpointBuilder;
20  import org.mule.api.endpoint.ImmutableEndpoint;
21  import org.mule.api.transport.Connector;
22  import org.mule.tck.AbstractServiceAndFlowTestCase;
23  import org.mule.tck.junit4.rule.DynamicPort;
24  import org.mule.transport.soap.axis.AxisConnector;
25  
26  import java.util.Arrays;
27  import java.util.Collection;
28  
29  import org.junit.Rule;
30  import org.junit.Test;
31  import org.junit.runners.Parameterized.Parameters;
32  
33  public class EndpointRetrievalMule2021TestCase extends AbstractServiceAndFlowTestCase
34  {
35  
36      public EndpointRetrievalMule2021TestCase(ConfigVariant variant, String configResources)
37      {
38          super(variant, configResources); 
39      }
40  
41      @Rule
42      public DynamicPort dynamicPort = new DynamicPort("port1");
43  
44      @Parameters
45      public static Collection<Object[]> parameters()
46      {
47          return Arrays.asList(new Object[][]{
48              {ConfigVariant.SERVICE, "endpoint-retrieval-mule-2021-test-service.xml"},
49              {ConfigVariant.FLOW, "endpoint-retrieval-mule-2021-test-flow.xml"}
50          });
51      }      
52      
53      @Test
54      public void testLookupEndpoint() throws MuleException
55      {
56          Object endpoint1 = muleContext.getRegistry().lookupObject("Endpoint");
57          // This returns the builder rather than the endpoint
58          assertTrue(endpoint1 instanceof EndpointBuilder);
59          assertFalse(endpoint1 instanceof ImmutableEndpoint);
60  
61          EndpointBuilder endpointBuiler = muleContext.getRegistry().lookupEndpointBuilder("Endpoint");
62          // There should however be an endpoint builder with this id/name
63          assertNotNull(endpointBuiler);
64  
65          ImmutableEndpoint endpoint2 = (ImmutableEndpoint) muleContext.getRegistry().lookupObject(
66              "axis:http://localhost:" + dynamicPort.getNumber() + "/mule/Service?method=toString");
67          // Null expected because lookupEndpoint does not create endpoints from uri's.
68          assertNull(endpoint2);
69      }
70  
71      @Test
72      public void testGetOutboundEndpoint() throws MuleException
73      {
74          ImmutableEndpoint endpoint1 = muleContext.getEndpointFactory().getOutboundEndpoint(
75              "Endpoint");
76          assertEndpointOk(endpoint1);
77          ImmutableEndpoint endpoint2 = muleContext.getEndpointFactory().getOutboundEndpoint(
78              "axis:http://localhost:" + dynamicPort.getNumber() + "/mule/Service?method=toString");
79          assertEndpointOk(endpoint2);
80      }
81  
82      @Test
83      public void testGetInboundEndpoint() throws MuleException
84      {
85          ImmutableEndpoint endpoint1 = muleContext.getEndpointFactory().getInboundEndpoint(
86              "Endpoint");
87          assertEndpointOk(endpoint1);
88          ImmutableEndpoint endpoint2 = muleContext.getEndpointFactory().getInboundEndpoint(
89              "axis:http://localhost:" + dynamicPort.getNumber() + "/mule/Service?method=toString");
90          assertEndpointOk(endpoint2);
91      }
92  
93      @Test
94      public void testGetResponseEndpoint() throws MuleException
95      {
96          ImmutableEndpoint endpoint1 = muleContext.getEndpointFactory().getInboundEndpoint(
97              "Endpoint");
98          assertEndpointOk(endpoint1);
99          ImmutableEndpoint endpoint2 = muleContext.getEndpointFactory().getInboundEndpoint(
100             "axis:http://localhost:" + dynamicPort.getNumber() + "/mule/Service?method=toString");
101         assertEndpointOk(endpoint2);
102     }
103 
104     private void assertEndpointOk(ImmutableEndpoint endpoint)
105     {
106         assertNotNull("Endpoint is null", endpoint);
107         Connector connector = endpoint.getConnector();
108         assertTrue("Connector not AXIS", connector instanceof AxisConnector);
109     }
110 
111 }