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.servlet.jetty;
8   
9   import org.mule.api.endpoint.EndpointURI;
10  import org.mule.endpoint.MuleEndpointURI;
11  import org.mule.tck.junit4.AbstractMuleContextTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  
17  public class JettyEndpointTestCase extends AbstractMuleContextTestCase
18  {
19      @Test
20      public void testHostPortOnlyUrl() throws Exception
21      {
22          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://localhost:8080", muleContext);
23          endpointUri.initialise();
24          assertEquals("http", endpointUri.getScheme());
25          assertEquals("http://localhost:8080", endpointUri.getAddress());
26          assertEquals(8080, endpointUri.getPort());
27          assertEquals("localhost", endpointUri.getHost());
28          assertEquals("http://localhost:8080", endpointUri.toString());
29          assertEquals(0, endpointUri.getParams().size());
30          assertEquals("jetty", endpointUri.getSchemeMetaInfo());
31      }
32  
33      @Test
34      public void testHostPortOnlyUrlAndUserInfo() throws Exception
35      {
36          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://admin:pwd@localhost:8080", muleContext);
37          endpointUri.initialise();
38          assertEquals("http", endpointUri.getScheme());
39          assertEquals("http://localhost:8080", endpointUri.getAddress());
40          assertEquals(8080, endpointUri.getPort());
41          assertEquals("localhost", endpointUri.getHost());
42          assertEquals("http://localhost:8080", endpointUri.getAddress());
43          assertEquals(0, endpointUri.getParams().size());
44          assertEquals("admin:pwd", endpointUri.getUserInfo());
45          assertEquals("admin", endpointUri.getUser());
46          assertEquals("pwd", endpointUri.getPassword());
47          assertEquals("jetty", endpointUri.getSchemeMetaInfo());
48      }
49  
50      @Test
51      public void testHostPortAndPathUrl() throws Exception
52      {
53          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://localhost:8080/app/path", muleContext);
54          endpointUri.initialise();
55          assertEquals("http", endpointUri.getScheme());
56          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
57          assertEquals(8080, endpointUri.getPort());
58          assertEquals("localhost", endpointUri.getHost());
59          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
60          assertEquals(endpointUri.getPath(), "/app/path");
61          assertEquals(0, endpointUri.getParams().size());
62          assertEquals("jetty", endpointUri.getSchemeMetaInfo());
63      }
64  
65      @Test
66      public void testHostPortAndPathUrlAndUserInfo() throws Exception
67      {
68          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://admin:pwd@localhost:8080/app/path", muleContext);
69          endpointUri.initialise();
70          assertEquals("http", endpointUri.getScheme());
71          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
72          assertEquals(8080, endpointUri.getPort());
73          assertEquals("localhost", endpointUri.getHost());
74          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
75          assertEquals(endpointUri.getPath(), "/app/path");
76          assertEquals(0, endpointUri.getParams().size());
77          assertEquals("admin:pwd", endpointUri.getUserInfo());
78          assertEquals("admin", endpointUri.getUser());
79          assertEquals("pwd", endpointUri.getPassword());
80          assertEquals("jetty", endpointUri.getSchemeMetaInfo());
81      }
82  
83  }