KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > lib > TestSpringObjectProvider


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 hivemind.test.lib;
16
17 import org.apache.hivemind.Registry;
18 import org.apache.hivemind.lib.SpringBeanFactoryHolder;
19 import org.apache.hivemind.lib.impl.SpringObjectProvider;
20 import org.apache.hivemind.xml.XmlTestCase;
21 import org.easymock.MockControl;
22 import org.springframework.beans.factory.BeanFactory;
23 import org.springframework.beans.factory.xml.XmlBeanFactory;
24 import org.springframework.core.io.ClassPathResource;
25
26 /**
27  * @author Howard M. Lewis Ship
28  * @since 1.1
29  */

30 public class TestSpringObjectProvider extends XmlTestCase
31 {
32     public void testBasic()
33     {
34         Object JavaDoc bean = new Object JavaDoc();
35         MockControl control = newControl(BeanFactory.class);
36         BeanFactory bf = (BeanFactory) control.getMock();
37
38         bf.getBean("fred");
39         control.setReturnValue(bean);
40
41         replayControls();
42
43         SpringObjectProvider p = new SpringObjectProvider();
44         p.setBeanFactory(bf);
45
46         Object JavaDoc result = p.provideObject(null, null, "fred", null);
47
48         assertSame(bean, result);
49
50         verifyControls();
51     }
52
53     public void testSpringIntegration() throws Exception JavaDoc
54     {
55         // Spring setup
56

57         ClassPathResource springBeansResource = new ClassPathResource("SpringBeans.xml",
58                 TestSpringLookupFactory.class);
59
60         BeanFactory beanFactory = new XmlBeanFactory(springBeansResource);
61
62         Registry r = buildFrameworkRegistry("SpringProvider.xml");
63
64         SpringBeanFactoryHolder h = (SpringBeanFactoryHolder) r.getService(
65                 "hivemind.lib.DefaultSpringBeanFactoryHolder",
66                 SpringBeanFactoryHolder.class);
67
68         h.setBeanFactory(beanFactory);
69
70         SimpleService a = (SimpleService) r.getService(
71                 "hivemind.test.lib.Adder",
72                 SimpleService.class);
73
74         assertEquals(17, a.add(9, 8));
75     }
76 }
Popular Tags