1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.Locale ; 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 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 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 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 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 |