KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > service > TestBuilderFactoryServiceModel


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.hivemind.service;
16
17 import hivemind.test.services.StringHolder;
18
19 import org.apache.hivemind.HiveMind;
20 import org.apache.hivemind.Registry;
21 import org.apache.hivemind.service.impl.BuilderFactory;
22 import org.apache.hivemind.xml.XmlTestCase;
23
24 /**
25  * Tests {@link org.apache.hivemind.impl.servicemodel.PooledServiceModel} integrated with {@link BuilderFactory}.
26  *
27  * @author Howard Lewis Ship
28  */

29 public class TestBuilderFactoryServiceModel extends XmlTestCase
30 {
31
32     /**
33      * Tests basic interaction of pooling with thread cleanup.
34      */

35     public void testManaged() throws Exception JavaDoc
36     {
37         Registry r = buildFrameworkRegistry("Pooled.xml");
38
39         StringHolder s =
40             (StringHolder) r.getService("hivemind.test.services.Managed", StringHolder.class);
41
42         interceptLogging("hivemind.test.services.Managed");
43
44         assertNull(s.getValue());
45
46         assertLoggedMessage("activateService()");
47
48         s.setValue("funky monkey");
49         assertEquals("funky monkey", s.getValue());
50
51         ThreadEventNotifier n =
52             (ThreadEventNotifier) r.getService(
53                 HiveMind.THREAD_EVENT_NOTIFIER_SERVICE,
54                 ThreadEventNotifier.class);
55
56         n.fireThreadCleanup();
57
58         assertLoggedMessage("passivateService()");
59
60         assertNull(s.getValue());
61     }
62
63 }
64
Popular Tags