1 15 package org.apache.tapestry.asset; 16 17 import java.util.Collections ; 18 import java.util.List ; 19 import java.util.Locale ; 20 21 import org.apache.hivemind.Location; 22 import org.apache.hivemind.Resource; 23 import org.apache.hivemind.test.HiveMindTestCase; 24 import org.apache.tapestry.IAsset; 25 import org.easymock.MockControl; 26 27 33 public class TestAssetSource extends HiveMindTestCase 34 { 35 private AssetFactoryContribution newContribution(String prefix, AssetFactory factory) 36 { 37 AssetFactoryContribution c = new AssetFactoryContribution(); 38 c.setPrefix(prefix); 39 c.setFactory(factory); 40 41 return c; 42 } 43 44 private List newContributions(String prefix, AssetFactory factory) 45 { 46 return Collections.singletonList(newContribution(prefix, factory)); 47 } 48 49 private Resource newResource() 50 { 51 return (Resource) newMock(Resource.class); 52 } 53 54 private AssetFactory newAssetFactory(Resource base, String path, Locale locale, 55 Location location, IAsset asset) 56 { 57 MockControl control = newControl(AssetFactory.class); 58 AssetFactory f = (AssetFactory) control.getMock(); 59 60 f.createAsset(base, path, locale, location); 61 control.setReturnValue(asset); 62 63 return f; 64 } 65 66 private IAsset newAsset() 67 { 68 return (IAsset) newMock(IAsset.class); 69 } 70 71 public void testKnownPrefix() 72 { 73 Location l = fabricateLocation(17); 74 75 Resource r = newResource(); 76 IAsset asset = newAsset(); 77 78 List contributions = newContributions("known", newAssetFactory( 79 r, 80 "path/to/asset", 81 Locale.ENGLISH, 82 l, 83 asset)); 84 85 replayControls(); 86 87 AssetSourceImpl as = new AssetSourceImpl(); 88 as.setContributions(contributions); 89 90 as.initializeService(); 91 92 IAsset actual = as.findAsset(r, "known:path/to/asset", Locale.ENGLISH, l); 93 94 assertSame(actual, asset); 95 96 verifyControls(); 97 } 98 99 public void testUnknownPrefix() 100 { 101 Location l = fabricateLocation(17); 102 103 Resource r = newResource(); 104 IAsset asset = newAsset(); 105 106 AssetFactory f = newAssetFactory(r, "unknown:path/to/asset", Locale.ENGLISH, l, asset); 107 108 replayControls(); 109 110 AssetSourceImpl as = new AssetSourceImpl(); 111 as.setDefaultAssetFactory(f); 112 113 IAsset actual = as.findAsset(r, "unknown:path/to/asset", Locale.ENGLISH, l); 114 115 assertSame(actual, asset); 116 117 verifyControls(); 118 } 119 120 public void testNoPrefix() 121 { 122 Location l = fabricateLocation(17); 123 124 Resource r = newResource(); 125 IAsset asset = newAsset(); 126 127 AssetFactory f = newAssetFactory(r, "path/to/asset", Locale.ENGLISH, l, asset); 128 129 replayControls(); 130 131 AssetSourceImpl as = new AssetSourceImpl(); 132 as.setLookupAssetFactory(f); 133 134 IAsset actual = as.findAsset(r, "path/to/asset", Locale.ENGLISH, l); 135 136 assertSame(actual, asset); 137 138 verifyControls(); 139 } 140 } | Popular Tags |