[jboss-svn-commits] JBL Code SVN: r31009 - in labs/jbosstm/trunk/common: classes/com/arjuna/common/internal/util/logging/basic and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jan 11 05:44:57 EST 2010


Author: jhalliday
Date: 2010-01-11 05:44:56 -0500 (Mon, 11 Jan 2010)
New Revision: 31009

Added:
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/DebugExt.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/ExerciseLoggerImpls.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/TestLevels.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/logi18n.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/propertyservice/
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/propertyservice/StringPropertyReplacerUnitTestCase.java
Removed:
   labs/jbosstm/trunk/common/tests/TestReadme.txt
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/util/
   labs/jbosstm/trunk/common/tests/com/hp/mwtests/commonlogging/
Modified:
   labs/jbosstm/trunk/common/build.xml
   labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/logging/basic/BasicLog.java
   labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/propertyservice/BeanPopulator.java
   labs/jbosstm/trunk/common/classes/com/arjuna/common/util/FileLocator.java
   labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/LogFactory.java
   labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/VisibilityLevel.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyEnvironmentBean.java
   labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java
Log:
Improve unit tests for common module. JBTM-685


Modified: labs/jbosstm/trunk/common/build.xml
===================================================================
--- labs/jbosstm/trunk/common/build.xml	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/build.xml	2010-01-11 10:44:56 UTC (rev 31009)
@@ -29,7 +29,7 @@
     <target name="run.tests">
 
         <javadoc sourcepath="${tests.dir}"
-                 packagenames="com.hp.mwtests.commonlogging.testlevels"
+                 packagenames="com.arjuna.common.tests.logging"
                  failonerror="yes"
                  private="yes"
                  defaultexcludes="yes">
@@ -51,35 +51,10 @@
         </copy>
 
         <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/TestLevels.java"/></tests>
+            <tests>
+                <fileset dir="tests" includes="**/*.java" excludes="**/Dummy*.java"/>
+            </tests>
         </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/logi18n.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/DebugExt.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/SetPropertyTest.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/PropertiesTest.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/SimpleTest.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/SystemPropertyTest.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/IOTest.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/EnvironmentBeanTest.java"/></tests>
-        </run.tests.macro>
-        <run.tests.macro>
-            <tests><fileset dir="tests" includes="**/BeanPopulatorTest.java"/></tests>
-        </run.tests.macro>
 
         <emma enabled="${emma.enabled}">
             <report>

Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/logging/basic/BasicLog.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/logging/basic/BasicLog.java	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/logging/basic/BasicLog.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -86,28 +86,12 @@
 {
     // ------------------------------------------------------- Class Attributes
 
-    /** Properties loaded from simplelog.properties */
-    static protected final Properties simpleLogProps = new Properties();
-
     /** The default format to use when formating dates */
     static protected final String DEFAULT_DATE_TIME_FORMAT =
         "yyyy/MM/dd HH:mm:ss:SSS zzz";
 
-    /** Include the instance name in the log message? */
-    static protected boolean showLogName = false;
-    /** Include the short name ( last component ) of the logger in the log
-     *  message. Defaults to true - otherwise we'll be lost in a flood of
-     *  messages without knowing who sends them.
-     */
-    static protected boolean showShortName = true;
-    /** Include the current time in the log message */
-    static protected boolean showDateTime = true;
-    /** The date and time format to use in the log message */
-    static protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
-    /** Used to format times */
-    static protected DateFormat dateFormatter = null;
-
     static PrintStream defaultLogFile = null;
+    static String defaultFileName = null;
 
     // ---------------------------------------------------- Log Level Constants
 
@@ -136,18 +120,23 @@
     // Initialize class attributes.
     // Load properties file, if found.
     // Override with system properties.
-    static {
+    private void initializeDefaultLog() {
 
-        showLogName = commonPropertyManager.getBasicLogEnvironmentBean().isShowLogName();
-        showShortName = commonPropertyManager.getBasicLogEnvironmentBean().isShowShortLogName();
-        showDateTime = commonPropertyManager.getBasicLogEnvironmentBean().isShowDate();
-        dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS zzz");
+        if(defaultLogFile != null) {
+            return;
+        }
 
-        String fileName = commonPropertyManager.getBasicLogEnvironmentBean().getLogFile();
+        defaultFileName = commonPropertyManager.getBasicLogEnvironmentBean().getLogFile();
         boolean fileAppend = commonPropertyManager.getBasicLogEnvironmentBean().isLogFileAppend();
         try {
-            FileOutputStream fOut = new FileOutputStream(fileName, fileAppend);
-            defaultLogFile = new PrintStream(fOut, true);
+
+            if(defaultFileName == null) {
+                defaultLogFile = System.out;
+            } else {
+                FileOutputStream fOut = new FileOutputStream(defaultFileName, fileAppend);
+                defaultLogFile = new PrintStream(fOut, true);
+            }
+
             defaultLogFile.println();
             defaultLogFile.println();
             defaultLogFile.println("---------------------------------------------------------------");
@@ -156,7 +145,7 @@
         }
         catch (Exception e)
         {
-            System.err.println("cannot set up default log for error messages to file " + fileName + ": " + e.getMessage());
+            System.err.println("cannot set up default log for error messages to file " + defaultFileName + ": " + e.getMessage());
             e.printStackTrace();
         }
     }
@@ -171,6 +160,19 @@
     /** The short name of this simple log instance */
     private String shortLogName = null;
 
+    /** Include the instance name in the log message? */
+    protected boolean showLogName = false;
+    /** Include the short name ( last component ) of the logger in the log
+     *  message. Defaults to true - otherwise we'll be lost in a flood of
+     *  messages without knowing who sends them.
+     */
+    protected boolean showShortName = true;
+    /** Include the current time in the log message */
+    protected boolean showDateTime = true;
+    /** The date and time format to use in the log message */
+    protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
+    /** Used to format times */
+    protected DateFormat dateFormatter = null;
 
     // ------------------------------------------------------------ Constructor
 
@@ -181,6 +183,11 @@
      */
     public BasicLog(String name) {
 
+        showLogName = commonPropertyManager.getBasicLogEnvironmentBean().isShowLogName();
+        showShortName = commonPropertyManager.getBasicLogEnvironmentBean().isShowShortLogName();
+        showDateTime = commonPropertyManager.getBasicLogEnvironmentBean().isShowDate();
+        dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS zzz");
+
         logName = name;
 
         // Set initial log level
@@ -209,6 +216,7 @@
             setLevel(BasicLog.LOG_LEVEL_OFF);
         }
 
+        initializeDefaultLog();
     }
 
 

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	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/internal/util/propertyservice/BeanPopulator.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -129,6 +129,12 @@
         }
     }
 
