[jboss-svn-commits] JBL Code SVN: r32107 - in labs/jbosstm/trunk: common/tests/com/arjuna/common/tests/logging and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Mar 16 05:45:35 EDT 2010
Author: jhalliday
Date: 2010-03-16 05:45:35 -0400 (Tue, 16 Mar 2010)
New Revision: 32107
Added:
labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/EnvironmentBeanTest.java
Modified:
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java
Log:
Improved EnvironmentBean unit test coverage. JBTM-720
Added: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/EnvironmentBeanTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/EnvironmentBeanTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/EnvironmentBeanTest.java 2010-03-16 09:45:35 UTC (rev 32107)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates,
+ * and individual contributors as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2010,
+ * @author JBoss, by Red Hat.
+ */
+package com.hp.mwtests.ts.arjuna.common;
+
+import com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean;
+import com.arjuna.ats.arjuna.common.CoreEnvironmentBean;
+import com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean;
+import com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean;
+import org.junit.Test;
+
+/**
+ * Unit tests for EnvironmentBean classes.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com)
+ */
+public class EnvironmentBeanTest
+{
+ @Test
+ public void testCoordinatorEnvironmentBean() throws Exception {
+ com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new CoordinatorEnvironmentBean());
+ }
+
+ @Test
+ public void testObjectStoreEnvironmentBean() throws Exception {
+ com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new ObjectStoreEnvironmentBean());
+ }
+
+ @Test
+ public void testRecoveryEnvironmentBean() throws Exception {
+ com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new RecoveryEnvironmentBean());
+ }
+
+ @Test
+ public void testCoreEnvironmentBean() throws Exception {
+ com.arjuna.common.tests.simple.EnvironmentBeanTest.testBeanByReflection(new CoreEnvironmentBean());
+ }
+}
Modified: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java 2010-03-16 06:53:33 UTC (rev 32106)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java 2010-03-16 09:45:35 UTC (rev 32107)
@@ -21,7 +21,9 @@
package com.arjuna.common.tests.logging;
import com.arjuna.common.internal.util.logging.LoggingEnvironmentBean;
+import com.arjuna.common.internal.util.logging.basic.BasicLogEnvironmentBean;
import com.arjuna.common.internal.util.logging.commonPropertyManager;
+import com.arjuna.common.tests.simple.EnvironmentBeanTest;
import com.arjuna.common.util.exceptions.LogConfigurationException;
import com.arjuna.common.util.logging.*;
@@ -101,4 +103,15 @@
}
}
+
+ @Test
+ public void testLoggingEnvironmentBean() throws Exception {
+ EnvironmentBeanTest.testBeanByReflection(new LoggingEnvironmentBean());
+ }
+
+ @Test
+ public void testBasicLogEnvironmentBean() throws Exception {
+ EnvironmentBeanTest.testBeanByReflection(new BasicLogEnvironmentBean());
+ }
+
}
Modified: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java 2010-03-16 06:53:33 UTC (rev 32106)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java 2010-03-16 09:45:35 UTC (rev 32107)
@@ -20,10 +20,14 @@
*/
package com.arjuna.common.tests.simple;
+import com.arjuna.common.internal.util.propertyservice.ConcatenationPrefix;
+import com.arjuna.common.internal.util.propertyservice.PropertyPrefix;
import org.junit.Test;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
-import java.util.Set;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
import static org.junit.Assert.*;
@@ -48,4 +52,112 @@
assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
+
+ ///////////////////////////////////////////////
+
+ public static void testBeanByReflection(Object environmentBean) throws Exception {
+
+ for(Field field : environmentBean.getClass().getDeclaredFields()) {
+ Class type = field.getType();
+
+ String setterMethodName = "set"+capitalizeFirstLetter(field.getName());
+ Method setter;
+ try {
+ setter = environmentBean.getClass().getMethod(setterMethodName, new Class[] {field.getType()});
+ } catch(NoSuchMethodException e) {
+ continue; // emma code coverage tool adds fields to instrumented classes - ignore them.
+ }
+
+ String getterMethodName;
+ Method getter = null;
+ if(field.getType().equals(Boolean.TYPE)) {
+ getterMethodName = "is"+capitalizeFirstLetter(field.getName());
+ try {
+ getter = environmentBean.getClass().getMethod(getterMethodName, new Class[] {});
+ } catch (NoSuchMethodException e) {}
+ }
+
+ if(getter == null) {
+ getterMethodName = "get"+capitalizeFirstLetter(field.getName());
+ getter = environmentBean.getClass().getMethod(getterMethodName, new Class[] {});
+ }
+
+ if(field.getType().getName().startsWith("java.util")) {
+ handleGroupProperty(environmentBean, field, setter, getter);
+ } else {
+ handleSimpleProperty(environmentBean, field, setter, getter);
+ }
+ }
+
+ }
+
+ private static void handleGroupProperty(Object bean, Field field, Method setter, Method getter)
+ throws Exception
+ {
+ Object inputValue = null;
+
+ if(java.util.Map.class.isAssignableFrom(field.getType())) {
+
+ inputValue = new HashMap<String,String>();
+ ((Map)inputValue).put("testKey", "testValue");
+
+ } else {
+
+ inputValue = new ArrayList<String>();
+ ((List)inputValue).add("testValue");
+
+ }
+
+ setter.invoke(bean, new Object[] {inputValue});
+
+ Object outputValue = getter.invoke(bean, new Object[] {});
+
+ assertEquals(inputValue, outputValue);
+ assertNotSame(inputValue, outputValue);
+
+ setter.invoke(bean, new Object[] {null});
+ outputValue = getter.invoke(bean, new Object[] {});
+ assertNotNull(outputValue);
+ assertTrue(((Collection)outputValue).isEmpty());
+
+ }
+
+ private static void handleSimpleProperty(Object bean, Field field, Method setter, Method getter)
+ throws Exception
+ {
+ Object inputValue = null;
+
+ if(field.getType().equals(Boolean.TYPE)) {
+
+ inputValue = Boolean.TRUE;
+ setter.invoke(bean, new Object[]{ inputValue });
+
+ } else if(field.getType().equals(String.class)) {
+
+ inputValue = "inputValue";
+ setter.invoke(bean, new Object[] {inputValue});
+
+ } else if(field.getType().equals(Long.TYPE)) {
+
+ inputValue = new Long(1001);
+ setter.invoke(bean, new Object[] {inputValue});
+
+ } else if(field.getType().equals(Integer.TYPE)) {
+
+ inputValue = new Integer(1001);
+ setter.invoke(bean, new Object[] {inputValue});
+
+ } else {
+
+ throw new Exception("unknown field type "+field.getType());
+ }
+
+ Object outputValue = getter.invoke(bean, new Object[] {});
+
+ assertEquals(inputValue, outputValue);
+ }
+
+ private static String capitalizeFirstLetter(String string) {
+ return (string.length()>0) ? (Character.toUpperCase(string.charAt(0))+string.substring(1)) : string;
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list