View Javadoc

1   /*
2    * $Id: AjaxNamespaceHandlerTestCase.java 23022 2011-09-25 14:49:23Z dfeist $
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  package org.mule.transport.ajax;
11  
12  import org.mule.api.endpoint.EndpointBuilder;
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.tck.junit4.rule.DynamicPort;
16  import org.mule.transport.ajax.container.AjaxServletConnector;
17  import org.mule.transport.ajax.embedded.AjaxConnector;
18  
19  import java.net.URL;
20  
21  import org.junit.Rule;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertNotNull;
26  import static org.junit.Assert.assertTrue;
27  
28  public class AjaxNamespaceHandlerTestCase extends FunctionalTestCase
29  {
30      @Rule
31      public DynamicPort dynamicPort1 = new DynamicPort("port1");
32  
33      @Rule
34      public DynamicPort dynamicPort2 = new DynamicPort("port2");
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "ajax-namespace-config.xml";
40      }
41  
42      @Test
43      public void testConnector1Properties() throws Exception
44      {
45          AjaxConnector connector =
46                  (AjaxConnector) muleContext.getRegistry().lookupConnector("connector1");
47  
48          assertNotNull(connector);
49  
50          assertTrue(connector.isJsonCommented());
51          assertEquals(1000, connector.getInterval());
52          assertEquals(1, connector.getLogLevel());
53          assertEquals(10000, connector.getMaxInterval());
54          assertEquals(3000, connector.getMultiFrameInterval());
55          assertEquals(4000, connector.getRefsThreshold());
56          assertEquals(50000, connector.getTimeout());
57          assertEquals(new URL("http://0.0.0.0:" + dynamicPort1.getNumber() + "/service"), connector.getServerUrl());
58          assertEquals("/foo/bar", connector.getResourceBase());
59          // Test a abstract connector property (MULE-5776)
60          assertTrue(connector.isValidateConnections());
61      }
62  
63      @Test
64      public void testSecureConnector2Properties() throws Exception
65      {
66          AjaxConnector connector =
67                  (AjaxConnector) muleContext.getRegistry().lookupConnector("connector2");
68  
69          assertNotNull(connector);
70  
71          assertTrue(connector.isJsonCommented());
72          assertEquals(1000, connector.getInterval());
73          assertEquals(1, connector.getLogLevel());
74          assertEquals(10000, connector.getMaxInterval());
75          assertEquals(3000, connector.getMultiFrameInterval());
76          assertEquals(4000, connector.getRefsThreshold());
77          assertEquals(50000, connector.getTimeout());
78          assertEquals(new URL("https://0.0.0.0:" + dynamicPort2.getNumber() + "/service"), connector.getServerUrl());
79          assertEquals("/foo/bar", connector.getResourceBase());
80  
81          //The full path gets resolved, we're just checkng that the property got set
82          assertTrue(connector.getKeyStore().endsWith("/serverKeystore"));
83          assertEquals("muleserver", connector.getKeyAlias());
84          assertEquals("mulepassword", connector.getKeyPassword());
85          assertEquals("mulepassword", connector.getKeyStorePassword());
86          //The full path gets resolved, we're just checkng that the property got set
87          assertTrue(connector.getClientKeyStore().endsWith("/clientKeystore"));
88          assertEquals("mulepassword", connector.getClientKeyStorePassword());
89          //The full path gets resolved, we're just checkng that the property got set
90          assertTrue(connector.getTrustStore().endsWith("/trustStore"));
91          assertEquals("mulepassword", connector.getTrustStorePassword());
92          assertTrue(connector.isExplicitTrustStoreOnly());
93          assertTrue(connector.isRequireClientAuthentication());
94      }
95  
96      @Test
97      public void testAjaxServletConnector() throws Exception
98      {
99          AjaxServletConnector connector = (AjaxServletConnector) muleContext.getRegistry().lookupConnector("connector3");
100         assertNotNull(connector);
101         //No properties
102     }
103 
104     @Test
105     public void testEmbeddedEndpoint() throws Exception
106     {
107         EndpointBuilder b = muleContext.getRegistry().lookupEndpointBuilder("endpoint1");
108         assertNotNull(b);
109         InboundEndpoint ep = b.buildInboundEndpoint();
110         assertEquals("/request", ep.getEndpointURI().getPath());
111     }
112 
113     @Test
114     public void testServletEndpoint() throws Exception
115     {
116         EndpointBuilder b = muleContext.getRegistry().lookupEndpointBuilder("endpoint2");
117         assertNotNull(b);
118         InboundEndpoint ep = b.buildInboundEndpoint();
119         assertEquals("/response", ep.getEndpointURI().getPath());
120     }
121 }