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.3 $ $Date: 2004/10/28 15:28:35 $
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);
61 } catch (Throwable e) {
62 e.printStackTrace();
63 }
64 assertNotNull(serviceFactory.getService(Boy.class));
65 assertNotNull(serviceFactory.getService(Kissable.class));
66 serviceFactory.unRegisterService(Boy.class.getName());
67 assertNull(serviceFactory.getService(Boy.class));
68 assertNull(serviceFactory.getService(Kissable.class));
69 }
70
71 /***
72 * Test for void invoke() with ID
73 */
74 public void testInvokeWithID() {
75
76 serviceEntryBoyWithID.setId("Boy");
77 serviceEntryBoyWithID
78 .setImplementation("org.huihoo.jfox.soaf.container.Boy");
79 serviceEntryBoyWithID.setManageable("false");
80 serviceEntryBoyWithID
81 .setInterface("org.huihoo.jfox.soaf.container.Kissable");
82 try {
83 serviceInterceptor.invoke(serviceEntryBoyWithID);
84 } catch (Throwable e) {
85 e.printStackTrace();
86 }
87 assertNotNull(serviceFactory.getService(Boy.class));
88 assertNotNull(serviceFactory.getService(Kissable.class));
89 assertNotNull(serviceFactory.getService("Boy"));
90 }
91
92 }