+    public static String printBean(Object bean) {
+        StringBuffer buffer = new StringBuffer();
+        printBean(bean, buffer);
+        return buffer.toString();
+    }    
+
     /**
      * Render the state of the known bean instances as text.
      */

Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/FileLocator.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/FileLocator.java	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/FileLocator.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -114,47 +114,6 @@
    }
 
    /**
-    * Locate the specific file.
-    * Return the file name in URL form or null.
-    */
-   public static URL locateURL (String findFile) throws FileNotFoundException
-   {
-      URL url;
-      String fullPathName;
-
-      if (findFile == null)
-         throw new FileNotFoundException("locateURL: null file name");
-
-      try {
-         if (findFile.startsWith(absolutePath))
-         {
-            return (new URL("file:/" + findFile.substring(absolutePath.length())));
-         }
-
-         if ((fullPathName = locateByProperty(findFile)) != null)
-         {
-            if(platformIsWindows())
-               url = new URL("file:/" + fullPathName);
-            else
-               url = new URL("file:" + fullPathName);
-            return url;
-         }
-         //TODO: TR: used for testing:  return new URL(findFile);
-      }
-      catch (MalformedURLException e)
-      {
-         System.err.println("locateURL: URL creation problem");
-         FileNotFoundException exception = new FileNotFoundException("locateURL: URL creation problem");
-         exception.initCause(e);
-         throw exception;
-      }
-      if ((url = locateByResource(findFile)) != null)
-         return url;
-
-      throw new FileNotFoundException("locateURL: file not found: " + findFile);
-   }
-
-   /**
     * Search for a file using the properties: user.dir, user.home, java.home
     * Returns absolute path name or null.
     */

Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/LogFactory.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/LogFactory.java	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/LogFactory.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -164,6 +164,10 @@
         return log;
     }
 
+    public static synchronized void reset() {
+        m_isInitialized = false;
+    }
+
     /**
      * set up the log subsystem to use.
      */

Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/VisibilityLevel.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/VisibilityLevel.java	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/logging/VisibilityLevel.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -95,8 +95,6 @@
          sLevel = ((sLevel == null) ? "VIS_PUBLIC" : " & VIS_PUBLIC");
       if ((level & VIS_PACKAGE) != 0)
          sLevel = ((sLevel == null) ? "VIS_PACKAGE" : " & VIS_PACKAGE");
-      if ((level & VisibilityLevel.VIS_ALL) != 0)
-         sLevel = ((sLevel == null) ? "VIS_ALL" : " & VIS_ALL");
 
       return ((sLevel == null) ? "VIS_NONE" : sLevel);
    }

Deleted: labs/jbosstm/trunk/common/tests/TestReadme.txt
===================================================================
--- labs/jbosstm/trunk/common/tests/TestReadme.txt	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/tests/TestReadme.txt	2010-01-11 10:44:56 UTC (rev 31009)
@@ -1,86 +0,0 @@
-JBoss, Home of Professional Open Source
-Copyright 2006, 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,
- at author JBoss Inc.
-
-1- Description:
----------------
-The tests directory provide a set of programs allowing to test features of the Common Logging Framework.
-Each Subdirectory provides its own Readme file explaining the aim of the test program and how to run it.
-
-Basically each program is execute using the following template.
-
-   prompt> java [-DLogFac=<log_name>] [-Doutput=<output_name>] [-Dlanguage=<language_name>] \
-	   [-Dcountry=<country_name>] [-Dlogfile=<file_name>] <java_program>
-
-	   where:
-	   ----------------------------------------------------------------------------------
-           []  : The property is Optional 
-
-	   <log_name>	  : CSFLOG or LOG4J	-	The default is CFSLOG
-	   <output_name>  : console or file	-	The default is console
-	   <language_name>: fr, en, ...		-	The default is en
-	   <country_name> : EN, FR, ...		-	The default is US
-
-	   <file_name>	  : The name given to the output file
-			    The way the name is used in HP CSF logging and LOG4j is different.
-			    - Log4j:
-			      The Default name given for the output file is "transaction.tlog",
-			      which can be changed by the <file_name> if provided.
-			    - CSF Log
-			      The Default name given for the output file is LOGactive.log. 
-			      If provided, <file_name> replaces only the suffix LOG.
-			      This default will be corrected in a next version.
-			     
-           <java_program> : The java class
-
-
-
-2- Important Note
------------------
-The Common Logging Framework provides a set of Levels defining the importance of a logging message.
-The provided default Levels and their corresponding underlying values are given below:
-
-    CommonLevel	     Log4j	HP log
-    -----------	     -----	------
-    FATAL	     FATAL	CRITICAL
-    ERROR	     ERROR	ERROR
-    WARN	     WARN	WARNING
-    INFO	     INFO	INFO
-    DEBUG	     DEBUG	DEBUG	
-
-When requested to be sent to an output (console, file, ...), a logging message associated with
-a CommonLevel is currently displayed or provided to the output with its corresponding underlying
-value. That is, when using the common Logging Framework on top of HP log, the developer should
-be aware that the CommonLevel FATAL will be displayed as a CRITICAL level. 
-
-A next release of the Common Logging Framework will sent a same value. A new HP LogFormater will
-be provided.
-
-For each CommonLevel the corresponding value that will be displayed with the current version are
-given below:
-
-    CommonLevel	     Log4j	HP log
-    -----------	     -----	------
-    FATAL	     FATAL	C
-    ERROR	     ERROR	E
-    WARN	     WARN	W
-    INFO	     INFO	I
-    DEBUG	     DEBUG	D	
-
-
-

