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.MBeanServerInceptor).
17   * 
18   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
19   * @version $Revision: 1.3 $ $Date: 2004/10/28 15:29:10 $
20   * @version Revision: 1.0
21   */
22  
23  public class MBeanServerInterceptorTest extends TestCase {
24  
25      private ManageableServiceContainer mServiceContainer = ManageableServiceContainer
26              .getInstance();
27  
28      private ServiceInterceptor serviceInterceptor = new MBeanServerInterceptor();
29  
30      private ClassLoader cl = Thread.currentThread().getContextClassLoader();
31  
32      private ServiceEntry simpleStandardWithID = new MockServiceEntry();
33  
34      private ServiceEntry simpleStandardWithoutID = new MockServiceEntry();
35  
36      private ServiceFactory serviceFactory = ServiceFactory.getInstance();
37  
38      /***
39       * @see TestCase#setUp()
40       */
41      protected void setUp() throws Exception {
42          super.setUp();
43          simpleStandardWithoutID
44                  .setImplementation("org.huihoo.jfox.soaf.container.SimpleStandard");
45          simpleStandardWithoutID.setManageable("true");
46  
47          simpleStandardWithID.setId("SimpleStandard");
48          simpleStandardWithID
49                  .setImplementation("org.huihoo.jfox.soaf.container.SimpleStandard");
50          simpleStandardWithID.setManageable("true");
51      }
52  
53      /***
54       * @see TestCase#tearDown()
55       */
56      protected void tearDown() throws Exception {
57          super.tearDown();
58      }
59  
60      public void testInvokeWihoutID() {
61  
62          try {
63              serviceInterceptor.invoke(simpleStandardWithoutID);
64              mServiceContainer.getMBeanServer().invoke(
65                      mServiceContainer.objectName(simpleStandardWithoutID),
66                      "reset", null, null);
67          } catch (Throwable e1) {
68              e1.printStackTrace();
69          }
70  
71          assertNotNull(serviceFactory.getService(SimpleStandardMBean.class));
72          assertNotNull(serviceFactory.getService(SimpleStandard.class));
73      }
74  
75  //    public void testInvoke() {
76  //        try {
77  //            serviceInterceptor.invoke(simpleStandardWithID, cl);
78  //            mServiceContainer.getMBeanServer().invoke(
79  //                    mServiceContainer.objectName(simpleStandardWithID),
80  //                    "reset", null, null);
81  //        } catch (Throwable e1) {
82  //            e1.printStackTrace();
83  //        }
84  //
85  //        //assertNotNull(serviceFactory.getService("SimpleStandard"));
86  //        //assertNotNull(serviceFactory.getService(SimpleStandard.class));
87  //    }
88  
89  }