KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > TestDeferredObjectTranslator


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.services.impl;
16
17 import org.apache.hivemind.Location;
18 import org.apache.hivemind.internal.Module;
19 import org.apache.hivemind.schema.Translator;
20 import org.apache.hivemind.test.HiveMindTestCase;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.services.impl.DeferredObjectImpl} and
25  * {@link org.apache.tapestry.services.impl.DeferredObjectTranslator}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class TestDeferredObjectTranslator extends HiveMindTestCase
31 {
32     private Module newModule()
33     {
34         return (Module) newMock(Module.class);
35     }
36
37     private Translator newTranslator(Module module, String JavaDoc objectReference, Location location,
38             Object JavaDoc result)
39     {
40         MockControl control = newControl(Translator.class);
41         Translator translator = (Translator) control.getMock();
42
43         translator.translate(module, Object JavaDoc.class, objectReference, location);
44         control.setReturnValue(result);
45
46         return translator;
47     }
48
49     public void testDeferredObject()
50     {
51         Object JavaDoc object = new Object JavaDoc();
52         Module module = newModule();
53         Location l = newLocation();
54         Translator translator = newTranslator(module, "OBJ-REFERENCE", l, object);
55
56         replayControls();
57
58         DeferredObject deferred = new DeferredObjectImpl(translator, module, "OBJ-REFERENCE", l);
59
60         assertSame(object, deferred.getObject());
61
62         // Check that a second call returns a cached value.
63

64         assertSame(object, deferred.getObject());
65
66         verifyControls();
67
68         assertSame(l, deferred.getLocation());
69     }
70
71     public void testDeferredObjectTranslator()
72     {
73         Object JavaDoc object = new Object JavaDoc();
74         Module module = newModule();
75         Location l = newLocation();
76         Translator objectTranslator = newTranslator(module, "OBJ-REFERENCE", l, object);
77
78         replayControls();
79
80         DeferredObjectTranslator translator = new DeferredObjectTranslator();
81         translator.setObjectTranslator(objectTranslator);
82
83         DeferredObject deferred = (DeferredObject) translator.translate(
84                 module,
85                 Object JavaDoc.class,
86                 "OBJ-REFERENCE",
87                 l);
88
89         assertSame(object, deferred.getObject());
90
91         // Check that a second call returns a cached value.
92

93         assertSame(object, deferred.getObject());
94
95         verifyControls();
96
97         assertSame(l, deferred.getLocation());
98     }
99 }
Popular Tags