KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > reverseproxy > ReverseProxyMethodHandlerTest


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.reverseproxy;
21
22 import static org.junit.Assert.assertEquals;
23 import org.junit.Test;
24
25 public class ReverseProxyMethodHandlerTest {
26     @Test
27     public void stripHttpProtocol() {
28         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("http://");
29         assertEquals("", stripProtocol);
30     }
31
32     @Test
33     public void stripHttpsProtocol() {
34         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("https://");
35         assertEquals("", stripProtocol);
36     }
37     
38     @Test
39     public void stripHttp() {
40         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("http://google.com");
41         assertEquals("google.com", stripProtocol);
42     }
43
44     @Test
45     public void stripHttps() {
46         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("https://google.com");
47         assertEquals("google.com", stripProtocol);
48     }
49     
50     @Test
51     public void stripNothing() {
52         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("");
53         assertEquals("", stripProtocol);
54     }
55     
56     @Test
57     public void stripForwardSlash() {
58         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("/");
59         assertEquals("/", stripProtocol);
60     }
61     
62     @Test
63     public void stripHost() {
64         String JavaDoc stripProtocol = ReverseProxyMethodHandler.stripProtocol("google.com");
65         assertEquals("google.com", stripProtocol);
66     }
67     
68     @Test
69     public void rebuildHttpLocalhost() {
70         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("http://localhost/home", "localhost", "google.com");
71         assertEquals("https://localhost/home", newLocation);
72     }
73     
74     @Test
75     public void rebuildHttpsLocalhost() {
76         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("https://localhost/home", "localhost", "google.com");
77         assertEquals("https://localhost/home", newLocation);
78     }
79     
80     @Test
81     public void rebuildLocalhostWithParmeters() {
82         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("https://localhost/home/blah?username=karl", "localhost", "google.com");
83         assertEquals("https://localhost/home/blah?username=karl", newLocation);
84     }
85     
86     @Test
87     public void rebuildHttpRemotehost() {
88         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("http://google.com/home", "localhost", "google.com");
89         assertEquals("https://localhost/home", newLocation);
90     }
91     
92     @Test
93     public void rebuildHttpsRemotehost() {
94         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("https://google.com/home", "localhost", "google.com");
95         assertEquals("https://localhost/home", newLocation);
96     }
97     
98     @Test
99     public void rebuildRemotehostWithParmeters() {
100         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("https://google.com/home/blah?username=karl", "localhost", "google.com");
101         assertEquals("https://localhost/home/blah?username=karl", newLocation);
102     }
103     
104     @Test
105     public void rebuildSlashHost() {
106         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("/", "localhost", "google.com");
107         assertEquals("/", newLocation);
108     }
109     
110     @Test
111     public void rebuildSlashPath() {
112         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("/home/blah?username=karl", "localhost", "google.com");
113         assertEquals("/home/blah?username=karl", newLocation);
114     }
115     
116     @Test
117     public void rebuildHttpUnknownHost() {
118         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("http://unknown/", "localhost", "google.com");
119         assertEquals("http://unknown/", newLocation);
120     }
121     
122     @Test
123     public void rebuildHttpsUnknownHost() {
124         String JavaDoc newLocation = ReverseProxyMethodHandler.rebuildLocation("https://unknown/", "localhost", "google.com");
125         assertEquals("https://unknown/", newLocation);
126     }
127 }
Popular Tags