1
2
3
4
5
6
7
8
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", muleContext);
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", muleContext);
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 assertEquals("http://admin:****@localhost:8080", endpointUri.toString());
47 }
48
49 public void testHostPortAndPathUrl() throws Exception
50 {
51 EndpointURI endpointUri = new MuleEndpointURI("http://localhost:8080/app/path", muleContext);
52 endpointUri.initialise();
53 assertEquals("http", endpointUri.getScheme());
54 assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
55 assertNull(endpointUri.getEndpointName());
56 assertEquals(8080, endpointUri.getPort());
57 assertEquals("localhost", endpointUri.getHost());
58 assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
59 assertEquals(endpointUri.getPath(), "/app/path");
60 assertEquals(0, endpointUri.getParams().size());
61 }
62
63 public void testHostPortAndPathUrlAndUserInfo() throws Exception
64 {
65 EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080/app/path", muleContext);
66 endpointUri.initialise();
67 assertEquals("http", endpointUri.getScheme());
68 assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
69 assertNull(endpointUri.getEndpointName());
70 assertEquals(8080, endpointUri.getPort());
71 assertEquals("localhost", endpointUri.getHost());
72 assertEquals("http://localhost:8080/app/path", endpointUri.getAddress());
73 assertEquals(endpointUri.getPath(), "/app/path");
74 assertEquals(0, endpointUri.getParams().size());
75 assertEquals("admin:pwd", endpointUri.getUserInfo());
76 assertEquals("admin", endpointUri.getUser());
77 assertEquals("pwd", endpointUri.getPassword());
78 assertEquals("http://admin:****@localhost:8080/app/path", endpointUri.toString());
79
80 }
81
82 public void testHostPortAndPathUrlUserInfoAndQuery() throws Exception
83 {
84 EndpointURI endpointUri = new MuleEndpointURI("http://admin:pwd@localhost:8080/app/path?${foo}", muleContext);
85 endpointUri.initialise();
86 assertEquals("http", endpointUri.getScheme());
87 assertEquals("http://localhost:8080/app/path?$[foo]", endpointUri.getAddress());
88 assertNull(endpointUri.getEndpointName());
89 assertEquals(8080, endpointUri.getPort());
90 assertEquals("localhost", endpointUri.getHost());
91 assertEquals(endpointUri.getPath(), "/app/path");
92 assertEquals(endpointUri.getQuery(), "$[foo]");
93 assertEquals(1, endpointUri.getParams().size());
94 assertEquals("admin:pwd", endpointUri.getUserInfo());
95 assertEquals("admin", endpointUri.getUser());
96 assertEquals("pwd", endpointUri.getPassword());
97 assertEquals("http://admin:****@localhost:8080/app/path?$[foo]", endpointUri.toString());
98
99 }
100 }