1 /***
2 * JFoxSOAF, Service-Oriented Application Framework
3 *
4 * Copyright (C) www.huihoo.org
5 *
6 * Distributable under GNU LGPL For more information, please visit:
7 * http://www.huihoo.org/jfox/jfoxsoaf
8 */
9
10 package org.huihoo.jfox.soaf.container;
11
12 import junit.framework.TestCase;
13
14 /***
15 * JUnit test case for the
16 * {@link org.huihoo.jfox.soaf.container.ServiceContainerInceptor).
17 *
18 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
19 * @version $Revision: 1.2 $ $Date: 2004/10/18 14:22:03 $
20 * @version Revision: 1.0
21 */
22
23 public class ServiceContainerInterceptorTest extends TestCase {
24
25 private ServiceEntry serviceEntryBoyWithID = new MockServiceEntry();
26
27 private ServiceEntry serviceEntryBoyWithoutID = new MockServiceEntry();
28
29 private ServiceInterceptor serviceInterceptor = new ServiceContainerInterceptor();
30
31 private ClassLoader cl = Thread.currentThread().getContextClassLoader();
32
33 private ServiceFactory serviceFactory = ServiceFactory.getInstance();
34
35 /***
36 * @see TestCase#setUp()
37 */
38 protected void setUp() throws Exception {
39 super.setUp();
40
41 }
42
43 /***
44 * @see TestCase#tearDown()
45 */
46 protected void tearDown() throws Exception {
47 super.tearDown();
48 }
49
50 /***
51 * Test for void invoke()
52 */
53 public void testInvoke() {
54 serviceEntryBoyWithoutID
55 .setImplementation(Boy.class.getName());
56 serviceEntryBoyWithoutID.setManageable("false");
57 serviceEntryBoyWithoutID
58 .setInterface(Kissable.class.getName());
59 try {
60 serviceInterceptor.invoke(serviceEntryBoyWithoutID, Thread
61 .currentThread().getContextClassLoader());
62 } catch (Throwable e) {
63 e.printStackTrace();
64 }
65 assertNotNull(serviceFactory.getService(Boy.class));
66 assertNotNull(serviceFactory.getService(Kissable.class));
67 serviceFactory.unRegisterService(Boy.class.getName());
68 assertNull(serviceFactory.getService(Boy.class));
69 assertNull(serviceFactory.getService(Kissable.class));
70 }
71
72 /***
73 * Test for void invoke() with ID
74 */
75 public void testInvokeWithID() {
76
77 serviceEntryBoyWithID.setId("Boy");
78 serviceEntryBoyWithID
79 .setImplementation("org.huihoo.jfox.soaf.container.Boy");
80 serviceEntryBoyWithID.setManageable("false");
81 serviceEntryBoyWithID
82 .setInterface("org.huihoo.jfox.soaf.container.Kissable");
83 try {
84 serviceInterceptor.invoke(serviceEntryBoyWithID, Thread
85 .currentThread().getContextClassLoader());
86 } catch (Throwable e) {
87 e.printStackTrace();
88 }
89 assertNotNull(serviceFactory.getService(Boy.class));
90 assertNotNull(serviceFactory.getService(Kissable.class));
91 assertNotNull(serviceFactory.getService("Boy"));
92 }
93
94 }