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