View Javadoc

1   /*
2    * $Id: AjaxNamespaceHandlerTestCase.java 20065 2010-11-03 19:21:08Z dzapata $
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.DynamicPortTestCase;
15  import org.mule.transport.ajax.container.AjaxServletConnector;
16  import org.mule.transport.ajax.embedded.AjaxConnector;
17  
18  import java.net.URL;
19  
20  public class AjaxNamespaceHandlerTestCase extends DynamicPortTestCase
21  {
22      protected String getConfigResources()
23      {
24          return "ajax-namespace-config.xml";
25      }
26  
27      public void testConnector1Properties() throws Exception
28      {
29          AjaxConnector connector =
30                  (AjaxConnector) muleContext.getRegistry().lookupConnector("connector1");
31  
32          assertNotNull(connector);
33  
34          assertTrue(connector.isJsonCommented());
35          assertEquals(1000, connector.getInterval());
36          assertEquals(1, connector.getLogLevel());
37          assertEquals(10000, connector.getMaxInterval());
38          assertEquals(3000, connector.getMultiFrameInterval());
39          assertEquals(4000, connector.getRefsThreshold());
40          assertEquals(50000, connector.getTimeout());
41          assertEquals(new URL("http://0.0.0.0:" + getPorts().get(0) + "/service"), connector.getServerUrl());
42          assertEquals("/foo/bar", connector.getResourceBase());
43      }
44  
45      public void testSecureConnector2Properties() throws Exception
46      {
47          AjaxConnector connector =
48                  (AjaxConnector) muleContext.getRegistry().lookupConnector("connector2");
49  
50          assertNotNull(connector);
51  
52          assertTrue(connector.isJsonCommented());
53          assertEquals(1000, connector.getInterval());
54          assertEquals(1, connector.getLogLevel());
55          assertEquals(10000, connector.getMaxInterval());
56          assertEquals(3000, connector.getMultiFrameInterval());
57          assertEquals(4000, connector.getRefsThreshold());
58          assertEquals(50000, connector.getTimeout());
59          assertEquals(new URL("https://0.0.0.0:" + getPorts().get(1) + "/service"), connector.getServerUrl());
60          assertEquals("/foo/bar", connector.getResourceBase());
61  
62          //The full path gets resolved, we're just checkng that the property got set
63          assertTrue(connector.getKeyStore().endsWith("/serverKeystore"));
64          assertEquals("mulepassword", connector.getKeyPassword());
65          assertEquals("mulepassword", connector.getKeyStorePassword());
66          //The full path gets resolved, we're just checkng that the property got set
67          assertTrue(connector.getClientKeyStore().endsWith("/clientKeystore"));
68          assertEquals("mulepassword", connector.getClientKeyStorePassword());
69          //The full path gets resolved, we're just checkng that the property got set
70          assertTrue(connector.getTrustStore().endsWith("/trustStore"));
71          assertEquals("mulepassword", connector.getTrustStorePassword());
72          assertTrue(connector.isExplicitTrustStoreOnly());
73          assertTrue(connector.isRequireClientAuthentication());
74      }
75  
76      public void testAjaxServletConnector() throws Exception
77      {
78          AjaxServletConnector connector = (AjaxServletConnector) muleContext.getRegistry().lookupConnector("connector3");
79          assertNotNull(connector);
80          //No properties
81      }
82  
83      public void testEmbeddedEndpoint() throws Exception
84      {
85          EndpointBuilder b = muleContext.getRegistry().lookupEndpointBuilder("endpoint1");
86          assertNotNull(b);
87          InboundEndpoint ep = b.buildInboundEndpoint();
88          assertEquals("/request", ep.getEndpointURI().getPath());
89      }
90  
91      public void testServletEndpoint() throws Exception
92      {
93          EndpointBuilder b = muleContext.getRegistry().lookupEndpointBuilder("endpoint2");
94          assertNotNull(b);
95          InboundEndpoint ep = b.buildInboundEndpoint();
96          assertEquals("/response", ep.getEndpointURI().getPath());
97      }
98  
99      @Override
100     protected int getNumPortsToFind()
101     {
102         return 2;
103     }
104 }