KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > service > impl > TestBuilderPropertyFacet


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.hivemind.service.impl;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.ServiceImplementationFactoryParameters;
19 import org.apache.hivemind.TranslatorManager;
20 import org.apache.hivemind.internal.Module;
21 import org.apache.hivemind.schema.Translator;
22 import org.apache.hivemind.test.HiveMindTestCase;
23 import org.easymock.MockControl;
24
25 public class TestBuilderPropertyFacet extends HiveMindTestCase
26 {
27     public void testCachingOfTranslatedValues() throws Exception JavaDoc
28     {
29         MockControl moduleControl = newControl(Module.class);
30         Module module = (Module) moduleControl.getMock();
31         
32         MockControl translatorControl = newControl(Translator.class);
33         Translator translator = (Translator) translatorControl.getMock();
34
35         MockControl paramsControl = newControl(ServiceImplementationFactoryParameters.class);
36         ServiceImplementationFactoryParameters params = (ServiceImplementationFactoryParameters) paramsControl
37                 .getMock();
38         
39         MockControl tmControl = newControl(TranslatorManager.class);
40         TranslatorManager tm = (TranslatorManager) tmControl.getMock();
41
42         BuilderPropertyFacet facet = new BuilderPropertyFacet();
43
44         facet.setTranslator("foo");
45         facet.setValue("bar");
46
47         params.getInvokingModule();
48         paramsControl.setDefaultReturnValue(module);
49         
50         module.getService(TranslatorManager.class);
51         moduleControl.setReturnValue(tm);
52
53         tm.getTranslator("foo");
54         tmControl.setReturnValue(translator);
55
56         translator.translate(module, Object JavaDoc.class, "bar", null);
57         translatorControl.setReturnValue("BAR");
58
59         replayControls();
60
61         facet.isAssignableToType(params, Object JavaDoc.class);
62         facet.getFacetValue(params, Object JavaDoc.class);
63
64         verifyControls();
65     }
66
67     public void testAssignableFromBadValue()
68     {
69         MockControl moduleControl = newControl(Module.class);
70         Module module = (Module) moduleControl.getMock();
71         
72         MockControl translatorControl = newControl(Translator.class);
73         Translator translator = (Translator) translatorControl.getMock();
74
75         MockControl paramsControl = newControl(ServiceImplementationFactoryParameters.class);
76         ServiceImplementationFactoryParameters params = (ServiceImplementationFactoryParameters) paramsControl
77                 .getMock();
78         
79         MockControl tmControl = newControl(TranslatorManager.class);
80         TranslatorManager tm = (TranslatorManager) tmControl.getMock();
81
82         BuilderPropertyFacet facet = new BuilderPropertyFacet();
83
84         facet.setTranslator("foo");
85         facet.setValue("bar");
86
87         params.getInvokingModule();
88         paramsControl.setDefaultReturnValue(module);
89
90         module.getService(TranslatorManager.class);
91         moduleControl.setReturnValue(tm);
92
93         tm.getTranslator("foo");
94         tmControl.setReturnValue(translator);
95
96         translator.translate(module, Object JavaDoc.class, "bar", null);
97         ApplicationRuntimeException exception = new ApplicationRuntimeException("");
98         translatorControl.setThrowable(exception);
99
100         replayControls();
101
102         try
103         {
104             facet.isAssignableToType(params, Object JavaDoc.class);
105             unreachable();
106         }
107         catch (ApplicationRuntimeException e)
108         {
109             assertSame(exception, e);
110         }
111
112         verifyControls();
113     }
114 }
115
Popular Tags