1 15 package org.apache.tapestry.services.impl; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.apache.tapestry.IMarkupWriter; 19 import org.apache.tapestry.INamespace; 20 import org.apache.tapestry.IPage; 21 import org.apache.tapestry.IRequestCycle; 22 import org.easymock.MockControl; 23 24 30 public class TestBaseTagWriter extends HiveMindTestCase 31 { 32 private IMarkupWriter newWriter(String url) 33 { 34 IMarkupWriter writer = (IMarkupWriter) newMock(IMarkupWriter.class); 35 36 writer.beginEmpty("base"); 37 writer.attribute("href", url); 38 writer.println(); 39 40 return writer; 41 } 42 43 private INamespace newNamespace(String id) 44 { 45 MockControl control = newControl(INamespace.class); 46 INamespace ns = (INamespace) control.getMock(); 47 48 ns.getId(); 49 control.setReturnValue(id); 50 51 return ns; 52 } 53 54 private IPage newPage(String pageName) 55 { 56 return newPage(newNamespace(null), pageName); 57 } 58 59 private IPage newPage(INamespace ns, String pageName) 60 { 61 MockControl control = newControl(IPage.class); 62 IPage page = (IPage) control.getMock(); 63 64 page.getNamespace(); 65 control.setReturnValue(ns); 66 67 if (pageName != null) 68 { 69 page.getPageName(); 70 control.setReturnValue(pageName); 71 } 72 73 return page; 74 } 75 76 private IRequestCycle newRequestCycle(IPage page, String url) 77 { 78 MockControl control = newControl(IRequestCycle.class); 79 IRequestCycle cycle = (IRequestCycle) control.getMock(); 80 81 cycle.getPage(); 82 control.setReturnValue(page); 83 84 cycle.getAbsoluteURL(url); 85 control.setReturnValue("http://foo.com/context" + url); 86 87 return cycle; 88 } 89 90 private void run(IMarkupWriter writer, IRequestCycle cycle) 91 { 92 replayControls(); 93 94 new BaseTagWriter().render(writer, cycle); 95 96 verifyControls(); 97 } 98 99 public void testNotApplicationNamespace() 100 { 101 INamespace ns = newNamespace("library"); 102 IPage page = newPage(ns, null); 103 IRequestCycle cycle = newRequestCycle(page, "/"); 104 IMarkupWriter writer = newWriter("http://foo.com/context/"); 105 106 run(writer, cycle); 107 } 108 109 public void testInRoot() 110 { 111 IPage page = newPage("Home"); 112 IRequestCycle cycle = newRequestCycle(page, "/"); 113 IMarkupWriter writer = newWriter("http://foo.com/context/"); 114 115 run(writer, cycle); 116 } 117 118 public void testInSubFolder() 119 { 120 IPage page = newPage("admin/AdminMenu"); 121 IRequestCycle cycle = newRequestCycle(page, "/admin/"); 122 IMarkupWriter writer = newWriter("http://foo.com/context/admin/"); 123 124 run(writer, cycle); 125 } 126 } | Popular Tags |