001: package com.sun.portal.rproxy.connectionhandler.test;
002:
003: import junit.framework.*;
004: import com.sun.portal.log.common.PortalLogger;
005: import com.sun.portal.rproxy.server.GatewayContextFactory;
006: import com.sun.portal.rproxy.server.DefaultGatewayContext;
007: import com.sun.portal.rproxy.connectionhandler.DomainWebProxyConfig;
008: import java.util.Arrays;
009: import java.util.List;
010: import java.util.ArrayList;
011: import java.util.logging.Logger;
012:
013: public class DomainWebProxyConfigTest extends TestCase {
014: public DomainWebProxyConfigTest(String name) {
015: super (name);
016: }
017:
018: private String[] domainSubDomainList = {
019: "aa.com aadomainproxy | subdomain aasubdomainproxy | * aastarproxy",
020: "bb.com bbdomainproxy | subdomain bbsubdomainproxy | * ",
021: "cc.com ccdomainproxy | subdomain ccsubdomainproxy",
022: "dd.com dddomainproxy | subdomain | * ddstarproxy",
023: "ee.com eedomainproxy | subdomain | *",
024: "ff.com ffdomainproxy | subdomain | * ffstarproxy",
025: "gg.com ggdomainproxy | * ggstarproxy",
026: "hh.com hhdomainproxy | *", "ii.com iidomainproxy",
027: "jj.com | subdomain jjsubdomainproxy | * jjstarproxy",
028: "kk.com | subdomain kksubdomainproxy | * ",
029: "ll.com | subdomain llsubdomainproxy",
030: "mm.com | subdomain | * mmstarproxy",
031: "nn.com | subdomain | *",
032: "oo.com | subdomain | * oostarproxy",
033: "pp.com | * ppstarproxy", "qq.com | *", "rr.com ",
034: "ss ssproxy", "tt" };
035:
036: private DefaultGatewayContext defaultGatewayContext = null;
037: private static Logger logger = PortalLogger
038: .getLogger(DomainWebProxyConfigTest.class);
039:
040: public void setUp() {
041: GatewayContextFactory
042: .init(GatewayContextFactory.DEFAULT_INSTANCE);
043: defaultGatewayContext = (DefaultGatewayContext) GatewayContextFactory
044: .getGatewayContext();
045:
046: }
047:
048: public void testContainHostUsingTranslateAll() {
049: defaultGatewayContext.setDomainsAndSubDomainsList(Arrays
050: .asList(domainSubDomainList));
051: defaultGatewayContext
052: .setDefaultDomainAndSubDomain("aa.com|subdomain");
053: boolean isContainHost = DomainWebProxyConfig
054: .containHost("www.sun.com");
055: assertEquals(false, isContainHost);
056:
057: defaultGatewayContext.setTranslateAll(true);
058: DomainWebProxyConfig.init();
059: isContainHost = DomainWebProxyConfig.containHost("www.sun.com");
060: assertEquals(true, isContainHost);
061: }
062:
063: public void testDefaultDomainSubDomain() {
064: defaultGatewayContext.setDomainsAndSubDomainsList(Arrays
065: .asList(domainSubDomainList));
066: defaultGatewayContext
067: .setDefaultDomainAndSubDomain("aa.com|subdomain");
068: DomainWebProxyConfig.init();
069: String webProxy = DomainWebProxyConfig.getWebProxy("machine");
070: assertEquals("aasubdomainproxy", webProxy);
071: }
072:
073: public void testDomainsAndSubDomains() {
074:
075: defaultGatewayContext.setDomainsAndSubDomainsList(Arrays
076: .asList(domainSubDomainList));
077: defaultGatewayContext
078: .setDefaultDomainAndSubDomain("aa.com|subdomain");
079: DomainWebProxyConfig.init();
080:
081: String[][] hostProxyMaps = {
082:
083: { "aa.com", "aadomainproxy" },
084: { "subdomain.aa.com", "aasubdomainproxy" },
085: { "subdomain2.aa.com", "aastarproxy" },
086: { "machine.subdomain.aa.com", "aasubdomainproxy" },
087: { "machine.subdomain2.aa.com", "aastarproxy" },
088:
089: { "bb.com", "bbdomainproxy" },
090: { "subdomain.bb.com", "bbsubdomainproxy" },
091: { "subdomain2.bb.com", null },
092: { "machine.subdomain.bb.com", "bbsubdomainproxy" },
093: { "machine.subdomain2.bb.com", null },
094:
095: { "cc.com", "ccdomainproxy" },
096: { "subdomain.cc.com", "ccsubdomainproxy" },
097: { "subdomain2.cc.com", "ccdomainproxy" },
098: { "machine.subdomain.cc.com", "ccsubdomainproxy" },
099: { "machine.subdomain2.cc.com", "ccdomainproxy" },
100:
101: { "dd.com", "dddomainproxy" },
102: { "subdomain.dd.com", "dddomainproxy" },
103: { "subdomain2.dd.com", "ddstarproxy" },
104: { "machine.subdomain.dd.com", "dddomainproxy" },
105: { "machine.subdomain2.dd.com", "ddstarproxy" },
106:
107: { "ee.com", "eedomainproxy" },
108: { "subdomain.ee.com", "eedomainproxy" },
109: { "subdomain2.ee.com", null },
110: { "machine.subdomain.ee.com", "eedomainproxy" },
111: { "machine.subdomain2.ee.com", null },
112:
113: { "ff.com", "ffdomainproxy" },
114: { "subdomain.ff.com", "ffdomainproxy" },
115: { "subdomain2.ff.com", "ffstarproxy" },
116: { "machine.subdomain.ff.com", "ffdomainproxy" },
117: { "machine.subdomain2.ff.com", "ffstarproxy" },
118:
119: { "gg.com", "ggdomainproxy" },
120: { "subdomain.gg.com", "ggstarproxy" },
121: { "subdomain2.gg.com", "ggstarproxy" },
122: { "machine.subdomain.gg.com", "ggstarproxy" },
123: { "machine.subdomain2.gg.com", "ggstarproxy" },
124:
125: { "hh.com", "hhdomainproxy" },
126: { "subdomain.hh.com", null },
127: { "subdomain2.hh.com", null },
128: { "machine.subdomain.hh.com", null },
129: { "machine.subdomain2.hh.com", null },
130:
131: { "ii.com", "iidomainproxy" },
132: { "subdomain.ii.com", "iidomainproxy" },
133: { "subdomain2.ii.com", "iidomainproxy" },
134: { "machine.subdomain.ii.com", "iidomainproxy" },
135: { "machine.subdomain2.ii.com", "iidomainproxy" },
136:
137: { "jj.com", null },
138: { "subdomain.jj.com", "jjsubdomainproxy" },
139: { "subdomain2.jj.com", "jjstarproxy" },
140: { "machine.subdomain.jj.com", "jjsubdomainproxy" },
141: { "machine.subdomain2.jj.com", "jjstarproxy" },
142:
143: { "kk.com", null },
144: { "subdomain.kk.com", "kksubdomainproxy" },
145: { "subdomain2.kk.com", null },
146: { "machine.subdomain.kk.com", "kksubdomainproxy" },
147: { "machine.subdomain2.kk.com", null },
148:
149: { "ll.com", null },
150: { "subdomain.ll.com", "llsubdomainproxy" },
151: { "subdomain2.ll.com", null },
152: { "machine.subdomain.ll.com", "llsubdomainproxy" },
153: { "machine.subdomain2.ll.com", null },
154:
155: { "mm.com", null }, { "subdomain.mm.com", null },
156: { "subdomain2.mm.com", "mmstarproxy" },
157: { "machine.subdomain.mm.com", null },
158: { "machine.subdomain2.mm.com", "mmstarproxy" },
159:
160: { "nn.com", null }, { "subdomain.nn.com", null },
161: { "subdomain2.nn.com", null },
162: { "machine.subdomain.nn.com", null },
163: { "machine.subdomain2.nn.com", null },
164:
165: { "oo.com", null }, { "subdomain.oo.com", null },
166: { "subdomain2.oo.com", "oostarproxy" },
167: { "machine.subdomain.oo.com", null },
168: { "machine.subdomain2.oo.com", "oostarproxy" },
169:
170: { "pp.com", null },
171: { "subdomain.pp.com", "ppstarproxy" },
172: { "subdomain2.pp.com", "ppstarproxy" },
173: { "machine.subdomain.pp.com", "ppstarproxy" },
174: { "machine.subdomain2.pp.com", "ppstarproxy" },
175:
176: { "qq.com", null }, { "subdomain.qq.com", null },
177: { "subdomain2.qq.com", null },
178: { "machine.subdomain.qq.com", null },
179: { "machine.subdomain2.qq.com", null },
180:
181: { "rr.com", null }, { "subdomain.rr.com", null },
182: { "subdomain2.rr.com", null },
183: { "machine.subdomain.rr.com", null },
184: { "machine.subdomain2.rr.com", null },
185:
186: { "ss", "ssproxy" }, { "subdomain.ss", "ssproxy" },
187: { "subdomain2.ss", "ssproxy" },
188: { "machine.subdomain.ss", "ssproxy" },
189: { "machine.subdomain2.ss", "ssproxy" },
190:
191: { "tt", null }, { "subdomain.tt", null },
192: { "subdomain2.tt", null },
193: { "machine.subdomain.tt", null },
194: { "machine.subdomain2.tt", null },
195:
196: /* { "xx.com", "starproxy"},
197: { "subdomain.xx.com", "starproxy"},
198: { "subdomain2.xx.com", "starproxy"},
199: { "machine.subdomain.xx.com", "starproxy"},
200: { "machine.subdomain2.xx.com", "starproxy"}, */
201:
202: };
203:
204: for (int i = 0; i < hostProxyMaps.length; i++) {
205: String webProxy = DomainWebProxyConfig
206: .getWebProxy(hostProxyMaps[i][0]);
207: assertEquals("The webproxy for " + hostProxyMaps[i][0],
208: hostProxyMaps[i][1], webProxy);
209: }
210:
211: }
212:
213: public void testStarProxy() {
214:
215: defaultGatewayContext.setDomainsAndSubDomainsList(Arrays
216: .asList(domainSubDomainList));
217: defaultGatewayContext
218: .setDefaultDomainAndSubDomain("aa.com|subdomain");
219: DomainWebProxyConfig.init();
220:
221: String[][] expectedHostProxyMaps = { { "xx.com", null },
222: { "subdomain.xx.com", null },
223: { "subdomain2.xx.com", null },
224: { "machine.subdomain.xx.com", null },
225: { "machine.subdomain2.xx.com", null }, };
226:
227: for (int i = 0; i < expectedHostProxyMaps.length; i++) {
228: String webProxy = DomainWebProxyConfig
229: .getWebProxy(expectedHostProxyMaps[i][0]);
230: assertEquals("The webproxy for "
231: + expectedHostProxyMaps[i][0],
232: expectedHostProxyMaps[i][1], webProxy);
233: }
234:
235: List listWithStarProxy = new ArrayList();
236: listWithStarProxy.addAll(Arrays.asList(domainSubDomainList));
237: listWithStarProxy.add("* starproxy");
238:
239: defaultGatewayContext
240: .setDomainsAndSubDomainsList(listWithStarProxy);
241: DomainWebProxyConfig.init();
242:
243: String[][] nowExpectedHostProxyMaps = {
244: { "xx.com", "starproxy" },
245: { "subdomain.xx.com", "starproxy" },
246: { "subdomain2.xx.com", "starproxy" },
247: { "machine.subdomain.xx.com", "starproxy" },
248: { "machine.subdomain2.xx.com", "starproxy" } };
249:
250: for (int i = 0; i < nowExpectedHostProxyMaps.length; i++) {
251: String webProxy = DomainWebProxyConfig
252: .getWebProxy(nowExpectedHostProxyMaps[i][0]);
253: assertEquals("After setting StarProxy, the webproxy for "
254: + nowExpectedHostProxyMaps[i][0],
255: nowExpectedHostProxyMaps[i][1], webProxy);
256: }
257:
258: }
259:
260: public static Test suite() {
261: TestSuite suite = new TestSuite();
262: suite.addTestSuite(DomainWebProxyConfigTest.class);
263: return suite;
264: }
265:
266: public static void main(String[] args) {
267: junit.textui.TestRunner.run(suite());
268: }
269: }
|