01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rproxy.rewriter.test;
06:
07: import com.sun.portal.rewriter.test.util.BasicTestCase;
08: import com.sun.portal.log.common.PortalLogger;
09: import com.sun.portal.rproxy.connectionhandler.Request;
10: import com.sun.portal.rproxy.connectionhandler.Response;
11: import com.sun.portal.rproxy.rewriter.SRAPAdapter;
12: import com.sun.portal.rproxy.rewriter.SRAPRewriterModule;
13: import com.sun.portal.rproxy.rewriter.test.util.MockRequest;
14: import com.sun.portal.rproxy.rewriter.test.util.MockResponse;
15: import junit.framework.TestSuite;
16:
17: import java.io.BufferedInputStream;
18:
19: public class TestSRAPAdapter extends BasicTestCase {
20: public TestSRAPAdapter(String aName) {
21: super (aName);
22: }//constructor
23:
24: public void testNot2RewriteContent() throws Exception {
25: Request lRequest = new MockRequest(
26: "https://zeus.nawab.india.com/",
27: "http://raja.sun.com/Base/ja/i18n.js");
28: assertNull(
29: "The stream should be returned untouched i.e null should be returned",
30: SRAPAdapter.rewrite(lRequest, new MockResponse("", "",
31: "")));
32: }//testNot2RewriteContent()
33:
34: public void testNot2RewriteContentNegative() throws Exception {
35: Request lRequest = new MockRequest(
36: "https://zeus.nawab.india.com/",
37: //RuleSet for this URI would be empty hence content is returned as is
38: "http://rajauiowreu.sunoiuwer.cwrepipwroeom/Base/jai18n.js");
39: Response lResponse = new MockResponse("", "", "");
40: assertNotNull(SRAPAdapter.rewrite(lRequest, lResponse));
41: }//testNot2RewriteContentNegative()
42:
43: public void testUnknownEncoding() throws Exception {
44: BufferedInputStream bis = new BufferedInputStream(String.class
45: .getResourceAsStream("/java/lang/String.class"));
46: Request lRequest = new MockRequest(
47: "https://zeus.nawab.india.com/",
48: "http://rajaweqewqweqwqe.sunwwwwwww.com/eee.js");
49: Response lResponse = new MockResponse(bis, "", "");
50: byte[] lResultBuf = new byte[1024];
51: SRAPAdapter.rewrite(lRequest, lResponse).read(lResultBuf);
52: byte[] origBuf = new byte[1024];
53: String.class.getResourceAsStream("/java/lang/String.class")
54: .read(origBuf);
55:
56: for (int i = 0; i < 1024; i++) {
57: assertEquals(lResultBuf[i], origBuf[i]);
58: }
59: }//testUnknownEncoding()
60:
61: public static void main(String[] args) {
62: SRAPRewriterModule.initFile();
63: //BasicTestCase.run( TestSRAPAdapter.class );
64: TestSuite testSuite = new TestSuite();
65: testSuite.addTest(new TestSRAPAdapter("testUnknownEncoding"));
66: BasicTestCase.run(testSuite);
67: }//main()
68:
69: }//class TestSRAPAdapter
|