1 15 package org.apache.tapestry.engine.encoders; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.apache.tapestry.Tapestry; 19 import org.apache.tapestry.engine.ServiceEncoding; 20 import org.apache.tapestry.services.ServiceConstants; 21 import org.easymock.MockControl; 22 23 29 public class TestDirectServiceEncoder extends HiveMindTestCase 30 { 31 private ServiceEncoding newEncoding(String servletPath) 32 { 33 MockControl control = newControl(ServiceEncoding.class); 34 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 35 36 encoding.getServletPath(); 37 control.setReturnValue(servletPath); 38 39 return encoding; 40 } 41 42 private void train(MockControl control, ServiceEncoding encoding, String parameterName, 43 String parameterValue) 44 { 45 encoding.getParameterValue(parameterName); 46 control.setReturnValue(parameterValue); 47 } 48 49 public void testEncodeWrongService() 50 { 51 MockControl control = newControl(ServiceEncoding.class); 52 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 53 54 train(control, encoding, ServiceConstants.SERVICE, "foo"); 55 56 replayControls(); 57 58 DirectServiceEncoder encoder = new DirectServiceEncoder(); 59 60 encoder.encode(encoding); 61 62 verifyControls(); 63 } 64 65 public void testEncodePageInNamespace() 66 { 67 MockControl control = newControl(ServiceEncoding.class); 68 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 69 70 train(control, encoding, ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE); 71 train(control, encoding, ServiceConstants.PAGE, "foo:Bar"); 72 73 replayControls(); 74 75 DirectServiceEncoder encoder = new DirectServiceEncoder(); 76 77 encoder.encode(encoding); 78 79 verifyControls(); 80 } 81 82 public void testEncodeStateless() 83 { 84 MockControl control = newControl(ServiceEncoding.class); 85 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 86 87 train(control, encoding, ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE); 88 train(control, encoding, ServiceConstants.PAGE, "admin/Menu"); 89 train(control, encoding, ServiceConstants.SESSION, null); 90 train(control, encoding, ServiceConstants.COMPONENT, "border.link"); 91 92 encoding.setServletPath("/admin/Menu,border.link.direct"); 93 encoding.setParameterValue(ServiceConstants.SERVICE, null); 94 encoding.setParameterValue(ServiceConstants.PAGE, null); 95 encoding.setParameterValue(ServiceConstants.SESSION, null); 96 encoding.setParameterValue(ServiceConstants.COMPONENT, null); 97 98 replayControls(); 99 100 DirectServiceEncoder encoder = new DirectServiceEncoder(); 101 encoder.setStatelessExtension("direct"); 102 103 encoder.encode(encoding); 104 105 verifyControls(); 106 } 107 108 public void testEncodeStateful() 109 { 110 MockControl control = newControl(ServiceEncoding.class); 111 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 112 113 train(control, encoding, ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE); 114 train(control, encoding, ServiceConstants.PAGE, "admin/Menu"); 115 train(control, encoding, ServiceConstants.SESSION, "T"); 116 train(control, encoding, ServiceConstants.COMPONENT, "border.link"); 117 118 encoding.setServletPath("/admin/Menu,border.link.sdirect"); 119 encoding.setParameterValue(ServiceConstants.SERVICE, null); 120 encoding.setParameterValue(ServiceConstants.PAGE, null); 121 encoding.setParameterValue(ServiceConstants.SESSION, null); 122 encoding.setParameterValue(ServiceConstants.COMPONENT, null); 123 124 replayControls(); 125 126 DirectServiceEncoder encoder = new DirectServiceEncoder(); 127 encoder.setStatefulExtension("sdirect"); 128 129 encoder.encode(encoding); 130 131 verifyControls(); 132 } 133 134 public void testDecodeWrongExtension() 135 { 136 ServiceEncoding encoding = newEncoding("/foo.svc"); 137 138 replayControls(); 139 140 DirectServiceEncoder encoder = new DirectServiceEncoder(); 141 encoder.setStatelessExtension("direct"); 142 encoder.setStatefulExtension("sdirect"); 143 144 encoder.decode(encoding); 145 146 verifyControls(); 147 } 148 149 public void testDecodeStateless() 150 { 151 ServiceEncoding encoding = newEncoding("/admin/Menu,border.link.direct"); 152 153 encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE); 154 encoding.setParameterValue(ServiceConstants.PAGE, "admin/Menu"); 155 encoding.setParameterValue(ServiceConstants.SESSION, null); 156 encoding.setParameterValue(ServiceConstants.COMPONENT, "border.link"); 157 158 replayControls(); 159 160 DirectServiceEncoder encoder = new DirectServiceEncoder(); 161 encoder.setStatelessExtension("direct"); 162 encoder.setStatefulExtension("sdirect"); 163 164 encoder.decode(encoding); 165 166 verifyControls(); 167 } 168 169 public void testDecodeStateful() 170 { 171 ServiceEncoding encoding = newEncoding("/admin/Menu,border.link.sdirect"); 172 173 encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE); 174 encoding.setParameterValue(ServiceConstants.PAGE, "admin/Menu"); 175 encoding.setParameterValue(ServiceConstants.SESSION, "T"); 176 encoding.setParameterValue(ServiceConstants.COMPONENT, "border.link"); 177 178 replayControls(); 179 180 DirectServiceEncoder encoder = new DirectServiceEncoder(); 181 encoder.setStatelessExtension("direct"); 182 encoder.setStatefulExtension("sdirect"); 183 184 encoder.decode(encoding); 185 186 verifyControls(); 187 } 188 } | Popular Tags |