1 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 18 public class TestURLRewriter extends TestCase { 19 20 private Log log; 21 public void setUp() throws Exception 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 { 39 43 46 47 48 String 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 prospective_url = 67 "portal/faces/public/page.jsp?portal:ctx=exo&" + 68 "portal:componentId=window-Cocoon&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 |