KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > translator > TestTranslatorBinding


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.form.translator;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.Location;
19 import org.apache.hivemind.lib.BeanFactory;
20 import org.apache.tapestry.IBinding;
21 import org.apache.tapestry.IComponent;
22 import org.apache.tapestry.binding.BindingTestCase;
23 import org.apache.tapestry.coerce.ValueConverter;
24 import org.easymock.MockControl;
25
26 /**
27  * Tests for {@link org.apache.tapestry.form.translator.TranslatorBinding} and
28  * {@link org.apache.tapestry.form.translator.TranslatorBindingFactory}.
29  *
30  * @author Howard Lewis Ship
31  * @since 4.0
32  */

33 public class TestTranslatorBinding extends BindingTestCase
34 {
35     public void testCreate()
36     {
37         Location l = newLocation();
38         ValueConverter vc = newValueConverter();
39         IComponent component = newComponent();
40
41         MockControl bfc = newControl(BeanFactory.class);
42         BeanFactory bf = (BeanFactory) bfc.getMock();
43
44         Translator translator = (Translator) newMock(Translator.class);
45
46         bf.get("string");
47         bfc.setReturnValue(translator);
48
49         replayControls();
50
51         TranslatorBindingFactory f = new TranslatorBindingFactory();
52         f.setValueConverter(vc);
53         f.setTranslatorBeanFactory(bf);
54
55         IBinding binding = f.createBinding(component, "description", "string", l);
56
57         assertSame(translator, binding.getObject());
58         assertSame(l, binding.getLocation());
59         assertTrue(binding.isInvariant());
60         assertEquals("description", binding.getDescription());
61
62         verifyControls();
63     }
64
65     public void testFailure()
66     {
67         Location l = newLocation();
68         IComponent component = newComponent();
69
70         MockControl bfc = newControl(BeanFactory.class);
71         BeanFactory bf = (BeanFactory) bfc.getMock();
72
73         Throwable JavaDoc t = new RuntimeException JavaDoc("Boom!");
74
75         bf.get("string");
76         bfc.setThrowable(t);
77
78         replayControls();
79
80         TranslatorBindingFactory f = new TranslatorBindingFactory();
81         f.setTranslatorBeanFactory(bf);
82
83         try
84         {
85             f.createBinding(component, "description", "string", l);
86             unreachable();
87         }
88         catch (ApplicationRuntimeException ex)
89         {
90             assertEquals("Boom!", ex.getMessage());
91             assertSame(t, ex.getRootCause());
92             assertSame(l, ex.getLocation());
93         }
94
95         verifyControls();
96
97     }
98 }
99
Popular Tags