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.asset.AssetService; 20 import org.apache.tapestry.engine.ServiceEncoding; 21 import org.apache.tapestry.services.ServiceConstants; 22 import org.easymock.MockControl; 23 24 30 public class TestAssetEncoder extends HiveMindTestCase 31 { 32 public void testWrongService() 33 { 34 MockControl control = newControl(ServiceEncoding.class); 35 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 36 37 encoding.getParameterValue(ServiceConstants.SERVICE); 38 control.setReturnValue("foo"); 39 40 replayControls(); 41 42 new AssetEncoder().encode(encoding); 43 44 verifyControls(); 45 } 46 47 public void testWrongPath() 48 { 49 MockControl control = newControl(ServiceEncoding.class); 50 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 51 52 encoding.getServletPath(); 53 control.setReturnValue("/Home.page"); 54 55 replayControls(); 56 57 AssetEncoder encoder = new AssetEncoder(); 58 encoder.setPath("/assets/"); 59 60 encoder.decode(encoding); 61 62 verifyControls(); 63 } 64 65 public void testEncode() 66 { 67 MockControl control = newControl(ServiceEncoding.class); 68 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 69 70 encoding.getParameterValue(ServiceConstants.SERVICE); 71 control.setReturnValue(Tapestry.ASSET_SERVICE); 72 73 encoding.getParameterValue(AssetService.PATH); 74 control.setReturnValue("/foo/bar/Baz.gif"); 75 76 encoding.getParameterValue(AssetService.DIGEST); 77 control.setReturnValue("12345"); 78 79 encoding.setServletPath("/assets/12345/foo/bar/Baz.gif"); 80 encoding.setParameterValue(AssetService.PATH, null); 81 encoding.setParameterValue(AssetService.DIGEST, null); 82 encoding.setParameterValue(ServiceConstants.SERVICE, null); 83 84 replayControls(); 85 86 AssetEncoder encoder = new AssetEncoder(); 87 encoder.setPath("/assets/"); 88 89 encoder.encode(encoding); 90 91 verifyControls(); 92 } 93 94 public void testDecode() 95 { 96 MockControl control = newControl(ServiceEncoding.class); 97 ServiceEncoding encoding = (ServiceEncoding) control.getMock(); 98 99 encoding.getServletPath(); 100 control.setReturnValue("/assets/12345/foo/bar/Baz.gif"); 101 102 encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.ASSET_SERVICE); 103 encoding.setParameterValue(AssetService.DIGEST, "12345"); 104 encoding.setParameterValue(AssetService.PATH, "/foo/bar/Baz.gif"); 105 106 replayControls(); 107 108 AssetEncoder encoder = new AssetEncoder(); 109 encoder.setPath("/assets/"); 110 111 encoder.decode(encoding); 112 113 verifyControls(); 114 } 115 } | Popular Tags |