KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > state > TestSOMRegistry


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.engine.state;
16
17 import java.util.Collections JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
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 /**
28  * Tests {@link TestSOMRegistry}.
29  *
30  * @author Howard M. Lewis Ship
31  * @since 4.0
32  */

33 public class TestSOMRegistry extends HiveMindTestCase
34 {
35     public void testInitializeAndGet()
36     {
37         Object JavaDoc stateObject = new Object JavaDoc();
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 JavaDoc applicationContributions = new HashMap JavaDoc();
52         applicationContributions.put("fred", c);
53
54         Map JavaDoc persistenceManagers = new HashMap JavaDoc();
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 JavaDoc applicationContributions = new HashMap JavaDoc();
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