KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > generators > VelocityGeneratorTest


1 /*
2  * Created on Nov 20, 2004
3  */

4 package com.openedit.generators;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.openedit.repository.filesystem.StringItem;
9
10 import com.openedit.BaseTestCase;
11 import com.openedit.WebPageRequest;
12 import com.openedit.page.Page;
13 import com.openedit.page.PageSettings;
14
15 /**
16  * @author Matthew Avery, mavery@einnovation.com
17  */

18 public class VelocityGeneratorTest extends BaseTestCase
19 {
20     private static final Log log = LogFactory.getLog(VelocityGeneratorTest.class);
21     public VelocityGeneratorTest( String JavaDoc name )
22     {
23         super( name );
24     }
25
26     public void testGenerate() throws Exception JavaDoc
27     {
28         WebPageRequest context = getFixture().createPageRequest("/generators/velocity.html");
29         context.putPageValue("variable", ", it worked.");
30         context.getPageStreamer().render();
31         String JavaDoc result = context.getWriter().toString();
32         log.info( result );
33         assertEquals( "<p>\nTest stuff , it worked.\n</p>", result );
34     }
35     
36     //Does not pass because we have no way to save the encoding flag
37
public void testEncoding() throws Exception JavaDoc
38     {
39         Page page = getPage("/apos.html");
40         getFixture().getPageManager().removePage(page);
41         
42         //change the encoding
43
PageSettings settings = page.getPageSettings();
44         settings.setPageCharacterEncoding("ISO-8859-1"); //TODO: This is not ending up anyplace
45
//getFixture().getPageManager().getPageSettingsManager().saveSetting(settings);
46

47         //create the content
48
String JavaDoc desc = "<DIV>Hobby Horse\u0092</DIV>";
49         StringItem newItem = new StringItem(page.getPath(),desc, settings.getPageCharacterEncoding());
50         newItem.setMessage("Testing");
51         page.setContentItem(newItem);
52         
53         getFixture().getPageManager().putPage(page);
54         getFixture().getPageManager().clearCache();
55         Thread.sleep(100);
56         //make sure we can read it back in again
57
Page reloadpage = getPage("/apos.html");
58         assertEquals( "ISO-8859-1",reloadpage.getCharacterEncoding());
59
60         
61         String JavaDoc reloadcontent = reloadpage.getContent();
62         assertEquals(desc,reloadcontent);
63         
64         //TODO: Now read it back in with the wrong encoding just to be sure
65
//you get the wrong answer
66
String JavaDoc wrongencoding = "<DIV>Hobby Horse\u2019</DIV>";
67                 
68         //If the encoding was UTF-8 then we would have got back \u2019 instead of 92
69
//92 is the correct value we expected when using this encoding
70

71     }
72 }
73
Popular Tags