1 4 package com.openedit.page; 5 6 import java.util.List ; 7 8 import junit.textui.TestRunner; 9 10 import com.openedit.BaseTestCase; 11 import com.openedit.ModuleManager; 12 import com.openedit.TestFixture; 13 import com.openedit.WebPageRequest; 14 15 18 public class PageRequestTest extends BaseTestCase 19 { 20 21 public PageRequestTest( String name ) 22 { 23 super( name ); 24 } 25 public static void main(String [] args) 26 { 27 TestRunner.run(PageRequestTest.class); 28 } 29 30 public void testIsEditable() throws Exception 31 { 32 TestFixture fixture = getFixture(); 33 Page page = getPage("/index.html"); 34 WebPageRequest req = getFixture().createPageRequest("/index.html"); 35 req.setUser(null); 36 assertFalse( req.isEditable() ); 37 38 } 39 public void testActionCount() throws Exception 40 { 41 45 Page page = getPage("/actions/includesfouractions.html"); 46 List actions = page.getPageActions(); 47 assertEquals(2,actions.size()); 49 WebPageRequest context = getFixture().createPageRequest("/actions/includesfouractions.html"); 50 getFixture().getEngine().beginRender(context); 51 52 page = getPage("/actions/fouractions.html"); 54 actions = page.getPageActions(); 55 assertEquals(2,actions.size()); 56 57 } 58 69 public void testFallBackDirectory() throws Exception 70 { 71 Page overridepage = getPage("/fallbackme/sub/fake.html"); 72 assertTrue( overridepage.exists() ); 73 assertNotNull( overridepage.getLayout() ); 74 assertEquals( "/fallbackme/layout1.html", overridepage.getLayout()); 75 String content = overridepage.getContent(); 76 assertEquals("<DIV>Fallback File</DIV>",content); 77 } 78 public void testFallBackDirectoryUseLayout() throws Exception 79 { 80 Page overridepage = getPage("/fallbackmenolayout/index.html"); 81 assertNotNull( overridepage.getLayout() ); 82 assertEquals( "/fallbackfiles/layout1junk.html", overridepage.getLayout()); 83 } 84 public void testFallBackSubDirectory() throws Exception 85 { 86 Page overridepage = getPage("/fallbackme/deep/deeper/content.html"); 87 assertTrue( overridepage.exists() ); 88 assertNotNull( overridepage.getLayout() ); 89 assertEquals( "/fallbackme/layout1.html", overridepage.getLayout()); 90 String content = overridepage.getContent(); 91 assertEquals("<DIV>Fallback to Here</DIV>",content); 92 } 93 public void testFallBackContentFile() throws Exception 94 { 95 96 Page overridepage = getPage("/fallbackme/nocontentfront.html"); 97 assertTrue( overridepage.exists() ); 98 String content = overridepage.getContent(); 99 assertEquals("<DIV>OLD</DIV>",content); 100 101 107 } 108 public void testFallbackProperty() throws Exception 109 { 110 Page overridepage = getPage("/fallbackme/somecontent.html"); 111 assertTrue( overridepage.exists() ); 112 113 String title = overridepage.get("browserTitle"); 114 assertEquals("Community",title ); 115 116 } 117 118 119 public void testContentFile() throws Exception 120 { 121 final String VIRTUAL_PAGE = "/contenttest/virtualpage.html"; 122 WebPageRequest context = getFixture().createPageRequest(VIRTUAL_PAGE); 123 PageStreamer streamer = context.getPageStreamer(); 124 streamer.render(); 125 126 String content = context.getWriter().toString(); 127 assertTrue(content.indexOf("actual content") >= 0); 128 assertTrue(content.indexOf("Welcome") >= 0); 130 } 131 public void testStream() throws Exception 132 { 133 final String VIRTUAL_PAGE = "/test/test.html"; 134 WebPageRequest context = getFixture().createPageRequest(VIRTUAL_PAGE); 135 PageStreamer streamer = context.getPageStreamer(); 136 assertTrue( streamer.doesExist("./side.html") ); 137 138 streamer.stream("./side.html"); 139 String content = context.getWriter().toString(); 140 assertFalse(content.indexOf("not found") >= 0); 141 assertTrue(content.indexOf("side") >= 0); 142 143 } 144 public void testCancelActions() throws Exception 145 { 146 Page page = getPage("/actions/cancel/threeactions.html"); 147 List actions = page.getPathActions(); 148 assertEquals(3,actions.size()); 149 PageAction action = (PageAction)actions.get(2); String clas = action.getConfig().getAttribute("class"); 152 assertEquals("java.sql.Date",clas); 153 ModuleManager manager = new ModuleManager(); 154 List small = manager.condenseActions(actions); 155 assertEquals(1,small.size()); 156 PageAction action2 = (PageAction)small.get(0); String clas2 = action2.getConfig().getAttribute("class"); 158 assertEquals("java.sql.Date",clas2); 159 160 } 161 162 public void testInnerInnerLayout() throws Exception 163 { 164 final String path = "/innerlayouts/contentpage.html"; 165 WebPageRequest context = getFixture().createPageRequest(path); 166 PageStreamer streamer = context.getPageStreamer(); 167 168 streamer.render(); 169 String content = context.getWriter().toString(); 170 assertEquals("1\n2\n3\n4\n5",content); 171 } 172 } 173 | Popular Tags |