1 15 package org.apache.tapestry.engine.state; 16 17 import java.util.Collections ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.hivemind.ApplicationRuntimeException; 22 import org.apache.hivemind.ErrorLog; 23 import org.apache.hivemind.Location; 24 import org.apache.hivemind.test.HiveMindTestCase; 25 import org.easymock.MockControl; 26 27 33 public class TestSOMRegistry extends HiveMindTestCase 34 { 35 public void testInitializeAndGet() 36 { 37 Object stateObject = new Object (); 38 MockControl pmc = newControl(StateObjectPersistenceManager.class); 39 StateObjectPersistenceManager pm = (StateObjectPersistenceManager) pmc.getMock(); 40 41 StateObjectFactory f = (StateObjectFactory) newMock(StateObjectFactory.class); 42 43 pm.get("fred", f); 44 pmc.setReturnValue(stateObject); 45 46 StateObjectContribution c = new StateObjectContribution(); 47 c.setName("fred"); 48 c.setScope("wierd"); 49 c.setFactory(f); 50 51 Map applicationContributions = new HashMap (); 52 applicationContributions.put("fred", c); 53 54 Map persistenceManagers = new HashMap (); 55 persistenceManagers.put("wierd", pm); 56 57 replayControls(); 58 59 SOMRegistryImpl r = new SOMRegistryImpl(); 60 r.setApplicationContributions(applicationContributions); 61 r.setFactoryContributions(Collections.EMPTY_MAP); 62 r.setPersistenceManagers(persistenceManagers); 63 r.initializeService(); 64 65 StateObjectManager som = r.get("fred"); 66 67 assertSame(stateObject, som.get()); 68 69 verifyControls(); 70 } 71 72 public void testInitializeUnknownScope() 73 { 74 Location l = fabricateLocation(55); 75 ErrorLog log = (ErrorLog) newMock(ErrorLog.class); 76 77 StateObjectContribution c = new StateObjectContribution(); 78 c.setName("fred"); 79 c.setScope("wierd"); 80 c.setLocation(l); 81 82 Map applicationContributions = new HashMap (); 83 applicationContributions.put("fred", c); 84 85 log.error(StateMessages.unknownScope("fred", "wierd"), l, null); 86 87 replayControls(); 88 89 SOMRegistryImpl r = new SOMRegistryImpl(); 90 r.setApplicationContributions(applicationContributions); 91 r.setFactoryContributions(Collections.EMPTY_MAP); 92 r.setPersistenceManagers(Collections.EMPTY_MAP); 93 r.setErrorLog(log); 94 r.initializeService(); 95 96 verifyControls(); 97 } 98 99 public void testGetUnknownObjectName() 100 { 101 SOMRegistryImpl r = new SOMRegistryImpl(); 102 103 try 104 { 105 r.get("angel"); 106 unreachable(); 107 } 108 catch (ApplicationRuntimeException ex) 109 { 110 assertEquals(StateMessages.unknownStateObjectName("angel"), ex.getMessage()); 111 } 112 } 113 } | Popular Tags |