01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.bindings;
16:
17: import org.apache.tapestry.Binding;
18: import org.apache.tapestry.ComponentResources;
19: import org.apache.tapestry.Translator;
20: import org.apache.tapestry.internal.test.InternalBaseTestCase;
21: import org.apache.tapestry.ioc.Location;
22: import org.apache.tapestry.ioc.internal.util.InternalUtils;
23: import org.apache.tapestry.ioc.internal.util.TapestryException;
24: import org.apache.tapestry.services.BindingFactory;
25: import org.apache.tapestry.services.TranslatorSource;
26: import org.testng.annotations.Test;
27:
28: /**
29: * Tests for several of the simpler binding factories.
30: */
31: public class BindingFactoryTest extends InternalBaseTestCase {
32:
33: @Test
34: public void literal_binding() {
35: ComponentResources res = mockInternalComponentResources();
36: Location l = mockLocation();
37:
38: replay();
39:
40: BindingFactory factory = new LiteralBindingFactory();
41:
42: Binding b = factory.newBinding("test binding", res, null,
43: "Tapestry5", l);
44:
45: assertSame(InternalUtils.locationOf(b), l);
46:
47: assertEquals(b.get(), "Tapestry5");
48: assertTrue(b.isInvariant());
49: assertSame(b.getBindingType(), String.class);
50:
51: try {
52: b.set(null);
53: unreachable();
54: } catch (TapestryException ex) {
55: assertSame(ex.getLocation(), l);
56: }
57:
58: verify();
59: }
60:
61: @Test
62: public void translate_binding() {
63: Translator translator = mockTranslator();
64: TranslatorSource source = newMock(TranslatorSource.class);
65: ComponentResources resources = mockComponentResources();
66: Location l = mockLocation();
67:
68: String description = "foo bar";
69: String expression = "mock";
70:
71: expect(source.get(expression)).andReturn(translator);
72:
73: replay();
74:
75: BindingFactory factory = new TranslateBindingFactory(source);
76:
77: Binding binding = factory.newBinding(description, resources,
78: resources, expression, l);
79:
80: assertSame(binding.get(), translator);
81:
82: assertSame(InternalUtils.locationOf(binding), l);
83:
84: verify();
85: }
86: }
|