1   /*
2    * $Id: HttpEndpointTestCase.java 12100 2008-06-19 08:58:48Z rossmason $
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.http;
12  
13  import org.mule.api.endpoint.EndpointURI;
14  import org.mule.endpoint.MuleEndpointURI;
15  import org.mule.tck.AbstractMuleTestCase;
16  
17  public class HttpEndpointTestCase extends AbstractMuleTestCase
18  {
19      public void testHostPortOnlyUrl() throws Exception
20      {
21          EndpointURI endpointUri = new MuleEndpointURI("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.getAddress());
29          assertEquals(0, endpointUri.getParams().size());
30      }
31  
32      public void testHostPortOnlyUrlAndUserInfo() throws Exception
33      {
34          EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080");
35          endpointUri.initialise();
36          assertEquals("http", endpointUri.getScheme());
37          assertEquals("http://localhost:8080", endpointUri.getAddress());
38          assertNull(endpointUri.getEndpointName());
39          assertEquals(8080, endpointUri.getPort());
40          assertEquals("localhost", endpointUri.getHost());
41          assertEquals("http://localhost:8080", endpointUri.getAddress());
42          assertEquals(0, endpointUri.getParams().size());
43          assertEquals("admin:pwd", endpointUri.getUserInfo());
44          assertEquals("admin", endpointUri.getUser());
45          assertEquals("pwd", endpointUri.getPassword());
46      }
47  
48      public void testHostPortAndPathUrl() throws Exception
49      {
50          EndpointURI endpointUri = new MuleEndpointURI("http://localhost:8080/app/path");
51          endpointUri.initialise();
52          assertEquals("http", endpointUri.getScheme());
53          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
54          assertNull(endpointUri.getEndpointName());
55          assertEquals(8080, endpointUri.getPort());
56          assertEquals("localhost", endpointUri.getHost());
57          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
58          assertEquals(endpointUri.getPath(), "/app/path");
59          assertEquals(0, endpointUri.getParams().size());
60      }
61  
62      public void testHostPortAndPathUrlAndUserInfo() throws Exception
63      {
64          EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080/app/path");
65          endpointUri.initialise();
66          assertEquals("http", endpointUri.getScheme());
67          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
68          assertNull(endpointUri.getEndpointName());
69          assertEquals(8080, endpointUri.getPort());
70          assertEquals("localhost", endpointUri.getHost());
71          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
72          assertEquals(endpointUri.getPath(), "/app/path");
73          assertEquals(0, endpointUri.getParams().size());
74          assertEquals("admin:pwd", endpointUri.getUserInfo());
75          assertEquals("admin", endpointUri.getUser());
76          assertEquals("pwd", endpointUri.getPassword());
77      }
78  
79      public void testHostPortAndPathUrlUserInfoAndQuery() throws Exception
80      {
81          EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080/app/path?${foo}");
82          endpointUri.initialise();
83          assertEquals("http", endpointUri.getScheme());
84          assertEquals("http://localhost:8080/app/path?$[foo]", endpointUri.getAddress());
85          assertNull(endpointUri.getEndpointName());
86          assertEquals(8080, endpointUri.getPort());
87          assertEquals("localhost", endpointUri.getHost());
88          assertEquals(endpointUri.getPath(), "/app/path");
89          assertEquals(endpointUri.getQuery(), "$[foo]");
90          assertEquals(1, endpointUri.getParams().size());
91          assertEquals("admin:pwd", endpointUri.getUserInfo());
92          assertEquals("admin", endpointUri.getUser());
93          assertEquals("pwd", endpointUri.getPassword());
94      }
95  }