1 15 package org.apache.tapestry.engine.encoders; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.apache.tapestry.engine.ServiceEncoding; 19 import org.apache.tapestry.services.ServiceConstants; 20 import org.easymock.MockControl; 21 22 28 public class TestPageServiceEncoder extends HiveMindTestCase 29 { 30 public void testEncodeOtherService() 31 { 32 MockControl control = newControl(ServiceEncoding.class); 33 ServiceEncoding e = (ServiceEncoding) control.getMock(); 34 35 e.getParameterValue(ServiceConstants.SERVICE); 36 control.setReturnValue("foo"); 37 38 replayControls(); 39 40 PageServiceEncoder encoder = new PageServiceEncoder(); 41 encoder.setServiceName("page"); 42 43 encoder.encode(e); 44 45 verifyControls(); 46 } 47 48 public void testEncode() 49 { 50 MockControl control = newControl(ServiceEncoding.class); 51 ServiceEncoding e = (ServiceEncoding) control.getMock(); 52 53 e.getParameterValue(ServiceConstants.SERVICE); 54 control.setReturnValue("page"); 55 56 e.getParameterValue(ServiceConstants.PAGE); 57 control.setReturnValue("Home"); 58 59 e.setServletPath("/Home.html"); 60 e.setParameterValue(ServiceConstants.SERVICE, null); 61 e.setParameterValue(ServiceConstants.PAGE, null); 62 63 replayControls(); 64 65 PageServiceEncoder encoder = new PageServiceEncoder(); 66 encoder.setServiceName("page"); 67 encoder.setExtension("html"); 68 69 encoder.encode(e); 70 71 verifyControls(); 72 } 73 74 public void testEncodeInNamespace() 75 { 76 MockControl control = newControl(ServiceEncoding.class); 77 ServiceEncoding e = (ServiceEncoding) control.getMock(); 78 79 e.getParameterValue(ServiceConstants.SERVICE); 80 control.setReturnValue("page"); 81 82 e.getParameterValue(ServiceConstants.PAGE); 83 control.setReturnValue("contrib:Foo"); 84 85 replayControls(); 86 87 PageServiceEncoder encoder = new PageServiceEncoder(); 88 encoder.setServiceName("page"); 89 90 encoder.encode(e); 91 92 verifyControls(); 93 } 94 95 public void testDecodeNoExtension() 96 { 97 MockControl control = newControl(ServiceEncoding.class); 98 ServiceEncoding e = (ServiceEncoding) control.getMock(); 99 100 e.getServletPath(); 101 control.setReturnValue("/app"); 102 103 replayControls(); 104 105 PageServiceEncoder encoder = new PageServiceEncoder(); 106 107 encoder.decode(e); 108 109 verifyControls(); 110 } 111 112 public void testDecodeEndsWithDot() 113 { 114 MockControl control = newControl(ServiceEncoding.class); 115 ServiceEncoding e = (ServiceEncoding) control.getMock(); 116 117 e.getServletPath(); 118 control.setReturnValue("/ends.with.dot."); 119 120 replayControls(); 121 122 PageServiceEncoder encoder = new PageServiceEncoder(); 123 124 encoder.decode(e); 125 126 verifyControls(); 127 } 128 129 public void testDecodeWrongExtension() 130 { 131 MockControl control = newControl(ServiceEncoding.class); 132 ServiceEncoding e = (ServiceEncoding) control.getMock(); 133 134 e.getServletPath(); 135 control.setReturnValue("/Home.direct"); 136 137 replayControls(); 138 139 PageServiceEncoder encoder = new PageServiceEncoder(); 140 141 encoder.decode(e); 142 143 verifyControls(); 144 } 145 146 public void testDecodeSuccess() 147 { 148 MockControl control = newControl(ServiceEncoding.class); 149 ServiceEncoding e = (ServiceEncoding) control.getMock(); 150 151 e.getServletPath(); 152 control.setReturnValue("/Home.html"); 153 154 e.setParameterValue(ServiceConstants.SERVICE, "page"); 155 e.setParameterValue(ServiceConstants.PAGE, "Home"); 156 157 replayControls(); 158 159 PageServiceEncoder encoder = new PageServiceEncoder(); 160 encoder.setExtension("html"); 161 encoder.setServiceName("page"); 162 163 encoder.decode(e); 164 165 verifyControls(); 166 } 167 } | Popular Tags |