View Javadoc

1   /*
2    * $Id: HttpEndpointTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
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  
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.junit4.AbstractMuleContextTestCase;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNull;
21  
22  public class HttpEndpointTestCase extends AbstractMuleContextTestCase
23  {
24  
25      @Test
26      public void testHostPortOnlyUrl() throws Exception
27      {
28          EndpointURI endpointUri = new MuleEndpointURI("http://localhost:8080", muleContext);
29          endpointUri.initialise();
30          assertEquals("http", endpointUri.getScheme());
31          assertEquals("http://localhost:8080", endpointUri.getAddress());
32          assertNull(endpointUri.getEndpointName());
33          assertEquals(8080, endpointUri.getPort());
34          assertEquals("localhost", endpointUri.getHost());
35          assertEquals("http://localhost:8080", endpointUri.getAddress());
36          assertEquals(0, endpointUri.getParams().size());
37      }
38  
39      @Test
40      public void testHostPortOnlyUrlAndUserInfo() throws Exception
41      {
42          EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080", muleContext);
43          endpointUri.initialise();
44          assertEquals("http", endpointUri.getScheme());
45          assertEquals("http://localhost:8080", endpointUri.getAddress());
46          assertNull(endpointUri.getEndpointName());
47          assertEquals(8080, endpointUri.getPort());
48          assertEquals("localhost", endpointUri.getHost());
49          assertEquals("http://localhost:8080", endpointUri.getAddress());
50          assertEquals(0, endpointUri.getParams().size());
51          assertEquals("admin:pwd", endpointUri.getUserInfo());
52          assertEquals("admin", endpointUri.getUser());
53          assertEquals("pwd", endpointUri.getPassword());
54          assertEquals("http://admin:****@localhost:8080", endpointUri.toString());
55      }
56  
57      @Test
58      public void testHostPortAndPathUrl() throws Exception
59      {
60          EndpointURI endpointUri = new MuleEndpointURI("http://localhost:8080/app/path", muleContext);
61          endpointUri.initialise();
62          assertEquals("http", endpointUri.getScheme());
63          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
64          assertNull(endpointUri.getEndpointName());
65          assertEquals(8080, endpointUri.getPort());
66          assertEquals("localhost", endpointUri.getHost());
67          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
68          assertEquals(endpointUri.getPath(), "/app/path");
69          assertEquals(0, endpointUri.getParams().size());
70      }
71  
72      @Test
73      public void testHostPortAndPathUrlAndUserInfo() throws Exception
74      {
75          EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080/app/path", muleContext);
76          endpointUri.initialise();
77          assertEquals("http", endpointUri.getScheme());
78          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
79          assertNull(endpointUri.getEndpointName());
80          assertEquals(8080, endpointUri.getPort());
81          assertEquals("localhost", endpointUri.getHost());
82          assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
83          assertEquals(endpointUri.getPath(), "/app/path");
84          assertEquals(0, endpointUri.getParams().size());
85          assertEquals("admin:pwd", endpointUri.getUserInfo());
86          assertEquals("admin", endpointUri.getUser());
87          assertEquals("pwd", endpointUri.getPassword());
88          assertEquals("http://admin:****@localhost:8080/app/path", endpointUri.toString());
89  
90      }
91  
92      @Test
93      public void testHostPortAndPathUrlUserInfoAndQuery() throws Exception
94      {
95          EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080/app/path?${foo}", muleContext);
96          endpointUri.initialise();
97          assertEquals("http", endpointUri.getScheme());
98          assertEquals("http://localhost:8080/app/path?$[foo]", endpointUri.getAddress());
99          assertNull(endpointUri.getEndpointName());
100         assertEquals(8080, endpointUri.getPort());
101         assertEquals("localhost", endpointUri.getHost());
102         assertEquals(endpointUri.getPath(), "/app/path");
103         assertEquals(endpointUri.getQuery(), "$[foo]");
104         assertEquals(1, endpointUri.getParams().size());
105         assertEquals("admin:pwd", endpointUri.getUserInfo());
106         assertEquals("admin", endpointUri.getUser());
107         assertEquals("pwd", endpointUri.getPassword());
108         assertEquals("http://admin:****@localhost:8080/app/path?$[foo]", endpointUri.toString());
109 
110     }
111 }