KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlet > cocoon > TestURLRewriter


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.portlet.cocoon;
6
7 import org.exoplatform.container.PortalContainer;
8 import org.exoplatform.container.RootContainer;
9 import org.exoplatform.portlet.cocoon.URLRewriter;
10 import org.exoplatform.services.log.LogService;
11 import java.io.*;
12 import org.apache.commons.logging.Log;
13 import junit.framework.TestCase;
14
15 /**
16  * Created by the Exo Development team.
17  */

18 public class TestURLRewriter extends TestCase {
19
20    private Log log;
21    public void setUp() throws Exception JavaDoc
22    {
23
24        LogService logService = (LogService) RootContainer.getInstance().
25                             getComponentInstanceOfType(LogService.class);
26
27     log = logService.getLog("org.exoplatform.services.xml");
28     logService.setLogLevel("org.exoplatform.services.xml", LogService.DEBUG, true);
29
30     log = logService.getLog("org.exoplatform.portlet.cocoon");
31     logService.setLogLevel("org.exoplatform.portlet.cocoon", LogService.DEBUG, true);
32
33     log = logService.getLog(this.getClass());
34
35
36    }
37
38   public void testRewrite() throws Exception JavaDoc {
39 // byte[] buffer = "<a HREF=\"http://test/test.jsp\">test</a>".getBytes();
40
// String testStr = "<a xmlns=\"\" HREF=\"page.jsp?portal:ctx=exo&portal:componentId=window-Cocoon&url=cocoon/samples/\">test</a>";
41
// assertEquals(testStr, URLRewriter.rewrite(buffer, "cocoon/", "page.jsp?portal:ctx=exo&portal:componentId=window-Cocoon") );
42

43 // byte[] buffer = "<a HREF=\"samples/\">test</a>".getBytes();
44
// System.out.println("OUT----"+URLRewriter.rewrite(buffer, "cocoon/", "portal/faces/public/page.jsp?portal:ctx=exo&portal:componentId=window-Cocoon"));
45

46
47
48       String JavaDoc test_url = "<a HREF='samples/'>test</a> "+
49                      " <a HREF='?cocoon-view=pretty-content'>Pretty content</a>";
50
51       ByteArrayInputStream inputStream =
52               new ByteArrayInputStream(test_url.getBytes());
53
54
55       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
56       URLRewriter urlRewriter = new URLRewriter();
57
58       urlRewriter.rewrite(inputStream, outputStream,
59               "portal/faces/public/page.jsp?portal:ctx=exo&portal:componentId=window-Cocoon",
60               "cocoon/");
61
62     assertTrue("empty output",outputStream.size()>0);
63     log.debug("Out 1 ["+outputStream+"]");
64     System.out.println("Out 1 ["+outputStream+"]");
65
66       String JavaDoc prospective_url =
67             "portal/faces/public/page.jsp?portal:ctx=exo&amp;" +
68             "portal:componentId=window-Cocoon&amp;url=cocoon/samples/";
69       assertTrue("Wrong result 1",outputStream.toString().indexOf(prospective_url) >= 0);
70
71       inputStream.reset();
72       outputStream.close();
73       urlRewriter.rewrite(inputStream, outputStream,
74                           "portal/faces/public/page.jsp",
75                           "cocoon/");
76       log.debug("Out 1 ["+outputStream+"]");
77       assertTrue("empty output",outputStream.size()>0);
78
79
80       prospective_url =
81             "portal/faces/public/page.jsp?url=cocoon/samples/";
82       assertTrue("Wrong result 2",outputStream.toString().indexOf(prospective_url) >= 0);
83
84
85   }
86 }
87
Popular Tags