001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Sergey A. Krivenko
020: * @version $Revision: 1.5.2.2 $
021: */package java.beans.beancontext;
022:
023: import java.util.Locale;
024:
025: import junit.framework.Test;
026: import junit.framework.TestCase;
027: import junit.framework.TestSuite;
028:
029: /**
030: * Test class for java.beans.beancontext.BeanContextServicesSupport.
031: * <p>
032: *
033: * @author Sergey A. Krivenko
034: * @version $Revision: 1.5.2.2 $
035: */
036:
037: public class BeanContextServicesSupportTest extends TestCase {
038:
039: /** STANDARD BEGINNING * */
040:
041: /**
042: * No arguments constructor to enable serialization.
043: * <p>
044: */
045: public BeanContextServicesSupportTest() {
046: super ();
047: }
048:
049: /**
050: * Constructs this test case with the given name.
051: * <p>
052: *
053: * @param name -
054: * The name for this test case.
055: * <p>
056: */
057: public BeanContextServicesSupportTest(String name) {
058: super (name);
059: }
060:
061: /** TEST CONSTRUCTORS * */
062:
063: /**
064: * Test constructor with BeanContextServices, Locale, boolean, boolean
065: * parameters.
066: * <p>
067: *
068: * @see BeanContextServicesSupport#BeanContextServicesSupport(
069: * BeanContextServices, Locale, boolean, boolean)
070: */
071: public void testConstructorBeanContextServicesLocalebooleanboolean() {
072: new BeanContextServicesSupport(null, null, true, true);
073: }
074:
075: /**
076: * Test constructor with BeanContextServices, Locale, boolean parameters
077: *
078: * @see BeanContextServicesSupport#BeanContextServicesSupport(
079: * BeanContextServices, Locale, boolean)
080: */
081: public void testConstructorBeanContextServicesLocaleboolean() {
082: new BeanContextServicesSupport(null, null, true);
083: }
084:
085: /**
086: * Test constructor with BeanContextServices, Locale parameters.
087: * <p>
088: *
089: * @see BeanContextServicesSupport#BeanContextServicesSupport(
090: * BeanContextServices, Locale)
091: */
092: public void testConstructorBeanContextServicesLocale() {
093: new BeanContextServicesSupport(null, null);
094: }
095:
096: /**
097: * Test constructor with BeanContextServices parameter.
098: * <p>
099: *
100: * @see BeanContextServicesSupport#BeanContextServicesSupport(
101: * BeanContextServices)
102: */
103: public void testConstructorBeanContextServices() {
104: new BeanContextServicesSupport(null);
105: }
106:
107: /**
108: * * Test constructor with no parameters.
109: * <p>
110: *
111: * @see BeanContextServicesSupport#BeanContextServicesSupport()
112: */
113: public void testConstructor() {
114: new BeanContextServicesSupport();
115: }
116:
117: /** TEST METHODS * */
118:
119: /**
120: * Test method createBCSChild() with Object, Object parameters.
121: * <p>
122: */
123: public void testCreateBCSChildObjectObject() {
124: // Just call the method
125: BeanContextServicesSupport sup = new BeanContextServicesSupport();
126: sup.createBCSChild(new Object(), new Object());
127: }
128:
129: /**
130: * Test method addService() with Class, BeanContextServiceProvider, boolean
131: * parameters.
132: * <p>
133: */
134: public void testAddServiceClassBeanContextServiceProviderboolean() {
135: // Instantiate services and add service
136: BeanContextServicesSupport sup = new BeanContextServicesSupport();
137: sup.addService(Object.class, getProvider(), true);
138:
139: assertEquals("One service should be registered", 1,
140: sup.services.size());
141: }
142:
143: /**
144: * Test method revokeService() with Class, BeanContextServiceProvider,
145: * boolean parameters.
146: * <p>
147: */
148: public void testRevokeServiceClassBeanContextServiceProviderboolean() {
149: // Instantiate services, add and remove service
150: BeanContextServicesSupport sup = new BeanContextServicesSupport();
151: BeanContextServiceProvider pr = getProvider();
152: sup.addService(Object.class, pr, true);
153: sup.revokeService(Object.class, pr, true);
154:
155: assertEquals("No service should be registered", 0, sup.services
156: .size());
157: }
158:
159: /**
160: * Test method addService() with Class, BeanContextServiceProvider
161: * parameters.
162: * <p>
163: */
164: public void testAddServiceClassBeanContextServiceProvider() {
165: // Instantiate services and add service
166: BeanContextServicesSupport sup = new BeanContextServicesSupport();
167: sup.addService(Object.class, getProvider());
168: }
169:
170: /**
171: * Test method hasService() with Class parameter.
172: * <p>
173: */
174: public void testHasServiceClass() {
175: // Instantiate services and add service
176: BeanContextServicesSupport sup = new BeanContextServicesSupport();
177: Class<?> cl = new Object().getClass();
178: sup.addService(cl, getProvider(), true);
179:
180: assertTrue("Service not found", sup.hasService(cl));
181: }
182:
183: /**
184: * Test method getBeanContextServicesPeer() with no parameters.
185: * <p>
186: */
187: public void testGetBeanContextServicesPeer() {
188: // Instantiate services
189: BeanContextServicesSupport sup = new BeanContextServicesSupport();
190:
191: assertTrue("The objects are not equal", sup
192: .getBeanContextServicesPeer().equals(sup));
193: }
194:
195: /**
196: * Test method releaseBeanContextResources() with no parameters.
197: * <p>
198: */
199: public void testReleaseBeanContextResources() {
200: // Instantiate services
201: BeanContextServicesSupport sup = new BeanContextServicesSupport();
202: sup.releaseBeanContextResources();
203:
204: assertNull("The resources are not released", sup.proxy);
205: }
206:
207: /**
208: * Test method initializeBeanContextResources() with no parameters.
209: * <p>
210: */
211: public void testInitializeBeanContextResources() {
212: // Instantiate services
213: BeanContextServicesSupport sup = new BeanContextServicesSupport();
214: sup.initializeBeanContextResources();
215:
216: // if (sup.proxy == null) {
217: // fail("The resources are not initialized");
218: // }
219: }
220:
221: /**
222: * Test method hasService() with Class=null parameter.
223: * <p>
224: */
225: public void test_hasServiceLjava_lang_Class() {
226: BeanContextServicesSupport obj = new BeanContextServicesSupport();
227: try {
228: obj.hasService(null);
229: fail("NullPointerException expected");
230: } catch (NullPointerException t) {
231: }
232: }
233:
234: /**
235: * Test method removeBeanContextServicesListener() with
236: * BeanContextServicesListener=null parameter.
237: * <p>
238: */
239: public void test_removeBeanContextServicesListenerLjava_beans_beancontext_BeanContextServicesListener() {
240: BeanContextServicesSupport obj = new BeanContextServicesSupport();
241: try {
242: obj.removeBeanContextServicesListener(null);
243: fail("NullPointerException expected");
244: } catch (NullPointerException t) {
245: }
246: }
247:
248: /**
249: * Test method serviceAvailable() with BeanContextServiceAvailableEvent=null
250: * parameter.
251: * <p>
252: */
253: public void test_serviceAvailableLjava_beans_beancontext_BeanContextServiceAvailableEvent() {
254: BeanContextServicesSupport obj = new BeanContextServicesSupport();
255: try {
256: obj.serviceAvailable(null);
257: fail("NullPointerException expected");
258: } catch (NullPointerException t) {
259: }
260: }
261:
262: /**
263: * Test method serviceRevoked() with BeanContextServiceRevokedEvent=null
264: * parameter.
265: * <p>
266: */
267: public void test_serviceRevokedLjava_beans_beancontext_BeanContextServiceRevokedEvent() {
268: BeanContextServicesSupport obj = new BeanContextServicesSupport();
269: try {
270: obj.serviceRevoked(null);
271: fail("NullPointerException expected");
272: } catch (NullPointerException t) {
273: }
274: }
275:
276: /** UTILITY METHODS * */
277:
278: /**
279: * Fake implementation of provider
280: */
281: @SuppressWarnings("unchecked")
282: private BeanContextServiceProvider getProvider() {
283:
284: return new BeanContextServiceProvider() {
285:
286: public java.util.Iterator getCurrentServiceSelectors(
287: BeanContextServices bcs, Class serviceClass) {
288:
289: return bcs.getCurrentServiceSelectors(serviceClass);
290: }
291:
292: public Object getService(BeanContextServices bcs,
293: Object requestor, Class serviceClass,
294: Object serviceSelector) {
295:
296: return null;
297: }
298:
299: public void releaseService(BeanContextServices bcs,
300: Object requestor, Object service) {
301: }
302: };
303: }
304:
305: /** STANDARD ENDING * */
306:
307: /**
308: * Start testing from the command line.
309: * <p>
310: */
311: public static Test suite() {
312: return new TestSuite(BeanContextServicesSupportTest.class);
313: }
314:
315: /**
316: * Start testing from the command line.
317: * <p>
318: *
319: * @param args -
320: * Command line parameters.
321: * <p>
322: */
323: public static void main(String args[]) {
324: junit.textui.TestRunner.run(suite());
325: }
326: }
|