BindingSourceImpl implements BindingSource { public Binding newBinding(String description, ComponentResources container, String defaultPrefix, String expression) { return newBinding(description, container, container, defaultPrefix, expression, null); } BindingSourceImpl(Map<String, BindingFactory> factories, StringInterner interner); Binding newBinding(String description, ComponentResources container, String defaultPrefix, String expression); Binding newBinding(String description, ComponentResources container, ComponentResources component,
                              String defaultPrefix, String expression, Location location);  }
@Test public void expression_has_no_prefix() { BindingFactory factory = mockBindingFactory(); Binding binding = mockBinding(); ComponentResources container = mockComponentResources(); ComponentResources component = mockComponentResources(); Location l = mockLocation(); String defaultPrefix = "def"; String description = "descrip"; String expression = "full expression"; train_newBinding(factory, description, container, component, expression, l, binding); replay(); Map<String, BindingFactory> map = newMap(); map.put(defaultPrefix, factory); BindingSource source = new BindingSourceImpl(map, interner); Binding actual = source.newBinding( description, container, component, defaultPrefix, expression, l); assertSame(actual, binding); verify(); }
@Test public void expression_prefix_not_in_configuration() { BindingFactory factory = mockBindingFactory(); Binding binding = mockBinding(); ComponentResources container = mockComponentResources(); ComponentResources component = mockComponentResources(); Location l = mockLocation(); String defaultPrefix = "def"; String description = "descrip"; String expression = "javascript:not-a-known-prefix"; train_newBinding(factory, description, container, component, expression, l, binding); replay(); Map<String, BindingFactory> map = newMap(); map.put(defaultPrefix, factory); BindingSource source = new BindingSourceImpl(map, interner); Binding actual = source.newBinding( description, container, component, defaultPrefix, expression, l); assertSame(actual, binding); verify(); }
@Test public void known_prefix() { BindingFactory factory = mockBindingFactory(); Binding binding = mockBinding(); ComponentResources container = mockComponentResources(); ComponentResources component = mockComponentResources(); Location l = mockLocation(); String defaultPrefix = "literal"; String description = "descrip"; train_newBinding(factory, description, container, component, "myproperty", l, binding); replay(); Map<String, BindingFactory> map = newMap(); map.put("prop", factory); BindingSource source = new BindingSourceImpl(map, interner); Binding actual = source.newBinding( description, container, component, defaultPrefix, "prop:myproperty", l); assertSame(actual, binding); verify(); }
@Test public void factory_throws_exception() { BindingFactory factory = mockBindingFactory(); ComponentResources container = mockComponentResources(); ComponentResources component = mockComponentResources(); Location l = mockLocation(); Throwable t = new RuntimeException("Simulated failure."); String defaultPrefix = "def"; String description = "descrip"; String expression = "full expression"; factory.newBinding(description, container, component, expression, l); setThrowable(t); replay(); Map<String, BindingFactory> map = newMap(); map.put(defaultPrefix, factory); BindingSource source = new BindingSourceImpl(map, interner); try { source.newBinding(description, container, component, defaultPrefix, expression, l); unreachable(); } catch (TapestryException ex) { assertTrue(ex.getMessage().contains( "Could not convert 'full expression' into a component parameter binding")); assertTrue(ex.getMessage().contains(t.getMessage())); assertSame(ex.getLocation(), l); assertSame(ex.getCause(), t); } verify(); }