/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

// $Id: WSRJMXAccessUnitTestCase.java,v 1.1.2.1 2003/09/29 23:46:50 starksm Exp $

package org.jboss.test.webservice.jmx;

import org.jboss.net.axis.AxisInvocationHandler;
import org.jboss.net.jmx.MBeanInvocationHandler;
import org.jboss.net.jmx.adaptor.RemoteAdaptor;
import org.jboss.net.jmx.adaptor.RemoteAdaptorInvocationHandler;
import org.jboss.net.jmx.MBeanInvocationHandler;
import org.jboss.test.webservice.AxisTestCase;

import junit.framework.Test;
import junit.framework.TestSuite;
import javax.management.ObjectName;

import java.net.URL;

/**
 * Tests remote accessibility of JMX MBean through the web service
 * @created 29 March
 * @author <a href="mailto:pbraswell@utopiansoft.com">Peter Braswell</a>
 * @version $Revision: 1.1.2.1 $
 */

public class WSRJMXAccessUnitTestCase extends AxisTestCase
{

   /**
    * Method setUp
    *
    *
    * @throws Exception
    *
    */

   public void setUp() throws Exception
   {

      super.setUp();

   }

   public void testGetter() throws Exception
   {
      MBeanInvocationHandler handler =
         createMBeanInvocationHandler(new URL(JMX_END_POINT));
      String str = (String) handler.invoke("JMXTest", // serviceName
         "getTestString", // methodName
         null, // arguments
         null); // classes           
      assertEquals(str, "JMX_TEST_STRING");
   }

   public void testSetter() throws Exception
   {
      MBeanInvocationHandler handler =
         createMBeanInvocationHandler(new URL(JMX_END_POINT));
      handler.invoke("JMXTest", // serviceName
         "setTestString", // methodName
         new String[]{"foo-dog"}, // arguments
         new Class[]{String.class}); // classes           
      // invoke the getter and compare the answer with the 
      // set string value
      String str = (String) handler.invoke("JMXTest", // serviceName
         "getTestString", // methodName
         null, // arguments
         null); // classes           
      assertEquals(str, "foo-dog");
   }

   public void testMethodInvoke() throws Exception
   {
      MBeanInvocationHandler handler =
         createMBeanInvocationHandler(new URL(JMX_END_POINT));
      handler.invoke("jboss.net:service=JMXTestMBean", // serviceName
         "noopOperation", // methodName
         null, // arguments
         null); // classes           
   }

   /**
    * Constructor WSRJMXAccessUnitTestCase
    *
    *
    * @param name
    *
    */

   public WSRJMXAccessUnitTestCase(String name)
   {
      super(name);
   }

   /**
    * Method suite
    *
    *
    * @return
    *
    * @throws Exception
    *
    */

   public static Test suite() throws Exception
   {
      return getDeploySetup(WSRJMXAccessUnitTestCase.class, "jmx-test.sar");
   }

   /* Member variables */

   protected String JMX_END_POINT = END_POINT + "/JMXTest";
   protected static String AXIS_JMX_NAME = "jboss.net:service=Axis";
   private JMXTestMBean mbean;

}