jlaskowski 2004/02/24 10:41:45
Modified: modules/kernel/src/java/org/apache/geronimo/gbean
GBeanInfo.java GBeanInfoFactory.java
modules/kernel/src/java/org/apache/geronimo/gbean/jmx
GBeanMBean.java
modules/kernel/src/java/org/apache/geronimo/kernel/config
Configuration.java
Added: modules/kernel/src/test/org/apache/geronimo/gbean
GBeanInfoFactoryTest.java GBeanInfoTest.java
Log:
o Change Set for operations and attributes of GBeanInfo to HashMap -
addInterface had a bug - two interfaces one with setter and another with getter
would cause that there're two attributes of the same name
o some typos
o change GBeanInfo::get* to their equivalents with no Set in the name and use
plural
o introduce null checks in constructors
o some javadoc improvements
o junit tests
Revision Changes Path
1.8 +10 -11
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java
Index: GBeanInfo.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- GBeanInfo.java 25 Jan 2004 21:07:04 -0000 1.7
+++ GBeanInfo.java 24 Feb 2004 18:41:45 -0000 1.8
@@ -58,13 +58,12 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
-
-import org.apache.geronimo.gbean.GAttributeInfo;
/**
* Describes a GBean.
@@ -77,7 +76,7 @@
* @param className name of the class to get the GBeanInfo from
* @param classLoader the class loader use to load the specifiec class
* @return GBeanInfo generated by supplied class
- * @throws org.apache.geronimo.gbean.InvalidConfigurationException if
there is a problem gettting the GBeanInfo info from the class
+ * @throws org.apache.geronimo.gbean.InvalidConfigurationException if
there is a problem getting the GBeanInfo from the class
*/
public static GBeanInfo getGBeanInfo(String className, ClassLoader
classLoader) throws InvalidConfigurationException {
Class clazz;
@@ -107,11 +106,11 @@
private final Set notifications;
private final Set references;
- public GBeanInfo(String className, Set attributes, GConstructorInfo
constructor, Set operations, Set references, Set notifications) {
+ public GBeanInfo(String className, Collection attributes,
GConstructorInfo constructor, Collection operations, Set references, Set
notifications) {
this(className, className, attributes, constructor, operations,
references, notifications);
}
- public GBeanInfo(String name, String className, Set attributes,
GConstructorInfo constructor, Set operations, Set references, Set
notifications) {
+ public GBeanInfo(String name, String className, Collection attributes,
GConstructorInfo constructor, Collection operations, Set references, Set
notifications) {
this.name = name;
this.className = className;
if(attributes == null) {
@@ -149,7 +148,7 @@
return className;
}
- public Set getAttributeSet() {
+ public Set getAttributes() {
return attributes;
}
@@ -168,15 +167,15 @@
return constructor;
}
- public Set getOperationsSet() {
+ public Set getOperations() {
return operations;
}
- public Set getNotificationsSet() {
+ public Set getNotifications() {
return notifications;
}
- public Set getReferencesSet() {
+ public Set getReferences() {
return references;
}
1.12 +57 -29
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoFactory.java
Index: GBeanInfoFactory.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- GBeanInfoFactory.java 21 Feb 2004 22:17:52 -0000 1.11
+++ GBeanInfoFactory.java 24 Feb 2004 18:41:45 -0000 1.12
@@ -57,26 +57,33 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Arrays;
/**
- *
- *
* @version $Revision$ $Date$
*/
public class GBeanInfoFactory {
+
private static final Class[] NO_ARGS = {};
+
private final String name;
+
private final String className;
- private final Set attributes = new HashSet();
+
+ private final Map attributes = new HashMap();
+
private GConstructorInfo constructor;
- private final Set operations = new HashSet();
+
+ private final Map operations = new HashMap();
+
private final Set references = new HashSet();
+
private final Set notifications = new HashSet();
public GBeanInfoFactory(String name) {
@@ -84,6 +91,9 @@
}
public GBeanInfoFactory(Class clazz) {
+ if (clazz == null) {
+ throw new IllegalArgumentException("argument is null");
+ }
this.name = this.className = clazz.getName();
}
@@ -101,13 +111,28 @@
}
public GBeanInfoFactory(String name, String className, GBeanInfo source)
{
- assert name != null && className != null && source != null;
+ if (name == null || className == null || source == null) {
+ throw new IllegalArgumentException("null argument(s) supplied");
+ }
this.name = name;
this.className = className;
- attributes.addAll(source.getAttributeSet());
- operations.addAll(source.getOperationsSet());
- references.addAll(source.getReferencesSet());
- notifications.addAll(source.getNotificationsSet());
+ Set sourceAttrs = source.getAttributes();
+ if (sourceAttrs != null && !sourceAttrs.isEmpty()) {
+ for (Iterator it = sourceAttrs.iterator(); it.hasNext();) {
+ GAttributeInfo gattrInfo = (GAttributeInfo) it.next();
+ attributes.put(gattrInfo.getName(), gattrInfo);
+ }
+ }
+
+ Set sourceOps = source.getOperations();
+ if (sourceOps != null && !sourceOps.isEmpty()) {
+ for (Iterator it = sourceOps.iterator(); it.hasNext();) {
+ GOperationInfo gopInfo = (GOperationInfo) it.next();
+ operations.put(gopInfo.getName(), gopInfo);
+ }
+ }
+ references.addAll(source.getReferences());
+ notifications.addAll(source.getNotifications());
//in case subclass constructor has same parameters as superclass.
constructor = source.getConstructor();
}
@@ -116,9 +141,8 @@
addInterface(intf, new String[0]);
}
- public void addInterface(Class intf, String[] persistentAttriubtes) {
- Set persistentName = new
HashSet(Arrays.asList(persistentAttriubtes));
- Map tempAttributes = new HashMap();
+ public void addInterface(Class intf, String[] persistentAttributes) {
+ Set persistentName = new
HashSet(Arrays.asList(persistentAttributes));
Method[] methods = intf.getMethods();
for (int i = 0; i < methods.length; i++) {
@@ -127,37 +151,40 @@
Class[] parameterTypes = method.getParameterTypes();
if ((name.startsWith("get") || name.startsWith("is")) &&
parameterTypes.length == 0) {
String attributeName = (name.startsWith("get")) ?
name.substring(3) : name.substring(2);
- GAttributeInfo attribute = (GAttributeInfo)
tempAttributes.get(attributeName);
+ GAttributeInfo attribute = (GAttributeInfo)
attributes.get(attributeName);
if (attribute == null) {
- tempAttributes.put(attributeName, new
GAttributeInfo(attributeName, persistentName.contains(attributeName), name,
null));
+ attributes.put(attributeName, new
GAttributeInfo(attributeName,
+ persistentName.contains(attributeName), name,
null));
} else {
- tempAttributes.put(attributeName, new
GAttributeInfo(attributeName, persistentName.contains(attributeName), name,
attribute.getSetterName()));
+ attributes.put(attributeName, new
GAttributeInfo(attributeName,
+ persistentName.contains(attributeName), name,
attribute.getSetterName()));
}
} else if (name.startsWith("set") && parameterTypes.length == 1)
{
String attributeName = name.substring(3);
- GAttributeInfo attribute = (GAttributeInfo)
tempAttributes.get(attributeName);
+ GAttributeInfo attribute = (GAttributeInfo)
attributes.get(attributeName);
if (attribute == null) {
- tempAttributes.put(attributeName, new
GAttributeInfo(attributeName, persistentName.contains(attributeName), null,
name));
+ attributes.put(attributeName, new
GAttributeInfo(attributeName,
+ persistentName.contains(attributeName), null,
name));
} else {
- tempAttributes.put(attributeName, new
GAttributeInfo(attributeName, persistentName.contains(attributeName),
attribute.getSetterName(), name));
+ attributes.put(attributeName, new
GAttributeInfo(attributeName,
+ persistentName.contains(attributeName),
attribute.getSetterName(), name));
}
} else {
List parameters = new ArrayList(parameterTypes.length);
for (int j = 0; j < parameterTypes.length; j++) {
parameters.add(parameterTypes[j].getName());
}
- operations.add(new GOperationInfo(name, name, parameters));
+ addOperation(new GOperationInfo(name, name, parameters));
}
}
- attributes.addAll(tempAttributes.values());
}
public void addAttribute(String name, boolean persistent) {
- attributes.add(new GAttributeInfo(name, persistent));
+ addAttribute(new GAttributeInfo(name, persistent));
}
public void addAttribute(GAttributeInfo info) {
- attributes.add(info);
+ attributes.put(info.getName(), info);
}
public void setConstructor(GConstructorInfo constructor) {
@@ -169,15 +196,15 @@
}
public void addOperation(GOperationInfo info) {
- operations.add(info);
+ operations.put(info.getName(), info);
}
public void addOperation(String name) {
- operations.add(new GOperationInfo(name, NO_ARGS));
+ addOperation(new GOperationInfo(name, NO_ARGS));
}
public void addOperation(String name, Class[] paramTypes) {
- operations.add(new GOperationInfo(name, paramTypes));
+ addOperation(new GOperationInfo(name, paramTypes));
}
public void addReference(GReferenceInfo info) {
@@ -185,7 +212,7 @@
}
public void addReference(String name, Class type) {
- references.add(new GReferenceInfo(name, type));
+ addReference(new GReferenceInfo(name, type));
}
public void addNotification(GNotificationInfo info) {
@@ -193,6 +220,7 @@
}
public GBeanInfo getBeanInfo() {
- return new GBeanInfo(name, className, attributes, constructor,
operations, references, notifications);
+ return new GBeanInfo(name, className, attributes.values(),
constructor, operations.values(), references,
+ notifications);
}
}
1.11 +12 -11
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Index: GBeanMBean.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- GBeanMBean.java 24 Feb 2004 06:05:37 -0000 1.10
+++ GBeanMBean.java 24 Feb 2004 18:41:45 -0000 1.11
@@ -94,9 +94,9 @@
import net.sf.cglib.reflect.FastClass;
/**
- * A GeronimoMBean is a J2EE Management Managed Object, and is standard base
for Geronimo services.
+ * A GBeanMBean is a J2EE Management Managed Object, and is standard base
for Geronimo services.
* This wraps one or more target POJOs and exposes the attributes and
opperation according to a supplied
- * GeronimoMBeanInfo instance. The GeronimoMBean also support caching of
attribute values and invocation results
+ * [EMAIL PROTECTED] GBeanInfo} instance. The GBeanMBean also supports
caching of attribute values and invocation results
* which can reduce the number of calls to a target.
*
* @version $Revision$ $Date$
@@ -128,7 +128,7 @@
private final Map referenceMap = new HashMap();
/**
- * Opperations supported by this GBeanMBean by (MBeanOperationSignature)
name.
+ * Operations supported by this GBeanMBean by (MBeanOperationSignature)
name.
*/
private final Map operationMap = new HashMap();
@@ -156,7 +156,7 @@
try {
type = classLoader.loadClass(beanInfo.getClassName());
} catch (ClassNotFoundException e) {
- throw new InvalidConfigurationException("Could not load GBean
class from classloader: " +
+ throw new InvalidConfigurationException("Could not load
GBeanInfo class from classloader: " +
" className=" + beanInfo.getClassName());
}
@@ -164,19 +164,19 @@
// attributes
Map constructorTypes =
gbeanInfo.getConstructor().getAttributeTypeMap();
- for (Iterator iterator = beanInfo.getAttributeSet().iterator();
iterator.hasNext();) {
+ for (Iterator iterator = beanInfo.getAttributes().iterator();
iterator.hasNext();) {
GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
addAttribute(new GBeanMBeanAttribute(this, attributeInfo,
(Class) constructorTypes.get(attributeInfo.getName())));
}
// references
- for (Iterator iterator = beanInfo.getReferencesSet().iterator();
iterator.hasNext();) {
+ for (Iterator iterator = beanInfo.getReferences().iterator();
iterator.hasNext();) {
GReferenceInfo referenceInfo = (GReferenceInfo) iterator.next();
addReference(new GBeanMBeanReference(this, referenceInfo,
(Class) constructorTypes.get(referenceInfo.getName())));
}
// operations
- for (Iterator iterator = beanInfo.getOperationsSet().iterator();
iterator.hasNext();) {
+ for (Iterator iterator = beanInfo.getOperations().iterator();
iterator.hasNext();) {
GOperationInfo operationInfo = (GOperationInfo) iterator.next();
addOperation(new GBeanMBeanOperation(this, operationInfo));
}
@@ -205,6 +205,7 @@
mbeanAttrs,
new MBeanConstructorInfo[0],
mbeanOps,
+ // Is there any way to add notifications before an instance
of the class is created?
(MBeanNotificationInfo[]) notifications.toArray(new
MBeanNotificationInfo[notifications.size()]));
}
@@ -218,7 +219,7 @@
* this static method in the class to be wrapped in the GBeanMBean
instance.
* @param className name of the class to call getGBeanInfo on
* @param classLoader the class loader for this GBean
- * @throws java.lang.Exception if an exception occurs while getting the
GeronimoMBeanInfo from the class
+ * @throws java.lang.Exception if an exception occurs while getting the
GBeanInfo from the class
*/
public GBeanMBean(String className, ClassLoader classLoader) throws
Exception {
this(GBeanInfo.getGBeanInfo(className, classLoader), classLoader);
@@ -229,7 +230,7 @@
* "getGBeanInfo" is called to get the gbean info. Usually one will
include
* this static method in the class to be wrapped in the GBeanMBean
instance.
* @param className name of the class to call getGBeanInfo on
- * @throws java.lang.Exception if an exception occurs while getting the
GeronimoMBeanInfo from the class
+ * @throws java.lang.Exception if an exception occurs while getting the
GBeanInfo from the class
*/
public GBeanMBean(String className) throws Exception {
this(className, ClassLoader.getSystemClassLoader());
@@ -373,7 +374,7 @@
}
protected void doStart() throws Exception {
- // start all of the reference
+ // start all of the references
for (Iterator iterator = referenceMap.values().iterator();
iterator.hasNext();) {
GBeanMBeanReference reference = (GBeanMBeanReference)
iterator.next();
reference.start();
1.14 +2 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Index: Configuration.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Configuration.java 24 Feb 2004 06:05:37 -0000 1.13
+++ Configuration.java 24 Feb 2004 18:41:45 -0000 1.14
@@ -395,7 +395,7 @@
oos.writeObject(attributeInfo.getName());
oos.writeObject(gbean.getAttribute(attributeInfo.getName()));
}
- Set endpointsSet = gbean.getGBeanInfo().getReferencesSet();
+ Set endpointsSet = gbean.getGBeanInfo().getReferences();
oos.writeInt(endpointsSet.size());
for (Iterator iterator = endpointsSet.iterator();
iterator.hasNext();) {
GReferenceInfo gEndpointInfo = (GReferenceInfo) iterator.next();
1.1
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanInfoFactoryTest.java
Index: GBeanInfoFactoryTest.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 [EMAIL PROTECTED]
*
* 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.gbean;
import java.io.Serializable;
import java.util.Set;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2004/02/24 18:41:45 $
*/
public class GBeanInfoFactoryTest extends TestCase {
/*
* void GBeanInfoFactory(String)
*/
public void testGBeanInfoFactoryString() {
assertNotNull(new GBeanInfoFactory(""));
assertNotNull(new GBeanInfoFactory((String) null));
}
/*
* void GBeanInfoFactory(Class)
*/
public void testGBeanInfoFactoryClass() {
assertNotNull(new GBeanInfoFactory(String.class));
try {
new GBeanInfoFactory((Class) null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {}
}
/*
* Class to test for void GBeanInfoFactory(String, String)
*/
public void testGBeanInfoFactoryStringString() {
}
/*
* void GBeanInfoFactory(String, GBeanInfo)
*/
public void testGBeanInfoFactoryStringGBeanInfo() {
try {
new GBeanInfoFactory((String) null, (GBeanInfo) null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {}
GBeanInfoFactory gbeanInfoFactory = new
GBeanInfoFactory(String.class.getName(),
GBeanInfo.getGBeanInfo(GBeanInfoTest.MockGBean.class.getName(),
GBeanInfoTest.MockGBean.class.getClassLoader()));
assertNotNull(gbeanInfoFactory);
}
/*
* void GBeanInfoFactory(String, String, GBeanInfo)
*/
public void testGBeanInfoFactoryStringStringGBeanInfo() {}
/*
* Class to test for void addInterface(Class)
*/
public void testAddInterfaceClass() {
GBeanInfoFactory gbeanInfoFactory;
gbeanInfoFactory = new GBeanInfoFactory("");
gbeanInfoFactory.addInterface(Serializable.class);
assertTrue(gbeanInfoFactory.getBeanInfo().getAttributes().size() ==
0);
assertTrue(gbeanInfoFactory.getBeanInfo().getOperations().size() ==
0);
gbeanInfoFactory = new GBeanInfoFactory("");
gbeanInfoFactory.addInterface(GBean.class);
GBeanInfo gbeanInfo = gbeanInfoFactory.getBeanInfo();
assertTrue(gbeanInfo.getAttributes().size() == 1);
GAttributeInfo gattrInfo = (GAttributeInfo)
gbeanInfo.getAttributes().iterator().next();
assertEquals("GBeanContext", gattrInfo.getName());
assertEquals("setGBeanContext", gattrInfo.getSetterName());
assertNull(gattrInfo.getGetterName());
assertTrue(gbeanInfo.getOperations().size() == 3);
gbeanInfoFactory = new GBeanInfoFactory("");
gbeanInfoFactory.addInterface(SetterOnlyInterface.class);
gbeanInfo = gbeanInfoFactory.getBeanInfo();
assertEquals(1, gbeanInfo.getAttributes().size());
gattrInfo = (GAttributeInfo)
gbeanInfo.getAttributes().iterator().next();
assertEquals("Int", gattrInfo.getName());
assertEquals("setInt", gattrInfo.getSetterName());
assertNull(gattrInfo.getGetterName());
Set opsSet = gbeanInfo.getOperations();
assertEquals(0, opsSet.size());
gbeanInfoFactory.addInterface(GetterOnlyInterface.class);
gbeanInfo = gbeanInfoFactory.getBeanInfo();
opsSet = gbeanInfo.getOperations();
assertEquals(0, opsSet.size());
assertEquals(1, gbeanInfo.getAttributes().size());
gattrInfo = (GAttributeInfo)
gbeanInfo.getAttributes().iterator().next();
assertEquals("Int", gattrInfo.getName());
assertEquals("getInt", gattrInfo.getGetterName());
assertEquals("setInt", gattrInfo.getSetterName());
}
/*
* Class to test for void addInterface(Class, String[])
*/
public void testAddInterfaceClassStringArray() {}
/*
* Class to test for void addAttribute(String, boolean)
*/
public void testAddAttributeStringboolean() {}
/*
* Class to test for void addAttribute(GAttributeInfo)
*/
public void testAddAttributeGAttributeInfo() {}
/*
* Class to test for void setConstructor(GConstructorInfo)
*/
public void testSetConstructorGConstructorInfo() {}
/*
* Class to test for void setConstructor(String[], Class[])
*/
public void testSetConstructorStringArrayClassArray() {}
/*
* Class to test for void addOperation(GOperationInfo)
*/
public void testAddOperationGOperationInfo() {}
/*
* Class to test for void addOperation(String, Class[])
*/
public void testAddOperationStringClassArray() {}
/*
* Class to test for void addReference(GReferenceInfo)
*/
public void testAddReferenceGReferenceInfo() {}
/*
* Class to test for void addReference(String, Class)
*/
public void testAddReferenceStringClass() {}
public void testAddNotification() {}
public void testGetBeanInfo() {}
protected void setUp() {}
protected void tearDown() {}
private static interface SetterOnlyInterface {
public void setInt(int i);
}
private static interface GetterOnlyInterface {
public int getInt();
}
}
1.1
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanInfoTest.java
Index: GBeanInfoTest.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 [EMAIL PROTECTED]
*
* 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.gbean;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2004/02/24 18:41:45 $
*/
public class GBeanInfoTest extends TestCase {
public void testGetGBeanInfo() {
// 1. Test GBean that exists
GBeanInfo gbeanInfo =
GBeanInfo.getGBeanInfo(MockGBean.class.getName(),
MockGBean.class.getClassLoader());
assertNotNull(gbeanInfo);
// 2. Test GBean that doesn't exist
try {
GBeanInfo.getGBeanInfo("ClassThatDoesNotExist", this.getClass()
.getClassLoader());
fail("InvalidConfigurationException expected");
} catch (InvalidConfigurationException expected) {
}
// 3. Test GBean that exist, but doesn't declare a getGBeanInfo()
// method
try {
GBeanInfo.getGBeanInfo(String.class.getName(), this.getClass()
.getClassLoader());
fail("InvalidConfigurationException expected");
} catch (InvalidConfigurationException expected) {
}
}
/*
* void GBeanInfo(String, Set, GConstructorInfo, Set, Set, Set)
*/
public void testGBeanInfoStringSetGConstructorInfoSetSetSet() {
GBeanInfo gbeanInfo = new GBeanInfo(null, null, null, null, null,
null);
assertNotNull(gbeanInfo);
}
/*
* void GBeanInfo(String, String, Set, GConstructorInfo, Set, Set, Set)
*/
public void testGBeanInfoStringStringSetGConstructorInfoSetSetSet() {
GBeanInfo gbeanInfo = new GBeanInfo(null, null, null, null, null,
null,
null);
assertNotNull(gbeanInfo);
}
public void testGetName() {
assertEquals(MockGBean.class.getName(), gbeanInfo.getName());
}
public void testGetClassName() {
assertEquals(MockGBean.class.getName(), gbeanInfo.getClassName());
}
public void testGetAttributeSet() {
Set attrSet = gbeanInfo.getAttributes();
assertEquals(2, attrSet.size());
assertTrue(attrSet.contains(persistentAttrInfo));
assertTrue(attrSet.contains(nonPersistentAttrInfo));
}
public void testGetPersistentAttributes() {
List attrList = gbeanInfo.getPersistentAttributes();
assertEquals(1, attrList.size());
assertEquals(persistentAttrInfo, attrList.get(0));
}
public void testGetConstructor() {
GConstructorInfo gctorInfo = gbeanInfo.getConstructor();
List attrNameList = gctorInfo.getAttributeNames();
assertEquals(2, attrNameList.size());
assertTrue(attrNameList.contains(String.class.getName()));
assertTrue(attrNameList.contains(Integer.class.getName()));
Map attrTypeMap = gctorInfo.getAttributeTypeMap();
assertTrue(attrTypeMap.containsValue(String.class));
assertTrue(attrTypeMap.containsValue(Integer.class));
assertEquals(String.class, attrTypeMap.get(String.class.getName()));
assertEquals(Integer.class, attrTypeMap.get(Integer.class.getName()));
}
public void testGetOperationsSet() {
Set gbeanOpSet = gbeanInfo.getOperations();
assertEquals(1, gbeanOpSet.size());
assertTrue(gbeanOpSet.contains(opInfo));
}
public void testGetNotificationsSet() {
Set gbeanNotificationSet = gbeanInfo.getNotifications();
assertEquals(1, gbeanNotificationSet.size());
assertTrue(gbeanNotificationSet.contains(notificationInfo));
}
public void testGetReferencesSet() {
Set gbeanRefSet = gbeanInfo.getReferences();
assertEquals(1, gbeanRefSet.size());
assertTrue(gbeanRefSet.contains(refInfo));
}
public void testToString() {
assertNotNull(gbeanInfo.toString());
assertEquals(gbeanInfo.toString(),
MockGBean.getGBeanInfo().toString());
}
GBeanInfo gbeanInfo;
final static String nonPersistentAttrName = "nonPersistentAttribute";
final static GAttributeInfo nonPersistentAttrInfo = new GAttributeInfo(
nonPersistentAttrName, false);
final static String persistentAttrName = "persistentAttribute";
final static GAttributeInfo persistentAttrInfo = new GAttributeInfo(
persistentAttrName, true);
final static GOperationInfo opInfo = new GOperationInfo("operation");
final static GNotificationInfo notificationInfo = new GNotificationInfo(
"notification", Collections.singleton(null));
final static GReferenceInfo refInfo = new GReferenceInfo("reference",
String.class);
public void setUp() {
gbeanInfo = MockGBean.getGBeanInfo();
}
protected void tearDown() throws Exception {
gbeanInfo = null;
}
public static final class MockGBean {
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(MockGBean.class);
infoFactory.setConstructor(new GConstructorInfo(new String[] {
String.class.getName(), Integer.class.getName()},
new Class[] { String.class, Integer.class}));
infoFactory.addAttribute(nonPersistentAttrInfo);
infoFactory.addAttribute(persistentAttrInfo);
infoFactory.addOperation(opInfo);
infoFactory.addNotification(notificationInfo);
infoFactory.addReference(refInfo);
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}
}