1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.Collections ; 18 19 import org.apache.hivemind.Location; 20 import org.apache.hivemind.test.HiveMindTestCase; 21 import org.apache.tapestry.IBinding; 22 import org.apache.tapestry.IComponent; 23 import org.apache.tapestry.binding.BindingConstants; 24 import org.apache.tapestry.binding.BindingFactory; 25 import org.easymock.MockControl; 26 27 33 public class TestBindingSource extends HiveMindTestCase 34 { 35 public void testNoPrefix() 36 { 37 IComponent component = (IComponent) newMock(IComponent.class); 38 IBinding binding = (IBinding) newMock(IBinding.class); 39 40 MockControl factoryControl = newControl(BindingFactory.class); 41 BindingFactory factory = (BindingFactory) factoryControl.getMock(); 42 43 Location l = fabricateLocation(99); 44 45 47 factory.createBinding(component, "foo", "a literal value without a prefix", l); 48 factoryControl.setReturnValue(binding); 49 50 replayControls(); 51 52 BindingSourceImpl bs = new BindingSourceImpl(); 53 bs.setLiteralBindingFactory(factory); 54 55 IBinding actual = bs.createBinding( 56 component, 57 "foo", 58 "a literal value without a prefix", 59 BindingConstants.LITERAL_PREFIX, 60 l); 61 62 assertSame(binding, actual); 63 64 verifyControls(); 65 } 66 67 public void testNoPrefixWithDefault() 68 { 69 IComponent component = (IComponent) newMock(IComponent.class); 70 IBinding binding = (IBinding) newMock(IBinding.class); 71 72 MockControl factoryControl = newControl(BindingFactory.class); 73 BindingFactory factory = (BindingFactory) factoryControl.getMock(); 74 75 Location l = fabricateLocation(99); 76 77 79 factory.createBinding(component, "foo", "an-expression", l); 80 factoryControl.setReturnValue(binding); 81 82 BindingPrefixContribution c = new BindingPrefixContribution(); 83 c.setPrefix(BindingConstants.OGNL_PREFIX); 84 c.setFactory(factory); 85 86 replayControls(); 87 88 BindingSourceImpl bs = new BindingSourceImpl(); 89 bs.setContributions(Collections.singletonList(c)); 90 bs.initializeService(); 91 92 IBinding actual = bs.createBinding( 93 component, 94 "foo", 95 "an-expression", 96 BindingConstants.OGNL_PREFIX, 97 l); 98 99 assertSame(binding, actual); 100 101 verifyControls(); 102 } 103 104 public void testKnownPrefix() 105 { 106 IComponent component = (IComponent) newMock(IComponent.class); 107 IBinding binding = (IBinding) newMock(IBinding.class); 108 109 MockControl factoryControl = newControl(BindingFactory.class); 110 BindingFactory factory = (BindingFactory) factoryControl.getMock(); 111 112 Location l = fabricateLocation(99); 113 114 116 factory.createBinding(component, "bar", "path part of locator", l); 117 factoryControl.setReturnValue(binding); 118 119 BindingPrefixContribution c = new BindingPrefixContribution(); 120 c.setPrefix("prefix"); 121 c.setFactory(factory); 122 123 replayControls(); 124 125 BindingSourceImpl bs = new BindingSourceImpl(); 126 bs.setContributions(Collections.singletonList(c)); 127 128 bs.initializeService(); 129 130 IBinding actual = bs.createBinding( 131 component, 132 "bar", 133 "prefix:path part of locator", 134 BindingConstants.LITERAL_PREFIX, 135 l); 136 137 assertSame(binding, actual); 138 139 verifyControls(); 140 } 141 142 public void testPrefixNoMatch() 143 { 144 IComponent component = (IComponent) newMock(IComponent.class); 145 IBinding binding = (IBinding) newMock(IBinding.class); 146 147 MockControl factoryControl = newControl(BindingFactory.class); 148 BindingFactory literalFactory = (BindingFactory) factoryControl.getMock(); 149 150 BindingFactory factory = (BindingFactory) newMock(BindingFactory.class); 151 152 Location l = fabricateLocation(99); 153 154 156 literalFactory.createBinding(component, "zip", "unknown:path part of locator", l); 157 factoryControl.setReturnValue(binding); 158 159 BindingPrefixContribution c = new BindingPrefixContribution(); 160 c.setPrefix("prefix"); 161 c.setFactory(factory); 162 163 replayControls(); 164 165 BindingSourceImpl bs = new BindingSourceImpl(); 166 bs.setContributions(Collections.singletonList(c)); 167 bs.setLiteralBindingFactory(literalFactory); 168 169 bs.initializeService(); 170 171 IBinding actual = bs.createBinding( 172 component, 173 "zip", 174 "unknown:path part of locator", 175 BindingConstants.LITERAL_PREFIX, 176 l); 177 178 assertSame(binding, actual); 179 180 verifyControls(); 181 } 182 } | Popular Tags |