1   /*
2    * $Id: JettyEndpointTestCase.java 12297 2008-07-11 17:54:29Z dandiep $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.servlet.jetty;
12  
13  import org.mule.api.endpoint.EndpointURI;
14  import org.mule.endpoint.MuleEndpointURI;
15  import org.mule.tck.AbstractMuleTestCase;
16  
17  public class JettyEndpointTestCase extends AbstractMuleTestCase
18  {
19      public void testHostPortOnlyUrl() throws Exception
20      {
21          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://localhost:8080");
22          endpointUri.initialise();
23          assertEquals("http", endpointUri.getScheme());
24          assertEquals("http://localhost:8080", endpointUri.getAddress());
25          assertNull(endpointUri.getEndpointName());
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      public void testHostPortOnlyUrlAndUserInfo() throws Exception
34      {
35          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://admin:pwd@localhost:8080");
36          endpointUri.initialise();
37          assertEquals("http", endpointUri.getScheme());
38          assertEquals("http://localhost:8080", endpointUri.getAddress());
39          assertNull(endpointUri.getEndpointName());
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      public void testHostPortAndPathUrl() throws Exception
51      {
52          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://localhost:8080/app/path");
53          endpointUri.initialise();
54          assertEquals("http", endpointUri.getScheme());
55          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
56          assertNull(endpointUri.getEndpointName());
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      public void testHostPortAndPathUrlAndUserInfo() throws Exception
66      {
67          EndpointURI endpointUri = new MuleEndpointURI("jetty:http://admin:pwd@localhost:8080/app/path");
68          endpointUri.initialise();
69          assertEquals("http", endpointUri.getScheme());
70          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
71          assertNull(endpointUri.getEndpointName());
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      public void testRestHostPortAndPathUrlAndUserInfo() throws Exception
84      {
85          EndpointURI endpointUri = new MuleEndpointURI("jetty:rest://admin:pwd@localhost:8080/app/path");
86          endpointUri.initialise();
87          assertEquals("rest", endpointUri.getScheme());
88          assertEquals("rest://localhost:8080/app/path", endpointUri.getAddress());
89          assertNull(endpointUri.getEndpointName());
90          assertEquals(8080, endpointUri.getPort());
91          assertEquals("localhost", endpointUri.getHost());
92          assertEquals("rest://localhost:8080/app/path", endpointUri.getAddress());
93          assertEquals(endpointUri.getPath(), "/app/path");
94          assertEquals(0, endpointUri.getParams().size());
95          assertEquals("admin:pwd", endpointUri.getUserInfo());
96          assertEquals("admin", endpointUri.getUser());
97          assertEquals("pwd", endpointUri.getPassword());
98          assertEquals("jetty", endpointUri.getSchemeMetaInfo());
99      }
100 
101 }