[jboss-svn-commits] JBL Code SVN: r29686 - in labs/jbosstm/trunk: ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/basic and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 20 08:32:22 EDT 2009
Author: jhalliday
Date: 2009-10-20 08:32:22 -0400 (Tue, 20 Oct 2009)
New Revision: 29686
Added:
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyProperties.java
Removed:
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyPropertyManager.java
labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/CSFToolTest.java
Modified:
labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/BeanPopulatorTest.java
labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/basic/BeanPopulatorTest.java
labs/jbosstm/trunk/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/BeanPopulatorTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/BeanPopulatorTest.java
labs/jbosstm/trunk/ArjunaJTS/jts/tests/classes/com/hp/mwtests/ts/jts/BeanPopulatorTest.java
labs/jbosstm/trunk/ArjunaJTS/orbportability/tests/classes/com/hp/mwtests/orbportability/initialisation/BeanPopulatorTest.java
labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/propertyservice/BeanPopulator.java
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/BeanPopulatorTest.java
labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java
Log:
Refactor config bean population code to reduce dependence on PropertyManager. JBTM-628
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/common/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -21,7 +21,7 @@
package com.hp.mwtests.ts.arjuna.common;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
-import com.arjuna.common.tests.simple.DummyPropertyManager;
+import com.arjuna.common.tests.simple.DummyProperties;
import com.arjuna.ats.arjuna.common.*;
import java.util.Set;
@@ -44,19 +44,24 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- testManager.addConcatenationKeys(RecoveryEnvironmentBean.class);
- testManager.addConcatenationKeys(CoreEnvironmentBean.class);
+ testProperties.addConcatenationKeys(RecoveryEnvironmentBean.class);
+ testProperties.addConcatenationKeys(CoreEnvironmentBean.class);
- BeanPopulator.configureFromPropertyManager(new CoordinatorEnvironmentBean(), testManager);
- BeanPopulator.configureFromPropertyManager(new RecoveryEnvironmentBean(), testManager);
- BeanPopulator.configureFromPropertyManager(new CoreEnvironmentBean(), testManager);
- BeanPopulator.configureFromPropertyManager(new ObjectStoreEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new CoordinatorEnvironmentBean(), testProperties);
+ BeanPopulator.configureFromProperties(new RecoveryEnvironmentBean(), testProperties);
+ BeanPopulator.configureFromProperties(new CoreEnvironmentBean(), testProperties);
+ BeanPopulator.configureFromProperties(new ObjectStoreEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.addAll( DummyPropertyManager.extractKeys(Environment.class));
+ expectedKeys.addAll( DummyProperties.extractKeys(Environment.class));
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ System.out.println(testProperties.usedKeys);
+
+ System.out.println(expectedKeys);
+
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
+
}
}
Modified: labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/basic/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/basic/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/ArjunaCore/txoj/tests/classes/com/hp/mwtests/ts/txoj/basic/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -23,7 +23,7 @@
import org.junit.Test;
import static org.junit.Assert.*;
-import com.arjuna.common.tests.simple.DummyPropertyManager;
+import com.arjuna.common.tests.simple.DummyProperties;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import com.arjuna.ats.txoj.common.TxojEnvironmentBean;
import com.arjuna.ats.txoj.common.Environment;
@@ -45,13 +45,13 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- BeanPopulator.configureFromPropertyManager(new TxojEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new TxojEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.addAll( DummyPropertyManager.extractKeys(Environment.class));
+ expectedKeys.addAll( DummyProperties.extractKeys(Environment.class));
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
Modified: labs/jbosstm/trunk/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -23,7 +23,7 @@
import org.junit.Test;
import static org.junit.Assert.*;
-import com.arjuna.common.tests.simple.DummyPropertyManager;
+import com.arjuna.common.tests.simple.DummyProperties;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import com.arjuna.ats.jdbc.common.Environment;
import com.arjuna.ats.jdbc.common.JDBCEnvironmentBean;
@@ -45,13 +45,13 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- BeanPopulator.configureFromPropertyManager(new JDBCEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new JDBCEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.addAll( DummyPropertyManager.extractKeys(Environment.class));
+ expectedKeys.addAll( DummyProperties.extractKeys(Environment.class));
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -21,7 +21,7 @@
package com.hp.mwtests.ts.jta.basic;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
-import com.arjuna.common.tests.simple.DummyPropertyManager;
+import com.arjuna.common.tests.simple.DummyProperties;
import com.arjuna.ats.jta.common.JTAEnvironmentBean;
import com.arjuna.ats.jta.common.Environment;
@@ -45,17 +45,17 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
- testManager.addConcatenationKeys(JTAEnvironmentBean.class);
+ DummyProperties testProperties = new DummyProperties();
+ testProperties.addConcatenationKeys(JTAEnvironmentBean.class);
- BeanPopulator.configureFromPropertyManager(new JTAEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new JTAEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.addAll( DummyPropertyManager.extractKeys(Environment.class));
+ expectedKeys.addAll( DummyProperties.extractKeys(Environment.class));
System.out.println("expectedKeys: "+expectedKeys);
- System.out.println("usedKeys: "+testManager.usedKeys);
+ System.out.println("usedKeys: "+testProperties.usedKeys);
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
Modified: labs/jbosstm/trunk/ArjunaJTS/jts/tests/classes/com/hp/mwtests/ts/jts/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jts/tests/classes/com/hp/mwtests/ts/jts/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/ArjunaJTS/jts/tests/classes/com/hp/mwtests/ts/jts/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -20,7 +20,7 @@
*/
package com.hp.mwtests.ts.jts;
-import com.arjuna.common.tests.simple.DummyPropertyManager;
+import com.arjuna.common.tests.simple.DummyProperties;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import com.arjuna.ats.jts.common.JTSEnvironmentBean;
import com.arjuna.ats.jts.common.Environment;
@@ -45,13 +45,13 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- BeanPopulator.configureFromPropertyManager(new JTSEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new JTSEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.addAll( DummyPropertyManager.extractKeys(Environment.class));
+ expectedKeys.addAll( DummyProperties.extractKeys(Environment.class));
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
Modified: labs/jbosstm/trunk/ArjunaJTS/orbportability/tests/classes/com/hp/mwtests/orbportability/initialisation/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/orbportability/tests/classes/com/hp/mwtests/orbportability/initialisation/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/ArjunaJTS/orbportability/tests/classes/com/hp/mwtests/orbportability/initialisation/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -20,7 +20,7 @@
*/
package com.hp.mwtests.orbportability.initialisation;
-import com.arjuna.common.tests.simple.DummyPropertyManager;
+import com.arjuna.common.tests.simple.DummyProperties;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;
import com.arjuna.orbportability.common.OrbPortabilityEnvironmentBean;
import com.arjuna.orbportability.common.Environment;
@@ -45,15 +45,15 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- testManager.addConcatenationKeys(OrbPortabilityEnvironmentBean.class);
+ testProperties.addConcatenationKeys(OrbPortabilityEnvironmentBean.class);
- BeanPopulator.configureFromPropertyManager(new OrbPortabilityEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new OrbPortabilityEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.addAll( DummyPropertyManager.extractKeys(Environment.class));
+ expectedKeys.addAll( DummyProperties.extractKeys(Environment.class));
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/propertyservice/BeanPopulator.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/propertyservice/BeanPopulator.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/propertyservice/BeanPopulator.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -46,11 +46,11 @@
T bean = null;
try {
bean = beanClass.newInstance();
- configureFromPropertyManager(bean, propertyManager);
+ configureFromProperties(bean, propertyManager.getProperties());
} catch (Exception e) {
throw new RuntimeException(e);
}
- singletonBeanInstances.put(beanClass, bean);
+ singletonBeanInstances.putIfAbsent(beanClass, bean);
}
return (T)singletonBeanInstances.get(beanClass);
@@ -58,7 +58,7 @@
/**
* Examine the properties of the provided bean and update them to match the values of the corresponding
- * properties in the PropertyManager.
+ * properties in the Properties.
* This will normally be used at startup to configure a freshly created default bean to match
* the configuration read from a properties file.
*
@@ -81,15 +81,15 @@
* the same prefix e.g. com.arjuna.ats.arjuna.foo. whilst still allowing for changing of the property
* name in cases where this makes for more readable code.
*
- * Obtain the value of the property from the PropertyManager and if it's not null, type convert it to match
+ * Obtain the value of the property from the Properties and if it's not null, type convert it to match
* the bean's property field type. Obtain the value of the property from the bean and if it's different
- * from the value read from the propertyManager, use the setter to update the bean.
+ * from the value read from the Properties, use the setter to update the bean.
*
* @param bean a JavaBean, the target of the property updates and source for defaults.
- * @param propertyManager a PropertyManager, the source of the configuration overrides.
+ * @param properties a Properties object, the source of the configuration overrides.
* @throws Exception if the configuration of the bean fails.
*/
- public static void configureFromPropertyManager(Object bean, PropertyManager propertyManager) throws Exception {
+ public static void configureFromProperties(Object bean, Properties properties) throws Exception {
if(!bean.getClass().isAnnotationPresent(PropertyPrefix.class)) {
throw new Exception("no PropertyPrefix found on "+bean.getClass().getName());
@@ -116,27 +116,38 @@
}
if(field.isAnnotationPresent(ConcatenationPrefix.class)) {
- handleGroupProperty(bean, propertyManager, field, setter, getter);
+ handleGroupProperty(bean, properties, field, setter, getter);
} else {
- handleSimpleProperty(bean, propertyManager, field, setter, getter);
+ handleSimpleProperty(bean, properties, field, setter, getter);
}
}
}
- private static void handleGroupProperty(Object bean, PropertyManager propertyManager, Field field, Method setter, Method getter)
+ /**
+ * Render the state of the known bean instances as text.
+ */
+ public static String printState() {
+ StringBuffer buffer = new StringBuffer();
+ for(Object bean : singletonBeanInstances.values()) {
+ printBean(bean, buffer);
+ }
+ return buffer.toString();
+ }
+
+ private static void handleGroupProperty(Object bean, Properties properties, Field field, Method setter, Method getter)
throws Exception
{
List<String> values = new LinkedList<String>();
- String valueFromPropertyManager = getValueFromPropertyManager(bean, propertyManager, field, bean.getClass().getSimpleName());
+ String valueFromProperties = getValueFromProperties(bean, properties, field, bean.getClass().getSimpleName());
- if(valueFromPropertyManager != null)
+ if(valueFromProperties != null)
{
// it's a single value which needs parsing
- String[] tokens = valueFromPropertyManager.split("\\s+");
+ String[] tokens = valueFromProperties.split("\\s+");
- // the order we want them is is the order they appear in the string, so we can just add in sequence:
+ // the order we want them in is the order they appear in the string, so we can just add in sequence:
for(String token : tokens) {
values.add(token);
}
@@ -147,7 +158,7 @@
// the order we want them in is the lex sort order of the keys, so we need to buffer and sort them:
List<String> listOfMatchingPropertyNames = new LinkedList<String>();
- Enumeration propertyNamesEnumeration = propertyManager.propertyNames();
+ Enumeration propertyNamesEnumeration = properties.propertyNames();
if (propertyNamesEnumeration != null)
{
@@ -167,7 +178,7 @@
Collections.sort(listOfMatchingPropertyNames);
for(String name : listOfMatchingPropertyNames) {
- String value = propertyManager.getProperty(name);
+ String value = properties.getProperty(name);
values.add(value);
}
}
@@ -179,44 +190,44 @@
}
}
- private static void handleSimpleProperty(Object bean, PropertyManager propertyManager, Field field, Method setter, Method getter)
+ private static void handleSimpleProperty(Object bean, Properties properties, Field field, Method setter, Method getter)
throws Exception
{
PropertyPrefix prefixAnnotation = bean.getClass().getAnnotation(PropertyPrefix.class);
String prefix = prefixAnnotation.prefix();
- String valueFromPropertyManager = getValueFromPropertyManager(bean, propertyManager, field, prefix);
+ String valueFromProperties = getValueFromProperties(bean, properties, field, prefix);
- if(valueFromPropertyManager != null) {
+ if(valueFromProperties != null) {
Object valueFromBean = getter.invoke(bean, new Object[] {});
if(field.getType().equals(Boolean.TYPE)) {
- if(!((Boolean)valueFromBean).booleanValue() && isPositive(valueFromPropertyManager)) {
+ if(!((Boolean)valueFromBean).booleanValue() && isPositive(valueFromProperties)) {
setter.invoke(bean, new Object[]{ Boolean.TRUE });
}
- if(((Boolean)valueFromBean).booleanValue() && isNegative(valueFromPropertyManager)) {
+ if(((Boolean)valueFromBean).booleanValue() && isNegative(valueFromProperties)) {
setter.invoke(bean, new Object[] { Boolean.FALSE});
}
} else if(field.getType().equals(String.class)) {
- if(!valueFromPropertyManager.equals(valueFromBean)) {
- setter.invoke(bean, new Object[] {valueFromPropertyManager});
+ if(!valueFromProperties.equals(valueFromBean)) {
+ setter.invoke(bean, new Object[] {valueFromProperties});
}
} else if(field.getType().equals(Long.TYPE)) {
- Long longValue = Long.valueOf(valueFromPropertyManager);
+ Long longValue = Long.valueOf(valueFromProperties);
if(!longValue.equals(valueFromBean)) {
setter.invoke(bean, new Object[] {longValue});
}
} else if(field.getType().equals(Integer.TYPE)) {
- Integer intValue = Integer.valueOf(valueFromPropertyManager);
+ Integer intValue = Integer.valueOf(valueFromProperties);
if(!intValue.equals(valueFromBean)) {
setter.invoke(bean, new Object[] {intValue});
}
@@ -229,22 +240,22 @@
}
}
- private static String getValueFromPropertyManager(Object bean, PropertyManager propertyManager, Field field, String prefix)
+ private static String getValueFromProperties(Object bean, Properties properties, Field field, String prefix)
{
String propertyFileKey;
- String valueFromPropertyManager = null;
+ String valueFromProperties = null;
- if(valueFromPropertyManager == null) {
+ if(valueFromProperties == null) {
propertyFileKey = bean.getClass().getCanonicalName()+"."+field.getName();
- valueFromPropertyManager = propertyManager.getProperty(propertyFileKey);
+ valueFromProperties = properties.getProperty(propertyFileKey);
}
- if(valueFromPropertyManager == null) {
+ if(valueFromProperties == null) {
propertyFileKey = bean.getClass().getSimpleName()+"."+field.getName();
- valueFromPropertyManager = propertyManager.getProperty(propertyFileKey);
+ valueFromProperties = properties.getProperty(propertyFileKey);
}
- if (valueFromPropertyManager == null) {
+ if (valueFromProperties == null) {
propertyFileKey = prefix+field.getName();
if(field.isAnnotationPresent(FullPropertyName.class)) {
@@ -252,12 +263,51 @@
propertyFileKey = fullPropertyName.name();
}
- valueFromPropertyManager = propertyManager.getProperty(propertyFileKey);
+ valueFromProperties = properties.getProperty(propertyFileKey);
}
- return valueFromPropertyManager;
+ return valueFromProperties;
}
+ private static void printBean(Object bean, StringBuffer buffer)
+ {
+ String lineSeparator = System.getProperty("line.separator");
+ buffer.append("Bean class: ");
+ buffer.append(bean.getClass().getCanonicalName());
+ buffer.append(lineSeparator);
+
+ for(Field field : bean.getClass().getDeclaredFields()) {
+ Class type = field.getType();
+
+ String getterMethodName;
+ Method getter = null;
+ if(field.getType().equals(Boolean.TYPE)) {
+ getterMethodName = "is"+capitalizeFirstLetter(field.getName());
+ try {
+ getter = bean.getClass().getMethod(getterMethodName, new Class[] {});
+ } catch (NoSuchMethodException e) {}
+ }
+
+ try {
+ if(getter == null) {
+ getterMethodName = "get"+capitalizeFirstLetter(field.getName());
+ getter = bean.getClass().getMethod(getterMethodName, new Class[] {});
+ }
+
+ Object valueFromBean = getter.invoke(bean, new Object[] {});
+
+ buffer.append(" ");
+ buffer.append(field.getName());
+ buffer.append(": ");
+ buffer.append(valueFromBean);
+ } catch(Exception e) {
+ buffer.append("failed to read property ");
+ buffer.append(field.getName());
+ }
+ buffer.append(lineSeparator);
+ }
+ }
+
private static String capitalizeFirstLetter(String string) {
return (string.length()>0) ? (Character.toUpperCase(string.charAt(0))+string.substring(1)) : string;
}
Modified: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/BeanPopulatorTest.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/BeanPopulatorTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/BeanPopulatorTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -18,9 +18,9 @@
// by the set of beans which wrap them and conversely that no undefined
// properties are looked for. i.e. that the Environment and Beans are in sync
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- BeanPopulator.configureFromPropertyManager(new LoggingEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new LoggingEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
@@ -33,17 +33,17 @@
expectedKeys.add("com.arjuna.common.util.logging.VisibilityLevel");
System.out.println("expected: "+expectedKeys);
- System.out.println("used: "+testManager.usedKeys);
+ System.out.println("used: "+testProperties.usedKeys);
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
@Test
public void testDefaultLogPropertiesPopulation() throws Exception {
- DummyPropertyManager testManager = new DummyPropertyManager(null);
+ DummyProperties testProperties = new DummyProperties();
- BeanPopulator.configureFromPropertyManager(new DefaultLogEnvironmentBean(), testManager);
+ BeanPopulator.configureFromProperties(new DefaultLogEnvironmentBean(), testProperties);
Set<String> expectedKeys = new HashSet<String>();
@@ -55,8 +55,8 @@
expectedKeys.add("com.arjuna.common.util.logging.default.logFile");
System.out.println("expected: "+expectedKeys);
- System.out.println("used: "+testManager.usedKeys);
+ System.out.println("used: "+testProperties.usedKeys);
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
\ No newline at end of file
Added: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyProperties.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyProperties.java (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyProperties.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, 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) 2009,
+ * @author JBoss, a division of Red Hat.
+ */
+package com.arjuna.common.tests.simple;
+
+import com.arjuna.common.internal.util.propertyservice.ConcatenationPrefix;
+
+import java.util.*;
+import java.lang.reflect.Field;
+
+/**
+ * Dummy Properties handler for EnvironmentBean test purposes.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com) 2009-10
+ */
+public class DummyProperties extends Properties
+{
+ public DummyProperties() {
+ super();
+ }
+
+ public DummyProperties(Properties properties) {
+ super(properties);
+ }
+
+ public static Set<String> extractKeys(Class environment) throws IllegalAccessException {
+
+ Set<String> keys = new HashSet<String>();
+
+ for(Field field : environment.getDeclaredFields()) {
+ String key = (String)field.get(null);
+
+ if(field.isAnnotationPresent(Deprecated.class)) {
+ continue;
+ }
+
+ keys.add(key);
+ }
+
+ return keys;
+ }
+
+ public void addConcatenationKeys(Class environmentBean) {
+
+ for(Field field : environmentBean.getDeclaredFields()) {
+ if(field.isAnnotationPresent(ConcatenationPrefix.class)) {
+ String prefix = field.getAnnotation(ConcatenationPrefix.class).prefix();
+ concatenationKeys.add(prefix);
+ System.out.println("addConcat : "+prefix);
+ }
+ }
+ }
+
+ @Override
+ public String getProperty(String key)
+ {
+ for(String prefix : concatenationKeys) {
+ if(key.startsWith(prefix) && !usedKeys.contains(prefix)) {
+ usedKeys.add(prefix);
+ break;
+ }
+ }
+
+ usedKeys.add(key);
+
+ return super.getProperty(key);
+ }
+
+ @Override
+ public Enumeration propertyNames()
+ {
+ Vector<String> names = new Vector<String>();
+ for(String prefix : concatenationKeys) {
+ names.add(prefix+"_one");
+ names.add(prefix+"_two");
+ }
+ return names.elements();
+ }
+
+ public Set<String> usedKeys = new HashSet<String>();
+ public Set<String> concatenationKeys = new HashSet<String>();
+}
Deleted: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyPropertyManager.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyPropertyManager.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyPropertyManager.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -1,149 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, 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) 2009,
- * @author JBoss, a division of Red Hat.
- */
-package com.arjuna.common.tests.simple;
-
-import com.arjuna.common.util.propertyservice.PropertyManager;
-import com.arjuna.common.util.propertyservice.plugins.PropertyManagementPlugin;
-import com.arjuna.common.util.exceptions.LoadPropertiesException;
-import com.arjuna.common.util.exceptions.SavePropertiesException;
-import com.arjuna.common.util.exceptions.ManagementPluginException;
-import com.arjuna.common.internal.util.propertyservice.ConcatenationPrefix;
-
-import java.util.*;
-import java.lang.reflect.Field;
-import java.io.IOException;
-
-/**
- * Basic PropertyManager impl for BeanPopulator for test purposes
- *
- * @author Jonathan Halliday (jonathan.halliday at redhat.com)
- */
-public class DummyPropertyManager implements PropertyManager
-{
- public static Set<String> extractKeys(Class environment) throws IllegalAccessException {
-
- Set<String> keys = new HashSet<String>();
-
- for(Field field : environment.getDeclaredFields()) {
- String key = (String)field.get(null);
-
- if(field.isAnnotationPresent(Deprecated.class)) {
- continue;
- }
-
- keys.add(key);
- }
-
- return keys;
- }
-
- public void addConcatenationKeys(Class environmentBean) {
-
- for(Field field : environmentBean.getDeclaredFields()) {
- if(field.isAnnotationPresent(ConcatenationPrefix.class)) {
- String prefix = field.getAnnotation(ConcatenationPrefix.class).prefix();
- concatenationKeys.add(prefix);
- System.out.println("addConcat : "+prefix);
- }
- }
- }
-
- public Set<String> usedKeys = new HashSet<String>();
- Properties properties = null;
- public Set<String> concatenationKeys = new HashSet<String>();
-
- public DummyPropertyManager(Properties properties) {
- this.properties = properties;
- }
-
- public String getProperty(String key)
- {
- for(String prefix : concatenationKeys) {
- if(key.startsWith(prefix) && !usedKeys.contains(prefix)) {
- usedKeys.add(prefix);
- break;
- }
- }
-
- usedKeys.add(key);
-
- if(properties != null) {
- return properties.getProperty(key);
- } else {
- return null;
- }
- }
-
- public String getProperty(String s, String s1)
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public String setProperty(String s, String s1, boolean b)
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public String setProperty(String s, String s1)
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public String removeProperty(String s)
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public Properties getProperties()
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public Enumeration propertyNames()
- {
- Vector<String> names = new Vector<String>();
- for(String prefix : concatenationKeys) {
- names.add(prefix+"_one");
- names.add(prefix+"_two");
- }
- return names.elements();
- }
-
- public void load(String s, String s1) throws IOException, ClassNotFoundException, LoadPropertiesException
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public void save(String s, String s1) throws IOException, ClassNotFoundException, SavePropertiesException
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public void addManagementPlugin(PropertyManagementPlugin propertyManagementPlugin) throws IOException, ManagementPluginException
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-
- public boolean verbose()
- {
- throw new RuntimeException("this is not expected to be called during the test");
- }
-}
\ No newline at end of file
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 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -40,11 +40,11 @@
// check that a bean is populated correctly by the BeanPopulator
DummyEnvironmentBean testBean = new DummyEnvironmentBean();
- DummyPropertyManager testManager = new DummyPropertyManager(testBean.getProperties());
- BeanPopulator.configureFromPropertyManager(testBean, testManager);
+ DummyProperties testProperties = new DummyProperties(testBean.getProperties());
+ BeanPopulator.configureFromProperties(testBean, testProperties);
Set<Object> expectedKeys = testBean.getProperties().keySet();
- assertTrue( testManager.usedKeys.containsAll(expectedKeys) );
+ assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
}
}
Deleted: labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/CSFToolTest.java
===================================================================
--- labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/CSFToolTest.java 2009-10-20 11:50:07 UTC (rev 29685)
+++ labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/CSFToolTest.java 2009-10-20 12:32:22 UTC (rev 29686)
@@ -1,229 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, 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) 2005-2006,
- * @author JBoss Inc.
- */
-/*
- # Copyright (C) 2001,
- #
- # Hewlett-Packard Company,
- # Newcastle upon Tyne,
- # Tyne and Wear,
- # UK.
-*/
-
-package org.jboss.jbossts.qa.Utils;
-
-import com.arjuna.ats.arjuna.common.Configuration;
-import com.arjuna.ats.arjuna.common.Environment;
-import com.arjuna.ats.arjuna.recovery.RecoveryConfiguration;
-
-import java.io.*;
-
-public class CSFToolTest
-{
- public static void main(String[] args)
- {
- new CSFToolTest(args);
- }
-
- /**
- * We may run into problems with the recovery manager file because we have not started the
- * process and so not loaded in the recovery properties.
- */
- public CSFToolTest(String[] args)
- {
- //first init orb to load properties
- try
- {
- ORBInterface.initORB(args, null);
- OAInterface.initOA();
- }
- catch (Exception e)
- {
- mCorrect = false;
- System.err.println("Exception in init: " + e);
- e.printStackTrace(System.err);
- }
-
- // now get values from static variables
-
- String mTSPropFile = System.getProperty(Environment.PROPERTIES_FILE);
- if (mTSPropFile == null)
- {
- mTSPropFile = Configuration.propertiesDir() + File.separator + Configuration.propertiesFile();
- }
-
- //we may have problems here
- String mTSRecPropFile = RecoveryConfiguration.recoveryManagerPropertiesFile();
-
- System.err.println("prop1 = " + mTSPropFile);
- System.err.println("prop2 = " + mTSRecPropFile);
-
- //create first config file
- mComand = "java PropertyFile2XML -file " + mTSPropFile + " -xml " + sPropFileName;
- System.err.println("running 1");
- System.err.println(mComand);
- runComand();
-
- //create second config file
- mComand = "java PropertyFile2XML -file " + mTSRecPropFile + " -xml " + sRecPropFileName;
- System.err.println("running 2");
- System.err.println(mComand);
- runComand();
-
- //now check file exist
- File f = new File(sPropFileName);
- if (!f.exists())
- {
- System.err.println(sPropFileName + "file does not exist");
- mCorrect = false;
- }
-
- f = new File(sRecPropFileName);
- if (!f.exists())
- {
- System.err.println(sRecPropFileName + "file does not exist");
- mCorrect = false;
- }
-
- try
- {
- OAInterface.shutdownOA();
- ORBInterface.shutdownORB();
- }
- catch (Exception exception)
- {
- mCorrect = false;
- System.err.println("Exception in shutdown: " + exception);
- exception.printStackTrace(System.err);
- }
-
- if (mCorrect)
- {
- System.out.println("Passed");
- }
- else
- {
- System.out.println("Failed");
- }
-
- }
-
- public void runComand()
- {
- try
- {
- mProcess = Runtime.getRuntime().exec(mComand);
- }
- catch (OutOfMemoryError ome)
- {
- System.out.println("Out of memeory end test = " + ome);
- }
- catch (IOException io)
- {
- mCorrect = false;
- System.out.println("runtime exception " + io);
- }
- outputToDisplay();
- }
-
- public void outputToDisplay()
- {
- Thread mOutReader = new Thread()
- {
- public void run()
- {
- try
- {
- BufferedReader br = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
- String line = br.readLine();
- while ((!isInterrupted() && line != null))
- {
- line = line.trim();
- writeToLog(line, true);
- line = br.readLine();
- }
- }
- catch (InterruptedIOException e)
- {
- }
- catch (Exception e)
- {
- }
- }
- };
-
- Thread mErrReader = new Thread()
- {
- public void run()
- {
- try
- {
- BufferedReader br = new BufferedReader(new InputStreamReader(mProcess.getErrorStream()));
- String line = br.readLine();
- while ((!isInterrupted() && line != null))
- {
- line = line.trim();
- writeToLog(line, false);
- line = br.readLine();
- }
- }
- catch (InterruptedIOException e)
- {
- }
- catch (Exception e)
- {
- }
- }
- };
-
- mOutReader.start();
- mErrReader.start();
-
- try
- {
- System.err.println("waiting for process to complete");
- mProcess.waitFor();
- }
- catch (Exception e)
- {
- mCorrect = false;
- System.out.println("process exception");
- }
- }
-
- public void writeToLog(String s, boolean b)
- {
- if (b)
- {
- System.out.println(s);
- }
- else
- {
- System.err.println(s);
- }
- }
-
-
- private Process mProcess;
- private String mComand;
- private boolean mCorrect = true;
- private static String sPropFileName = "arjuna.config";
- private static String sRecPropFileName = "arjuna_recovery.config";
-}
More information about the jboss-svn-commits
mailing list