01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.ioc.internal.services;
16:
17: import org.apache.tapestry.ioc.ObjectCreator;
18: import org.apache.tapestry.ioc.internal.IOCInternalTestCase;
19: import org.testng.annotations.Test;
20:
21: public class JustInTimeObjectCreatorTest extends IOCInternalTestCase {
22: private static final String SERVICE_ID = "FooBar";
23:
24: @Test
25: public void create_after_shutdown() {
26: ObjectCreator creator = mockObjectCreator();
27:
28: replay();
29:
30: JustInTimeObjectCreator j = new JustInTimeObjectCreator(
31: creator, SERVICE_ID);
32:
33: j.registryDidShutdown();
34:
35: try {
36: j.createObject();
37: unreachable();
38: } catch (IllegalStateException ex) {
39: assertEquals(
40: ex.getMessage(),
41: "Proxy for service FooBar is no longer active because the IOC Registry has been shut down.");
42: }
43: }
44:
45: @Test
46: public void eager_load() {
47: ObjectCreator creator = mockObjectCreator();
48: Object service = new Object();
49:
50: replay();
51:
52: JustInTimeObjectCreator j = new JustInTimeObjectCreator(
53: creator, SERVICE_ID);
54:
55: verify();
56:
57: // First access: use the creator to get the actual object.
58:
59: train_createObject(creator, service);
60:
61: replay();
62:
63: j.eagerLoadService();
64:
65: verify();
66:
67: // This part tests the caching part.
68:
69: replay();
70:
71: assertSame(j.createObject(), service);
72:
73: verify();
74: }
75: }
|