Copied: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/DebugExt.java (from rev 30955, labs/jbosstm/trunk/common/tests/com/hp/mwtests/commonlogging/debugextension/DebugExt.java)
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/DebugExt.java	                        (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/DebugExt.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.
+ */
+package com.arjuna.common.tests.logging;
+
+import com.arjuna.common.internal.util.logging.LoggingEnvironmentBean;
+import com.arjuna.common.util.logging.*;
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+public class DebugExt
+{
+    @Test
+    public void testDebugExt()
+    {
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        PrintStream bufferedStream = new PrintStream(buffer);
+        PrintStream originalStream = System.out;
+
+        LoggingEnvironmentBean loggingEnvironmentBean = commonPropertyManager.getLoggingEnvironmentBean();
+        String originalFactory = loggingEnvironmentBean.getLoggingFactory();
+        String originalDebugLevel = loggingEnvironmentBean.getDebugLevel();
+        String originalVisibilityLevel = loggingEnvironmentBean.getVisibilityLevel();
+        String originalFacilityLevel = loggingEnvironmentBean.getFacilityLevel();
+
+        loggingEnvironmentBean.setLoggingFactory("com.arjuna.common.internal.util.logging.jakarta.JakartaLogFactory;com.arjuna.common.internal.util.logging.jakarta.Log4JLogger");
+        loggingEnvironmentBean.setDebugLevel("0x"+Long.toString(DebugLevel.FUNCS_AND_OPS, 16));
+        loggingEnvironmentBean.setVisibilityLevel("0x"+Long.toString(VisibilityLevel.VIS_PACKAGE, 16));
+        loggingEnvironmentBean.setFacilityLevel("0xffffffff"); // FacilityCode.FAC_ALL - Long.toString does the wrong thing.
+
+		System.setOut(bufferedStream);
+        LogFactory.reset(); // make sure it reloads the modified config.
+
+        try {
+    		writeLogMessages();
+        } finally {
+            loggingEnvironmentBean.setLoggingFactory(originalFactory);
+            loggingEnvironmentBean.setDebugLevel(originalDebugLevel);
+            loggingEnvironmentBean.setVisibilityLevel(originalVisibilityLevel);
+            loggingEnvironmentBean.setFacilityLevel(originalFacilityLevel);
+            System.setOut(originalStream);
+            LogFactory.reset();
+        }
+		verifyResult(buffer.toString());
+    }
+
+    private static void writeLogMessages()
+    {
+        LogNoi18n myNoi18nLog = LogFactory.getLogNoi18n("DebugExt");
+
+        myNoi18nLog.debug(DebugLevel.FUNCS_AND_OPS, VisibilityLevel.VIS_PACKAGE, FacilityCode.FAC_ALL,
+                "This debug message is enabled since it matches default Finer Values");
+
+        myNoi18nLog.debug(DebugLevel.CONSTRUCT_AND_DESTRUCT, VisibilityLevel.VIS_PACKAGE, FacilityCode.FAC_ALL,
+                "This debug message is discarded since it does'nt match default Finer Values");
+
+        myNoi18nLog.debug(DebugLevel.FULL_DEBUGGING, VisibilityLevel.VIS_PACKAGE, FacilityCode.FAC_ALL,
+                "This debug message is enabled since it the Logger allows full debugging");
+    }
+
+    private static void verifyResult(String result) {
+        String[] lines = result.split("\r?\n");
+
+        assertNotNull(lines);
+        assertEquals(2, lines.length);
+
+        assertTrue("Got actual value: "+lines[0], lines[0].matches("\\s*DEBUG \\[main\\] .*enabled.*"));
+        assertTrue("Got actual value: "+lines[1], lines[1].matches("\\s*DEBUG \\[main\\] .*enabled.*"));
+    }
+}

Added: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/ExerciseLoggerImpls.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/ExerciseLoggerImpls.java	                        (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/ExerciseLoggerImpls.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -0,0 +1,178 @@
+/*
+ * 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.arjuna.common.tests.logging;
+
+import com.arjuna.common.internal.util.logging.LoggingEnvironmentBean;
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
+import com.arjuna.common.util.logging.LogFactory;
+import com.arjuna.common.util.logging.LogNoi18n;
+import com.arjuna.common.util.logging.Logi18n;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Locale;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Verify logger classes produce the expected output.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com) 2010-01
+ */
+public class ExerciseLoggerImpls
+{
+    private static final String CLASS = ExerciseLoggerImpls.class.getName();
+    
+    @Test
+    public void testJakartaLog4j() {
+        testWithFactory("com.arjuna.common.internal.util.logging.jakarta.JakartaLogFactory;com.arjuna.common.internal.util.logging.jakarta.Log4JLogger", 0);
+    }
+
+    @Test
+    public void testBasicLog() {
+
+        commonPropertyManager.getBasicLogEnvironmentBean().setLogFile(null);
+        commonPropertyManager.getBasicLogEnvironmentBean().setLevel("debug");
+        testWithFactory("com.arjuna.common.internal.util.logging.basic.BasicLogFactory", 5);
+    }
+
+	private void testWithFactory(String factory, int skipHeaderLines) {
+		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+		PrintStream bufferedStream = new PrintStream(buffer);
+		PrintStream originalStream = System.out;
+
+        LoggingEnvironmentBean loggingEnvironmentBean = commonPropertyManager.getLoggingEnvironmentBean();
+        String originalFactory = loggingEnvironmentBean.getLoggingFactory();
+        String originalDebugLevel = loggingEnvironmentBean.getDebugLevel();
+        Locale originalLocale = Locale.getDefault();
+
+        loggingEnvironmentBean.setLoggingFactory(factory);
+        loggingEnvironmentBean.setDebugLevel("0xffffffff");
+
+		System.setOut(bufferedStream);
+        LogFactory.reset(); // make sure it reloads the modified config.
+
+        try {
+
+            Locale.setDefault(new Locale("en", "US"));
+
+            Logi18n logi18n = LogFactory.getLogi18n(CLASS, "logging_msg");
+    		generateTestOutput(logi18n);
+
+            LogNoi18n logNoi18n = LogFactory.getLogNoi18n("loggingtest");
+            generateTestOutput(logNoi18n);
+
+        } finally {
+            loggingEnvironmentBean.setLoggingFactory(originalFactory);
+            loggingEnvironmentBean.setDebugLevel(originalDebugLevel);
+            Locale.setDefault(originalLocale);
+            System.setOut(originalStream);
+            LogFactory.reset();
+        }
+		verifyResult(buffer.toString(), skipHeaderLines);
+
+	}
+
+    private void generateTestOutput(Logi18n logi18n) {
+        logi18n.debug("debug_message");
+        logi18n.debug("debug_message", (Throwable)null);
+        logi18n.debug("debug_param_message", new Object[] {"one", "two"});
+        logi18n.debug("debug_param_message", new Object[] {"one", "two"}, null);
+
+        logi18n.info("info_message");
+        logi18n.info("info_message", (Throwable)null);
+        logi18n.info("info_param_message", new Object[] {"one", "two"});
+        logi18n.info("info_param_message", new Object[] {"one", "two"}, null);
+
+        logi18n.warn("warn_message");
+        logi18n.warn("warn_message", (Throwable)null);
+        logi18n.warn("warn_param_message", new Object[] {"one", "two"});
+        logi18n.warn("warn_param_message", new Object[] {"one", "two"}, null);
+
+        logi18n.error("error_message");
+        logi18n.error("error_message", (Throwable)null);
+        logi18n.error("error_param_message", new Object[] {"one", "two"});
+        logi18n.error("error_param_message", new Object[] {"one", "two"}, null);
+
+        logi18n.fatal("fatal_message");
+        logi18n.fatal("fatal_message", (Throwable)null);
+        logi18n.fatal("fatal_param_message", new Object[] {"one", "two"});
+        logi18n.fatal("fatal_param_message", new Object[] {"one", "two"}, null);
+
+    }
+
+    private void generateTestOutput(LogNoi18n logNoi18n) {
+        
+    }
+
+    private void verifyResult(String result, int skipHeaderLines) {
+        String[] lines = result.split("\r?\n");
+
+        if(skipHeaderLines > 0) {
+            lines = Arrays.copyOfRange(lines, skipHeaderLines, lines.length);
+        }
+
+        String[][] expected = new String[][] {
+                {"DEBUG", "This is a debug message"},
+                {"DEBUG", "This is a debug message"},
+                {"DEBUG", "This is a debug message with params one and two"},
+                {"DEBUG", "This is a debug message with params one and two"},
+
+                {"INFO", "This is a info message"},
+                {"INFO", "This is a info message"},
+                {"INFO", "This is a info message with params one and two"},
+                {"INFO", "This is a info message with params one and two"},
+
+                {"WARN", "This is a warn message"},
+                {"WARN", "This is a warn message"},
+                {"WARN", "This is a warn message with params one and two"},
+                {"WARN", "This is a warn message with params one and two"},
+                
+                {"ERROR", "This is a error message"},
+                {"ERROR", "This is a error message"},
+                {"ERROR", "This is a error message with params one and two"},
+                {"ERROR", "This is a error message with params one and two"},
+                
+                {"FATAL", "This is a fatal message"},
+                {"FATAL", "This is a fatal message"},
+                {"FATAL", "This is a fatal message with params one and two"},
+                {"FATAL", "This is a fatal message with params one and two"}
+                
+                
+
+        };
+
+        assertNotNull(lines);
+
+        for(String line : lines) {
+            System.out.println("LINE: "+line);
+        }
+
+        assertEquals(expected.length, lines.length);
+
+        for(int i = 0; i < expected.length; i++) {
+            String expectedPattern = ".*"+expected[i][0]+".*ExerciseLoggerImpls.*"+expected[i][1]+"$";
+            assertTrue("Got actual value: "+lines[i], lines[i].matches(expectedPattern));
+        }
+    }
+}

Added: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java	                        (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/LogConfig.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -0,0 +1,104 @@
+/*
+ * 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.arjuna.common.tests.logging;
+
+import com.arjuna.common.internal.util.logging.LoggingEnvironmentBean;
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
+import com.arjuna.common.util.exceptions.LogConfigurationException;
+import com.arjuna.common.util.logging.*;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Exercise assorted logging configuration options, particularly the Debug, Facility and Visibility filters.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com) 2010-01
+ */
+public class LogConfig
+{
+    @Test
+    public void testDebugLevels() {
+
+        DebugLevel d = new DebugLevel();
+        assertEquals(DebugLevel.NO_DEBUGGING, d.getLevel(d.printString(DebugLevel.NO_DEBUGGING)));
+        assertEquals(DebugLevel.CONSTRUCTORS, d.getLevel(d.printString(DebugLevel.CONSTRUCTORS)));
+        assertEquals(DebugLevel.DESTRUCTORS, d.getLevel(d.printString(DebugLevel.DESTRUCTORS)));
+
+        assertEquals(DebugLevel.FUNCTIONS, d.getLevel(d.printString(DebugLevel.FUNCTIONS)));
+        assertEquals(DebugLevel.OPERATORS, d.getLevel(d.printString(DebugLevel.OPERATORS)));
+
+
+        assertEquals(DebugLevel.TRIVIAL_FUNCS, d.getLevel(d.printString(DebugLevel.TRIVIAL_FUNCS)));
+        assertEquals(DebugLevel.TRIVIAL_OPERATORS, d.getLevel(d.printString(DebugLevel.TRIVIAL_OPERATORS)));
+
+        assertEquals(DebugLevel.ERROR_MESSAGES, d.getLevel(d.printString(DebugLevel.ERROR_MESSAGES)));
+        assertEquals(DebugLevel.FULL_DEBUGGING, d.getLevel(d.printString(DebugLevel.FULL_DEBUGGING)));
+    }
+
+    @Test
+    public void testFacilityCode() {
+
+        FacilityCode facilityCode = new FacilityCode();
+        assertEquals(FacilityCode.FAC_NONE, facilityCode.getLevel(facilityCode.printString(FacilityCode.FAC_NONE)));
+        assertEquals(FacilityCode.FAC_ALL, facilityCode.getLevel(facilityCode.printString(FacilityCode.FAC_ALL)));
+    }
+
+    @Test
+    public void testVisibilityLevel() {
+
+        VisibilityLevel visibilityLevel = new VisibilityLevel();
+        assertEquals(VisibilityLevel.VIS_NONE, visibilityLevel.getLevel(visibilityLevel.printString(VisibilityLevel.VIS_NONE)));
+
+        System.out.println(""+VisibilityLevel.VIS_PRIVATE);
+        System.out.println(visibilityLevel.printString(VisibilityLevel.VIS_PRIVATE));
+        System.out.printf(""+visibilityLevel.getLevel("VIS_PRIVATE"));
+
+        assertEquals(VisibilityLevel.VIS_PRIVATE, visibilityLevel.getLevel(visibilityLevel.printString(VisibilityLevel.VIS_PRIVATE)));
+        assertEquals(VisibilityLevel.VIS_PROTECTED, visibilityLevel.getLevel(visibilityLevel.printString(VisibilityLevel.VIS_PROTECTED)));
+        assertEquals(VisibilityLevel.VIS_PUBLIC, visibilityLevel.getLevel(visibilityLevel.printString(VisibilityLevel.VIS_PUBLIC)));
+        assertEquals(VisibilityLevel.VIS_PACKAGE, visibilityLevel.getLevel(visibilityLevel.printString(VisibilityLevel.VIS_PACKAGE)));
+        assertEquals(VisibilityLevel.VIS_ALL, visibilityLevel.getLevel(visibilityLevel.printString(VisibilityLevel.VIS_ALL)));
+    }
+
+    @Test
+    public void testBadFactory() {
+
+        LoggingEnvironmentBean loggingEnvironmentBean = commonPropertyManager.getLoggingEnvironmentBean();
+        String originalFactory = loggingEnvironmentBean.getLoggingFactory();
+
+        loggingEnvironmentBean.setLoggingFactory("bogusFactory");
+        LogFactory.reset();
+
+        try {
+             // should throw LogConfigurationException
+            LogNoi18n logNoi18n = LogFactory.getLogNoi18n("test");
+            fail("should not reach here");
+        } catch(RuntimeException e) {
+            // expected
+            assertTrue(e.getCause() instanceof LogConfigurationException);
+        } finally {
+            loggingEnvironmentBean.setLoggingFactory(originalFactory);
+            LogFactory.reset();
+        }
+
+    }
+}

Copied: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/TestLevels.java (from rev 30955, labs/jbosstm/trunk/common/tests/com/hp/mwtests/commonlogging/testlevels/TestLevels.java)
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/TestLevels.java	                        (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/TestLevels.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.
+ */
+package com.arjuna.common.tests.logging;
+
+import com.arjuna.common.internal.util.logging.LoggingEnvironmentBean;
+import com.arjuna.common.util.logging.Logi18n;
+import com.arjuna.common.util.logging.LogFactory;
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+
+/**
+ * JUnit test that verifies log statements made through the CLF appear at the expected log level.
+ * It does this by replacing System.out with a memory backed buffer, writing some log messages
+ * and then checking the buffer contents for the expected regexps.
+ *
+ * Note: due to the way logging is initialized, this is somewhat fragile.
+ */
+public class TestLevels
+{
+   /**
+    * for logging purposes.
+    */
+   private static final String CLASS = TestLevels.class.getName();
+
+   /**
+    *
+    * @message testMessage This is the {0} message, logged at level {1}.
+    *
+    * @param args
+    */
+   public static void main(String[] args)
+   {
+	   // CommonLogging-properties.xml: <common><properties><property name= value=>
+	   // cd common/install/lib
+	   // java -cp jbossts-common.jar:tests/common_tests.jar:../../../ext/commons-logging.jar:../../../ext/log4j-1.2.8.jar:../../etc/ com.hp.mwtests.commonlogging.testlevels.TestLevels
+//	   junit.textui.TestRunner.run(suite());
+	}
+
+//	public static Test suite() {
+//		return new TestSuite(TestLevels.class);
+//	}
+
+
+    @Test
+	public void testLog4j() {
+		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+		PrintStream bufferedStream = new PrintStream(buffer);
+		PrintStream originalStream = System.out;
+
+        LoggingEnvironmentBean loggingEnvironmentBean = commonPropertyManager.getLoggingEnvironmentBean();
+        String originalFactory = loggingEnvironmentBean.getLoggingFactory();
+        String originalDebugLevel = loggingEnvironmentBean.getDebugLevel();
+
+		// test the releveling for AS integration:
+        loggingEnvironmentBean.setLoggingFactory("com.arjuna.common.internal.util.logging.jakarta.JakartaRelevelingLogFactory;com.arjuna.common.internal.util.logging.jakarta.Log4JLogger");
+        loggingEnvironmentBean.setDebugLevel("0xffffffff");
+
+		System.setOut(bufferedStream);
+        LogFactory.reset(); // make sure it reloads the modified config.
+
+        try {
+    		writeLogMessages();
+        } finally {
+            loggingEnvironmentBean.setLoggingFactory(originalFactory);
+            loggingEnvironmentBean.setDebugLevel(originalDebugLevel);
+            System.setOut(originalStream);
+            LogFactory.reset();
+        }
+		verifyResult(buffer.toString(), true);
+	}
+
+	private static void writeLogMessages() {
+		// Don't init the log in a member variable - it must be done AFTER System.out is changed.
+		Logi18n log = LogFactory.getLogi18n(CLASS, "TestLevels");
+		log.debug("testMessage", new Object[] {"1st", "debug"});
+		log.info("testMessage", new Object[] {"1st", "info"});
+		log.warn("testMessage", new Object[] {"1st", "warn"});
+		log.error("testMessage", new Object[] {"1st", "error"});
+		log.fatal("testMessage", new Object[] {"1st", "fatal"});
+	}
+
+	private static void verifyResult(String result, boolean expectReleveling) {
+        String[] lines = result.split("\r?\n");
+		assertNotNull(lines);
+		assertEquals(5, lines.length);
+		assertTrue("Got actual value: "+lines[0], lines[0].matches("\\s*DEBUG \\[main\\] \\(TestLevels.java.*"));
+
+		if(expectReleveling) {
+			assertTrue("Got actual value: "+lines[1], lines[1].matches("\\s*DEBUG \\[main\\] \\(TestLevels.java.*"));
+		} else {
+			assertTrue("Got actual value: "+lines[1], lines[1].matches("\\s*INFO \\[main\\] \\(TestLevels.java.*"));
+		}
+		assertTrue("Got actual value: "+lines[2], lines[2].matches("\\s*WARN \\[main\\] \\(TestLevels.java.*"));
+		assertTrue("Got actual value: "+lines[3], lines[3].matches("\\s*ERROR \\[main\\] \\(TestLevels.java.*"));
+		assertTrue("Got actual value: "+lines[4], lines[4].matches("\\s*FATAL \\[main\\] \\(TestLevels.java.*"));
+	}
+}
+

Copied: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/logi18n.java (from rev 30955, labs/jbosstm/trunk/common/tests/com/hp/mwtests/commonlogging/i18n/logi18n.java)
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/logi18n.java	                        (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/logging/logi18n.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.
+ */
+package com.arjuna.common.tests.logging;
+
+import com.arjuna.common.internal.util.logging.LoggingEnvironmentBean;
+import com.arjuna.common.util.logging.Logi18n;
+import com.arjuna.common.util.logging.LogFactory;
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
+
+import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Tests that i18n works by outputting the same message for two different locales.
+ *
+ */
+public class logi18n
+{
+    private static final String CLASS = logi18n.class.getName();
+
+    @Test
+	public void testLogi18n() {
+		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+		PrintStream bufferedStream = new PrintStream(buffer);
+		PrintStream originalStream = System.out;
+
+        LoggingEnvironmentBean loggingEnvironmentBean = commonPropertyManager.getLoggingEnvironmentBean();
+        String originalFactory = loggingEnvironmentBean.getLoggingFactory();
+
+        commonPropertyManager.getLoggingEnvironmentBean().setLoggingFactory("com.arjuna.common.internal.util.logging.jakarta.JakartaLogFactory;com.arjuna.common.internal.util.logging.jakarta.Log4JLogger");
+
+		System.setOut(bufferedStream);
+        LogFactory.reset(); // make sure it reloads the modified config.
+
+        try {
+    		writeLogMessages();
+        } finally {
+            loggingEnvironmentBean.setLoggingFactory(originalFactory);
+            System.setOut(originalStream);
+            LogFactory.reset();
+        }
+		verifyResult(buffer.toString());
+
+	}
+
+   private static void writeLogMessages()
+   {
+       Logi18n log = LogFactory.getLogi18n(CLASS, "logging_msg");
+
+       Locale originalDefault = Locale.getDefault();
+       try {
+           Locale.setDefault(new Locale("en", "US"));
+           log.info("IDENTIFICATION", new String[] { "Foo", "Bar"});
+           log.fatal("fatal_message");
+           log.info("info_message");
+
+           Locale.setDefault(new Locale("fr", "FR"));
+           log = LogFactory.getLogi18n(CLASS, "logging_msg");
+           log.info("IDENTIFICATION", new String[] { "Foo", "Bar"});
+           log.fatal("fatal_message");
+           log.info("info_message");
+       } finally {
+           Locale.setDefault(originalDefault);
+       }
+   }
+
+    private static void verifyResult(String result) {
+        String[] lines = result.split("\r?\n");
+
+        assertNotNull(lines);
+        assertEquals(6, lines.length);
+        
+        assertTrue("Got actual value: "+lines[0], lines[0].matches("\\s*INFO \\[main\\] \\(logi18n.java.*The FirstName is Foo and the LastName is Bar$"));
+        assertTrue("Got actual value: "+lines[1], lines[1].matches("\\s*FATAL \\[main\\] \\(logi18n.java.*This is a fatal message$"));
+        assertTrue("Got actual value: "+lines[2], lines[2].matches("\\s*INFO \\[main\\] \\(logi18n.java.*This is a info message$"));
+
+        assertTrue("Got actual value: "+lines[3], lines[3].matches("\\s*INFO \\[main\\] \\(logi18n.java.*le prenom est Foo et le nom est Bar$"));
+        assertTrue("Got actual value: "+lines[4], lines[4].matches("\\s*FATAL \\[main\\] \\(logi18n.java.*Ceci est un message Fatal$"));
+        assertTrue("Got actual value: "+lines[5], lines[5].matches("\\s*INFO \\[main\\] \\(logi18n.java.*Ceci est un message pour information$"));
+    }
+}
+    
+    
+    

Added: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/propertyservice/StringPropertyReplacerUnitTestCase.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/propertyservice/StringPropertyReplacerUnitTestCase.java	                        (rev 0)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/propertyservice/StringPropertyReplacerUnitTestCase.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -0,0 +1,416 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.arjuna.common.tests.propertyservice;
+
+// copied into the com.arjuna namespace from org.jboss.util
+// as we don't want JBossTS to depend on JBoss common-core just for this one class.
+// original version is jboss-common-core 2.2.8.GA
+// svn.jboss.org/repos/common/common-core/tags/2.2.8.GA/src/test/java/org/jboss/test/util/test/StringPropertyReplacerUnitTestCase.java
+
+import static com.arjuna.common.util.propertyservice.StringPropertyReplacer.*;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import static org.junit.Assert.*;
+
+import java.util.Properties;
+
+/**
+ * A StringPropertyReplacerUnitTestCase.
+ *
+ * @author Brian Stansberry
+ * @author Jonathan Halliday - forked to create the com.arjuna version and updated for junit4
+ * @version $Revision$
+ *
+ */
+public class StringPropertyReplacerUnitTestCase
+{
+   private static final String PROP_A = "string.prop.replace.test.a";
+   private static final String PROP_B = "string.prop.replace.test.b";
+   private static final String PROP_C = "string.prop.replace.test.c";
+   private static final String PROP_D = "string.prop.replace.test.d";
+   private static final String DEFAULT = "DEFAULT";
+   private static final String VALUE = "VALUE";
+   private static final String WRAPPER = "wrapper";
+
+   @After
+   public void tearDown() throws Exception
+   {
+      System.clearProperty(PROP_A);
+      System.clearProperty(PROP_B);
+      System.clearProperty(PROP_C);
+      System.clearProperty(PROP_D);
+   }
+
+   private static Properties setupProperties()
+   {
+      Properties props = new Properties();
+      props.put(PROP_A, VALUE);
+      props.put(PROP_C, VALUE);
+      return props;
+   }
+
+   private static void setupSystemProperties()
+   {
+      System.setProperty(PROP_A, VALUE);
+      System.setProperty(PROP_C, VALUE);
+   }
+
+    @Test
+   public void testNullInput()
+   {
+      try
+      {
+         assertNull(replaceProperties(null));
+         fail("NPE expected with null input");
+      }
+      catch (NullPointerException good) {}
+
+      try
+      {
+         assertNull(replaceProperties(null, setupProperties()));
+         fail("NPE expected with null input");
+      }
+      catch (NullPointerException good) {}
+   }
+
+    @Test
+   public void testBasicReplacement()
+   {
+      basicReplacementTest(false);
+   }
+
+    @Test
+   public void testBasicReplacementFromSystemProps()
+   {
+      basicReplacementTest(true);
+   }
+
+   private void basicReplacementTest(boolean useSysProps)
+   {
+      String input = "${"+PROP_A+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(VALUE, output);
+   }
+
+    @Test
+   public void testWrappedReplacement()
+   {
+      wrappedReplacementTest(false);
+   }
+
+    @Test
+   public void testWrappedReplacementFromSystemProps()
+   {
+      wrappedReplacementTest(true);
+   }
+
+   private void wrappedReplacementTest(boolean useSysProps)
+   {
+      String input = WRAPPER+"${"+PROP_A+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(WRAPPER+VALUE, output);
+
+      input = "${"+PROP_A+"}"+WRAPPER;
+      output = null;
+      if (useSysProps)
+      {
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(VALUE+WRAPPER, output);
+
+      input = WRAPPER+"${"+PROP_A+"}"+WRAPPER;
+      output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(WRAPPER+VALUE+WRAPPER, output);
+   }
+
+    @Test
+   public void testMissingProperty()
+   {
+      missingPropertyTest(false);
+   }
+
+    @Test
+   public void testMissingPropertyFromSystemProps()
+   {
+      missingPropertyTest(true);
+   }
+
+   private void missingPropertyTest(boolean useSysProps)
+   {
+      String input = WRAPPER+"${"+PROP_B+"}"+WRAPPER;
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(input, output);
+   }
+
+    @Test
+   public void testWrappedMissingProperty()
+   {
+      wrappedMissingPropertyTest(false);
+   }
+
+    @Test
+   public void testWrappedMissingPropertyFromSystemProps()
+   {
+      wrappedMissingPropertyTest(true);
+   }
+
+   private void wrappedMissingPropertyTest(boolean useSysProps)
+   {
+      String input = WRAPPER+"${"+PROP_B+"}"+WRAPPER;
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(input, output);
+   }
+
+    @Test
+   public void testDefaultValue()
+   {
+      defaultValueTest(false);
+   }
+
+    @Test
+   public void testDefaultValueFromSystemProps()
+   {
+      defaultValueTest(true);
+   }
+
+   private void defaultValueTest(boolean useSysProps)
+   {
+      String input = "${"+PROP_B+":"+DEFAULT+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(DEFAULT, output);
+   }
+
+    @Test
+   public void testSecondaryProperty()
+   {
+      secondaryPropertyTest(false);
+   }
+
+    @Test
+   public void testSecondaryPropertyFromSystemProps()
+   {
+      secondaryPropertyTest(true);
+   }
+
+   private void secondaryPropertyTest(boolean useSysProps)
+   {
+      String input = "${"+PROP_B+","+PROP_C+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(VALUE, output);
+   }
+
+    @Test
+   public void testSecondaryPropertyAndDefault()
+   {
+      secondaryPropertyAndDefaultTest(false);
+   }
+
+    @Test
+   public void testSecondaryPropertyAndDefaultFromSystemProps()
+   {
+      secondaryPropertyAndDefaultTest(true);
+   }
+
+   private void secondaryPropertyAndDefaultTest(boolean useSysProps)
+   {
+      String input = "${"+PROP_B+","+PROP_D+":"+DEFAULT+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(DEFAULT, output);
+   }
+
+    @Test
+   public void testSecondaryPropertyAndMissing()
+   {
+      secondaryPropertyAndMissingTest(false);
+   }
+
+    @Test
+   public void testSecondaryPropertyAndMissingFromSystemProps()
+   {
+      secondaryPropertyAndMissingTest(true);
+   }
+
+   private void secondaryPropertyAndMissingTest(boolean useSysProps)
+   {
+      String input = "${"+PROP_B+","+PROP_D+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(input, output);
+   }
+
+    @Test
+   public void testMultipleReplacements()
+   {
+      multipleReplacementTest(false);
+   }
+
+    @Test
+   public void testMultipleReplacementsFromSystemProps()
+   {
+      multipleReplacementTest(true);
+   }
+
+   private void multipleReplacementTest(boolean useSysProps)
+   {
+      String input = "${"+PROP_A+"}${"+PROP_C+"}";
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(VALUE+VALUE, output);
+   }
+
+    @Test
+   public void testPartialMissing()
+   {
+      partialMissingTest(false);
+   }
+
+    @Test
+   public void testPartialMissingFromSystemProps()
+   {
+      partialMissingTest(true);
+   }
+
+   private void partialMissingTest(boolean useSysProps)
+   {
+      String badinput = "${"+PROP_B+"}";
+      String input = WRAPPER+"${"+PROP_A+"}"+badinput+"${"+PROP_C+"}"+WRAPPER;
+      String output = null;
+      if (useSysProps)
+      {
+         setupSystemProperties();
+         output = replaceProperties(input);
+      }
+      else
+      {
+         output = replaceProperties(input, setupProperties());
+      }
+
+      assertEquals(WRAPPER+VALUE+badinput+VALUE+WRAPPER, output);
+   }
+
+}

Modified: labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyEnvironmentBean.java
===================================================================
--- labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyEnvironmentBean.java	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/DummyEnvironmentBean.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -20,9 +20,12 @@
  */
 package com.arjuna.common.tests.simple;
 
+import com.arjuna.common.internal.util.propertyservice.ConcatenationPrefix;
 import com.arjuna.common.internal.util.propertyservice.PropertyPrefix;
 import com.arjuna.common.internal.util.propertyservice.FullPropertyName;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 /**
@@ -36,14 +39,23 @@
     private long myLong = -1;
     @FullPropertyName(name = "my_custom_name")
     private String myString = "default";
-    private boolean myBoolean = false;
+    private boolean myFirstBoolean = false;
+    private boolean mySecondBoolean = true;
 
+    @ConcatenationPrefix(prefix = "my_concat_prefix")
+    private volatile List<String> myList = new ArrayList<String>();
+
     public Properties getProperties() {
         Properties properties = new Properties();
         properties.setProperty("myprefix.myInt", "1");
         properties.setProperty("myprefix.myLong", "1");
         properties.setProperty("my_custom_name", "not_the_default");
-        properties.setProperty("myprefix.myBoolean", "NO");
+        properties.setProperty("myprefix.myFirstBoolean", "NO");
+        properties.setProperty("myprefix.mySecondBoolean", "YES");
+
+        properties.setProperty("my_concat_prefix_one", "one");
+        properties.setProperty("my_concat_prefix_two", "two");
+
         return properties;
     }
 
@@ -77,13 +89,33 @@
         this.myString = myString;
     }
 
-    public boolean isMyBoolean()
+    public boolean isMyFirstBoolean()
     {
-        return myBoolean;
+        return myFirstBoolean;
     }
 
-    public void setMyBoolean(boolean myBoolean)
+    public void setMyFirstBoolean(boolean myFirstBoolean)
     {
-        this.myBoolean = myBoolean;
+        this.myFirstBoolean = myFirstBoolean;
     }
+
+    public boolean isMySecondBoolean()
+    {
+        return mySecondBoolean;
+    }
+
+    public void setMySecondBoolean(boolean mySecondBoolean)
+    {
+        this.mySecondBoolean = mySecondBoolean;
+    }
+
+    public List<String> getMyList()
+    {
+        return myList;
+    }
+
+    public void setMyList(List<String> myList)
+    {
+        this.myList = myList;
+    }
 }
\ 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	2010-01-11 10:19:49 UTC (rev 31008)
+++ labs/jbosstm/trunk/common/tests/com/arjuna/common/tests/simple/EnvironmentBeanTest.java	2010-01-11 10:44:56 UTC (rev 31009)
@@ -41,10 +41,11 @@
 
         DummyEnvironmentBean testBean = new DummyEnvironmentBean();
         DummyProperties testProperties = new DummyProperties(testBean.getProperties());
+        testProperties.addConcatenationKeys(DummyEnvironmentBean.class);
         BeanPopulator.configureFromProperties(testBean, testProperties);
 
         Set<Object> expectedKeys = testBean.getProperties().keySet();
 
         assertTrue( testProperties.usedKeys.containsAll(expectedKeys) );
     }
-}
+}
\ No newline at end of file



More information about the jboss-svn-commits mailing list