KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright 2004, 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 java.util.Locale JavaDoc;
18
19 import org.apache.hivemind.test.HiveMindTestCase;
20 import org.apache.tapestry.IEngine;
21 import org.apache.tapestry.services.EngineFactory;
22 import org.apache.tapestry.services.ObjectPool;
23 import org.apache.tapestry.services.RequestLocaleManager;
24 import org.easymock.MockControl;
25
26 /**
27  * Tests for {@link org.apache.tapestry.services.impl.EngineManagerImpl}.
28  *
29  * @author Howard Lewis Ship
30  * @since 4.0
31  */

32 public class TestEngineManager extends HiveMindTestCase
33 {
34
35     public void testGetFromPool()
36     {
37
38         MockControl extractorControl = newControl(RequestLocaleManager.class);
39         RequestLocaleManager extractor = (RequestLocaleManager) extractorControl.getMock();
40
41         MockControl poolControl = newControl(ObjectPool.class);
42         ObjectPool pool = (ObjectPool) poolControl.getMock();
43
44         // Training
45

46         extractor.extractLocaleForCurrentRequest();
47         extractorControl.setReturnValue(Locale.CHINESE);
48
49         IEngine engine = (IEngine) newMock(IEngine.class);
50
51         pool.get(Locale.CHINESE);
52         poolControl.setReturnValue(engine);
53
54         replayControls();
55
56         EngineManagerImpl m = new EngineManagerImpl();
57
58         m.setEnginePool(pool);
59         m.setLocaleManager(extractor);
60
61         IEngine actual = m.getEngineInstance();
62
63         assertSame(engine, actual);
64
65         verifyControls();
66     }
67
68     public void testGetNotInPool()
69     {
70
71         MockControl extractorControl = newControl(RequestLocaleManager.class);
72         RequestLocaleManager extractor = (RequestLocaleManager) extractorControl.getMock();
73
74         MockControl poolControl = newControl(ObjectPool.class);
75         ObjectPool pool = (ObjectPool) poolControl.getMock();
76
77         // Training
78

79         extractor.extractLocaleForCurrentRequest();
80         extractorControl.setReturnValue(Locale.CHINESE);
81
82         IEngine engine = (IEngine) newMock(IEngine.class);
83
84         pool.get(Locale.CHINESE);
85         poolControl.setReturnValue(null);
86
87         MockControl factoryControl = newControl(EngineFactory.class);
88         EngineFactory factory = (EngineFactory) factoryControl.getMock();
89
90         factory.constructNewEngineInstance(Locale.CHINESE);
91         factoryControl.setReturnValue(engine);
92
93         replayControls();
94
95         EngineManagerImpl m = new EngineManagerImpl();
96
97         m.setEnginePool(pool);
98         m.setLocaleManager(extractor);
99         m.setEngineFactory(factory);
100
101         IEngine actual = m.getEngineInstance();
102
103         assertSame(engine, actual);
104
105         verifyControls();
106     }
107
108     public void testStoreNoSession()
109     {
110
111         MockControl engineControl = newControl(IEngine.class);
112         IEngine engine = (IEngine) engineControl.getMock();
113
114         ObjectPool pool = (ObjectPool) newMock(ObjectPool.class);
115
116         // Training
117

118         engine.getLocale();
119         engineControl.setReturnValue(Locale.KOREAN);
120
121         pool.store(Locale.KOREAN, engine);
122
123         replayControls();
124
125         EngineManagerImpl m = new EngineManagerImpl();
126
127         m.setEnginePool(pool);
128
129         m.storeEngineInstance(engine);
130
131         verifyControls();
132     }
133
134 }
Popular Tags