KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > service > impl > TestBuilderFactory


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.impl;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.hivemind.ApplicationRuntimeException;
19 import org.apache.hivemind.ErrorLog;
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.Registry;
22 import org.apache.hivemind.ServiceImplementationFactoryParameters;
23 import org.apache.hivemind.internal.Module;
24 import org.apache.hivemind.test.AggregateArgumentsMatcher;
25 import org.apache.hivemind.test.ArgumentMatcher;
26 import org.apache.hivemind.test.TypeMatcher;
27 import org.apache.hivemind.xml.XmlTestCase;
28 import org.easymock.MockControl;
29
30 /**
31  * Additional tests for {@link org.apache.hivemind.service.impl.BuilderFactoryLogic}.
32  *
33  * @author Howard M. Lewis Ship
34  * @since 1.1
35  */

36 public class TestBuilderFactory extends XmlTestCase
37 {
38     /**
39      * Tests for errors when actually invoking the initializer method (as opposed to an error
40      * finding the method).
41      *
42      * @since 1.1
43      */

44     public void testErrorInInitializer() throws Exception JavaDoc
45     {
46         Location l = newLocation();
47
48         MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
49         ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
50                 .getMock();
51
52         Log log = (Log) newMock(Log.class);
53
54         MockControl mc = newControl(Module.class);
55         Module module = (Module) mc.getMock();
56
57         MockControl errorLogc = newControl(ErrorLog.class);
58         ErrorLog errorLog = (ErrorLog) errorLogc.getMock();
59
60         fp.getLog();
61         fpc.setReturnValue(log);
62
63         fp.getServiceId();
64         fpc.setReturnValue("foo.Bar");
65
66         fp.getInvokingModule();
67         fpc.setReturnValue(module);
68
69         module.resolveType("org.apache.hivemind.service.impl.InitializerErrorRunnable");
70         mc.setReturnValue(InitializerErrorRunnable.class);
71
72         fp.getErrorLog();
73         fpc.setReturnValue(errorLog);
74
75         Throwable JavaDoc cause = new ApplicationRuntimeException("Failure in initializeService().");
76
77         String JavaDoc message = ServiceMessages.unableToInitializeService(
78                 "foo.Bar",
79                 "initializeService",
80                 InitializerErrorRunnable.class,
81                 cause);
82
83         errorLog.error(message, l, new ApplicationRuntimeException(""));
84         errorLogc.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[]
85         { null, null, new TypeMatcher() }));
86
87         BuilderParameter p = new BuilderParameter();
88         p.setClassName(InitializerErrorRunnable.class.getName());
89         p.setLocation(l);
90
91         replayControls();
92
93         BuilderFactoryLogic logic = new BuilderFactoryLogic(fp, p);
94
95         assertNotNull(logic.createService());
96
97         verifyControls();
98     }
99     
100     public void testListPropertyAutowire() throws Exception JavaDoc
101     {
102         final Registry reg = buildFrameworkRegistry( "ListProperty.xml" );
103         ListPropertyBean bean = ( ListPropertyBean )reg.getService( ListPropertyBean.class );
104         assertNull( bean.getList() );
105         
106     }
107 }
Popular Tags