You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2003/08/30 22:19:03 UTC
cvs commit: incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/jmx MBeanProxyFactoryTest.java
jdillon 2003/08/30 13:19:03
Modified: modules/common/src/java/org/apache/geronimo/common/jmx
MBeanProxyHandler.java
Added: modules/common/src/java/org/apache/geronimo/common/jmx
MBeanProxyException.java
modules/common/src/test/org/apache/geronimo/common/jmx
MBeanProxyFactoryTest.java
Log:
o Throw MBeanProxyException if we can not handle decoding
o Actually including the tests ;-)
Revision Changes Path
1.2 +7 -3 incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyHandler.java
Index: MBeanProxyHandler.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MBeanProxyHandler.java 30 Aug 2003 20:12:23 -0000 1.1
+++ MBeanProxyHandler.java 30 Aug 2003 20:19:03 -0000 1.2
@@ -89,6 +89,10 @@
protected Map attributeMap;
protected Map taskCache;
+ //
+ // TODO: Replace cache map with a backing which will not eat memory
+ //
+
public MBeanProxyHandler(final MBeanServer server,
final ObjectName target)
{
@@ -141,8 +145,8 @@
}
}
- // Else we don't have much choice, so just toss the original
- throw t;
+ // Else we don't have much choice, so...
+ throw new MBeanProxyException(t);
}
}
1.1 incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyException.java
Index: MBeanProxyException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.common.jmx;
/**
* Thrown to indicate a problem with an MBean proxy.
*
* @version $Revision: 1.1 $ $Date: 2003/08/30 20:19:03 $
*/
public class MBeanProxyException
extends RuntimeException
{
public MBeanProxyException()
{
super();
}
public MBeanProxyException(String msg)
{
super(msg);
}
public MBeanProxyException(Throwable t)
{
super(t);
}
public MBeanProxyException(String msg, Throwable t)
{
super(msg, t);
}
}
1.1 incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/jmx/MBeanProxyFactoryTest.java
Index: MBeanProxyFactoryTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.common.jmx;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import junit.framework.TestCase;
/**
* Unit test for {@link MBeanProxyFactory} class.
*
* @version $Revision: 1.1 $ $Date: 2003/08/30 20:19:03 $
*/
public class MBeanProxyFactoryTest
extends TestCase
{
protected MBeanServer server;
protected ObjectName target;
protected MockObject targetObject;
protected void setUp() throws Exception
{
server = MBeanServerFactory.createMBeanServer("geronimo.test");
target = new ObjectName("geronimo.test:bean=test");
targetObject = new MockObject();
server.registerMBean(targetObject, target);
}
protected void tearDown() throws Exception
{
MBeanServerFactory.releaseMBeanServer(server);
server = null;
}
public void testCreate() throws Exception
{
MockObjectMBean bean = (MockObjectMBean)
MBeanProxyFactory.create(MockObjectMBean.class, server, target);
assertNotNull(bean);
}
public void testGetString() throws Exception
{
MockObjectMBean bean = (MockObjectMBean)
MBeanProxyFactory.create(MockObjectMBean.class, server, target);
assertNotNull(bean);
String value = bean.getString();
assertEquals(targetObject.getString(), value);
}
public void testSetString() throws Exception
{
MockObjectMBean bean = (MockObjectMBean)
MBeanProxyFactory.create(MockObjectMBean.class, server, target);
assertNotNull(bean);
String value = "newvalue";
bean.setString(value);
assertEquals(value, targetObject.getString());
}
public void testOperation_Simple() throws Exception
{
MockObjectMBean bean = (MockObjectMBean)
MBeanProxyFactory.create(MockObjectMBean.class, server, target);
assertNotNull(bean);
String value = bean.doIt();
assertEquals(targetObject.doIt(), value);
}
public void testOperation_PoorlyNamed() throws Exception
{
MockObjectMBean bean = (MockObjectMBean)
MBeanProxyFactory.create(MockObjectMBean.class, server, target);
assertNotNull(bean);
String value = bean.setPoorlyNameOperation();
assertEquals(targetObject.setPoorlyNameOperation(), value);
}
public void testMBeanProxy() throws Exception
{
MockObjectMBean bean = (MockObjectMBean)
MBeanProxyFactory.create(MockObjectMBean.class, server, target);
assertNotNull(bean);
assertTrue(bean instanceof MBeanProxyFactory.MBeanProxy);
MBeanProxyFactory.MBeanProxy ctx = (MBeanProxyFactory.MBeanProxy)bean;
assertNotNull(ctx.getMBeanProxyObjectName());
assertEquals(target, ctx.getMBeanProxyObjectName());
assertNotNull(ctx.getMBeanProxyMBeanServer());
}
//
// Mock MBean
//
public static interface MockObjectMBean
{
String getString();
boolean isSomething();
void setString(String value);
String doIt();
String setPoorlyNameOperation();
}
public static class MockObject
implements MockObjectMBean
{
String string = "MyString";
boolean something;
public void setString(String value)
{
this.string = value;
}
public String getString()
{
return string;
}
public void setSomething(boolean flag)
{
something = flag;
}
public boolean isSomething()
{
return something;
}
public String doIt()
{
return "done";
}
public String setPoorlyNameOperation()
{
return "bad";
}
}
}