[embjopr-commits] EMBJOPR SVN: r910 - in branches/EmbJopr-1.4.0-SN-EAP5/jsfunit: src/test/java/org/jboss/jopr/jsfunit/as5 and 3 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Fri Apr 2 13:33:07 EDT 2010


Author: ozizka at redhat.com
Date: 2010-04-02 13:33:06 -0400 (Fri, 02 Apr 2010)
New Revision: 910

Added:
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/SubPoolStatsParser.java
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesMapValidator.java
Modified:
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/pom.xml
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/ConnFactoryOperationsTest.java
   branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/testdata/war/
Log:
* POM: Moved Cargo to start-stop-server
* Fixed ConnectionFactories tests


Property changes on: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit
___________________________________________________________________
Name: svn:ignore
   - nb-configuration.xml
TEST-TestSuite-01.xsl
parent
CHANGES.txt
pom_1.xml
TEST-TestSuite-02.xsl
pom_05-XSLT.xml
pom_3.xml
pom_2.xml
pom_pure_maven.xml
target
TEST-TestSuite.xsl
pom_4.xml
nbactions.xml
target-233of308

   + nb-configuration.xml
TEST-TestSuite-01.xsl
parent
CHANGES.txt
pom_1.xml
TEST-TestSuite-02.xsl
pom_05-XSLT.xml
pom_3.xml
pom_2.xml
pom_pure_maven.xml
target
TEST-TestSuite.xsl
pom_4.xml
nbactions.xml
target-233of308
target-EAP501CR1-37of308
target-ConnFactories


Modified: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/pom.xml
===================================================================
--- branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/pom.xml	2010-04-01 13:45:34 UTC (rev 909)
+++ branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/pom.xml	2010-04-02 17:33:06 UTC (rev 910)
@@ -491,90 +491,17 @@
          </plugins></build>
       </profile>
 
-      <profile>
-         <id>jboss5x</id>
-         
-         <properties>
-           <jboss5x>true</jboss5x>
-         </properties>
-         <build>
-            <plugins>
 
 
-              <!-- AntRun - Exctract the war to let Cargo plugin deploy it. -->
-              <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-antrun-plugin</artifactId>
-                <executions>
-                  <!-- Extract WAR (SEAM bug) - rename to _archive.war and unzip to a .war dir. .  -->
-                  <execution>
-                    <id>extract_war_for_cargo</id>
-                    <phase>package</phase> <goals><goal>run</goal></goals>
-                    <configuration><tasks>
-                      <echo>Extracting war...</echo>
-                      <move file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
-                          toFile="${project.build.directory}/${project.build.finalName}_archive.${project.packaging}"/>
-                      <unzip src="${project.build.directory}/${project.build.finalName}_archive.${project.packaging}"
-                             dest="${project.build.directory}/${project.build.finalName}.${project.packaging}"/>
-                     <echo>  *** Disabling navtree AJAX... ***  </echo>
-                     <replace file="${project.build.directory}/${project.build.finalName}.${project.packaging}/WEB-INF/facelets/resourceNavigation.xhtml"
-                              token="switchType=&quot;ajax" value="switchType=&quot;server"/>
-                    </tasks></configuration>
-                  </execution>
-                  <!-- Write "Don't kill" to hudson log/ -->
-                  <execution>
-                    <id>dont_kill_appeal</id>
-                    <phase>pre-integration-test</phase> <goals><goal>run</goal></goals>
-                    <configuration><tasks>
-                      <echo>##########################  Please don't kill this job unless it takes more than four hours.</echo>
-                      <echo>##########################  There's no logging visible on Hudson during test run.</echo>
-                    </tasks></configuration>
-                  </execution>
-                  <!-- Delete the exploded WAR and rename the archive back. -->
-                  <execution>
-                    <id>rename-the-artifact-back</id>
-                    <phase>post-integration-test</phase> <goals><goal>run</goal></goals>
-                    <configuration><tasks>
-                      <echo>Renaming exploded war and renaming the zip back to the artifact name.</echo>
-                      <move file="${project.build.directory}/${project.build.finalName}.${project.packaging}" toFile="${project.build.directory}/${project.build.finalName}_exploded.${project.packaging}"/>
-                      <move file="${project.build.directory}/${project.build.finalName}_archive.${project.packaging}"
-                          toFile="${project.build.directory}/${project.build.finalName}.${project.packaging}"/>
-                    </tasks></configuration>
-                  </execution>
-                </executions>
-              </plugin>
 
-              <!-- Exctract the war to let Cargo plugin deploy it.
-              <plugin>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <executions>
-                  <execution>
-                    <id>explode-war</id>
-                    <phase>pre-integration-test</phase>
-                    <goals>
-                      <goal>unpack</goal>
-                    </goals>
-                    <configuration>
-                      <outputDirectory>${project.build.directory}/${project.build.finalName}_for_cargo_EMBJOPR-235.${project.packaging}</outputDirectory>
-                      <overWriteReleases>true</overWriteReleases>
-                      <overWriteSnapshots>true</overWriteSnapshots>
-                      <includes>**\/*</includes>
-                      <excludes></excludes>
-                      <artifactItems>
-                        <artifactItem>
-                          <groupId>org.jboss.jopr</groupId>
-                          <artifactId>jopr-embedded-jsfunit</artifactId>
-                          <version>${project.version}</version>
-                          <type>war</type>
-                        </artifactItem>
-                      </artifactItems>
-                    </configuration>
-                  </execution>
-                </executions>
-              </plugin>
-               -->
 
+      <profile>
+         <id>start-stop-server</id>
+         <activation> <property><name>cargo</name></property> </activation>
 
+         <build>
+            <plugins>
+
                <!-- Cargo plugin (for AS 5) -->
                <plugin>
                   <groupId>org.codehaus.cargo</groupId>
@@ -692,6 +619,98 @@
                   </executions>
                </plugin>
 
+         </plugins></build>
+      </profile>
+
+
+
+
+
+      <profile>
+         <id>jboss5x</id>
+         
+         <properties>
+           <jboss5x>true</jboss5x>
+         </properties>
+         <build>
+            <plugins>
+
+
+              <!-- AntRun - Exctract the war to let Cargo plugin deploy it. -->
+              <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                  <!-- Extract WAR (SEAM bug) - rename to _archive.war and unzip to a .war dir. .  -->
+                  <execution>
+                    <id>extract_war_for_cargo</id>
+                    <phase>package</phase> <goals><goal>run</goal></goals>
+                    <configuration><tasks>
+                      <echo>Extracting war...</echo>
+                      <move file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
+                          toFile="${project.build.directory}/${project.build.finalName}_archive.${project.packaging}"/>
+                      <unzip src="${project.build.directory}/${project.build.finalName}_archive.${project.packaging}"
+                             dest="${project.build.directory}/${project.build.finalName}.${project.packaging}"/>
+                     <echo>  *** Disabling navtree AJAX... ***  </echo>
+                     <replace file="${project.build.directory}/${project.build.finalName}.${project.packaging}/WEB-INF/facelets/resourceNavigation.xhtml"
+                              token="switchType=&quot;ajax" value="switchType=&quot;server"/>
+                    </tasks></configuration>
+                  </execution>
+                  <!-- Write "Don't kill" to hudson log/ -->
+                  <execution>
+                    <id>dont_kill_appeal</id>
+                    <phase>pre-integration-test</phase> <goals><goal>run</goal></goals>
+                    <configuration><tasks>
+                      <echo>##########################  Please don't kill this job unless it takes more than four hours.</echo>
+                      <echo>##########################  There's no logging visible on Hudson during test run.</echo>
+                    </tasks></configuration>
+                  </execution>
+                  <!-- Delete the exploded WAR and rename the archive back. -->
+                  <execution>
+                    <id>rename-the-artifact-back</id>
+                    <phase>post-integration-test</phase> <goals><goal>run</goal></goals>
+                    <configuration><tasks>
+                      <echo>Renaming exploded war and renaming the zip back to the artifact name.</echo>
+                      <move file="${project.build.directory}/${project.build.finalName}.${project.packaging}" toFile="${project.build.directory}/${project.build.finalName}_exploded.${project.packaging}"/>
+                      <move file="${project.build.directory}/${project.build.finalName}_archive.${project.packaging}"
+                          toFile="${project.build.directory}/${project.build.finalName}.${project.packaging}"/>
+                    </tasks></configuration>
+                  </execution>
+                </executions>
+              </plugin>
+
+              <!-- Exctract the war to let Cargo plugin deploy it.
+              <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                  <execution>
+                    <id>explode-war</id>
+                    <phase>pre-integration-test</phase>
+                    <goals>
+                      <goal>unpack</goal>
+                    </goals>
+                    <configuration>
+                      <outputDirectory>${project.build.directory}/${project.build.finalName}_for_cargo_EMBJOPR-235.${project.packaging}</outputDirectory>
+                      <overWriteReleases>true</overWriteReleases>
+                      <overWriteSnapshots>true</overWriteSnapshots>
+                      <includes>**\/*</includes>
+                      <excludes></excludes>
+                      <artifactItems>
+                        <artifactItem>
+                          <groupId>org.jboss.jopr</groupId>
+                          <artifactId>jopr-embedded-jsfunit</artifactId>
+                          <version>${project.version}</version>
+                          <type>war</type>
+                        </artifactItem>
+                      </artifactItems>
+                    </configuration>
+                  </execution>
+                </executions>
+              </plugin>
+               -->
+
+
+
                <!-- Surefire plugin (for AS 5) -->
                <plugin>
                   <groupId>org.apache.maven.plugins</groupId>

Modified: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
===================================================================
--- branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java	2010-04-01 13:45:34 UTC (rev 909)
+++ branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java	2010-04-02 17:33:06 UTC (rev 910)
@@ -38,8 +38,10 @@
 import java.util.LinkedHashMap;
 import java.util.Properties;
 import org.apache.commons.lang.StringUtils;
+import org.jboss.jopr.jsfunit.as5.connfactories.SubPoolStatsParser;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NavTreeNode;
 import org.jboss.jopr.jsfunit.exceptions.*;
+import org.jboss.jopr.jsfunit.util.ValuesMapValidator;
 import org.jboss.jsfunit.jsfsession.ComponentIDNotFoundException;
 
 /**
@@ -592,28 +594,92 @@
                                                             StringBuffer expectedBuffer,
                                                             String errorMessage,
 																														Boolean isRegEx) throws Exception {
-        performResourceOperation(resourceCategory, resourceSubCategory, 
+        performResourceOperation(resourceCategory, resourceSubCategory,
                                  resourceName, operationName, takesParameters);
-        
+
         // Get the result of the operation
         HtmlDivision historyPanel = (HtmlDivision)client.getElement(OPERATION_RESULTS);
-        HtmlTextArea resultTextBox = (HtmlTextArea)historyPanel.getFirstByXPath(".//textarea[@class='property-value-input']"); 
+        HtmlTextArea resultTextBox = (HtmlTextArea)historyPanel.getFirstByXPath(".//textarea[@class='property-value-input']");
 
         assertNotNull("Could not get the result of the operation", resultTextBox);
-        
+
         String actualResult = resultTextBox.getText();
 
+				validateMatchOrEqualityWithFail( expectedBuffer.toString(), actualResult, errorMessage, isRegEx );
+
+    }
+
+		/**
+		 *   @returns null if OK, error message if not OK.
+		 */
+		private String validateMatchOrEquality( String exp, String act, boolean isRegEx ){
+				act = StringUtils.defaultString( act, "~null~" );
 				boolean isSuccess = isRegEx
-				  ? actualResult.matches(expectedBuffer.toString())
-					: actualResult.contains(expectedBuffer.toString()) ;
+				  ? act.matches(exp)
+					: act.contains(exp) ;
 				String condVerb = isRegEx ? "match" : "contain";
 
 				if( !isSuccess ){
-					fail(errorMessage + " - \nexpected the result to "+condVerb+":\n\n>>>" + expectedBuffer.toString() + "<<<\n\nbut was:\n\n>>>" + actualResult + "<<<" );
+					String LINES = exp.contains("\n") || act.contains("\n")  ?  "\n\n" : "";
+					return "expected the result to "+condVerb+":"+LINES+"{{{"+exp+"}}}"+LINES+"but was:"+LINES+"{{{"+act+"}}}";
 				}
-        
+				return null;
+		}
+
+		/**
+		 * Calls #validateMatchOrEquality( String, String, true ) if exp starts with "@REGEX:"; otherwise with false.
+		 */
+		private String validateMatchOrEquality( String exp, String act ){
+			if( exp.startsWith( REGEX_PREFIX ) ){
+				exp = exp.substring( REGEX_PREFIX.length() );
+				return validateMatchOrEquality(exp, act, true);
+			}
+			return validateMatchOrEquality(exp, act, false);
+		}
+
+		public void validateMatchOrEqualityWithFail( String exp, String act, String errorMessagePrefix ){
+				String errString = validateMatchOrEquality( exp, act );
+				if( null != errString )
+					fail( errorMessagePrefix + errString );
+		}
+		public void validateMatchOrEqualityWithFail( String exp, String act, String errorMessagePrefix, boolean isRegEx ){
+				String errString = validateMatchOrEquality( exp, act, isRegEx );
+				if( null != errString )
+					fail( errorMessagePrefix + errString );
+		}
+
+
+
+		/** Validates the given map (not a StringBuffer). */
+    protected void performResourceOperationAndCheckValueBox(String resourceCategory,
+                                                            String resourceSubCategory,
+                                                            String resourceName,
+                                                            String operationName,
+                                                            Boolean takesParameters,
+                                                            Map<String, Object> expectedValues,
+                                                            String errorMessage,
+																														Boolean isRegEx) throws Exception {
+        performResourceOperation(resourceCategory, resourceSubCategory,
+                                 resourceName, operationName, takesParameters);
+
+        // Get the result of the operation
+        HtmlDivision historyPanel = (HtmlDivision)client.getElement(OPERATION_RESULTS);
+        HtmlTextArea resultTextBox = (HtmlTextArea)historyPanel.getFirstByXPath(".//textarea[@class='property-value-input']");
+
+        assertNotNull("Could not get the result of the operation", resultTextBox);
+
+        String actualResult = resultTextBox.getText();
+
+				String err = ValuesMapValidator.CONTAINS_ALL.validate(expectedValues, SubPoolStatsParser.parse(actualResult));
+
+				if( null != err ){
+					fail("Unexpected result values: >>>" + actualResult + "<<<\n\nError message:\n"+err );
+				}
+
     }
-    
+
+		
+
     /**
      * Perform the given operation for the given resource and
      * then check that the resulting table contains the correct values.
@@ -650,7 +716,10 @@
 				// The list of properties to check is not taken from the table, but given by the test.
 				Properties properties = ejtt.tabMenu.getTabContentBox().getTable(table).getProperties();
 				for( String key : expectedValues.keySet() ){
-					assertEquals("Incorrect value for '" + key + "' - ", expectedValues.get(key), properties.getProperty(key));
+					//assertEquals("Incorrect value for '" + key + "' - ", expectedValues.get(key), properties.getProperty(key));
+					String expVal = expectedValues.get(key);
+					String actVal = properties.getProperty(key); // StringUtils.defaultString( properties.getProperty(key), "~null~" );
+					validateMatchOrEqualityWithFail( expVal, actVal, key+": " );
 				}
 
     }

Modified: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/ConnFactoryOperationsTest.java
===================================================================
--- branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/ConnFactoryOperationsTest.java	2010-04-01 13:45:34 UTC (rev 909)
+++ branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/ConnFactoryOperationsTest.java	2010-04-02 17:33:06 UTC (rev 910)
@@ -25,10 +25,13 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.LinkedHashMap;
 import javax.resource.cci.Connection;
+import org.jboss.jopr.jsfunit.as5.ResourceTestBase;
 import org.jboss.managed.api.ComponentType;
+import org.jboss.util.Strings.Range;
 
 /**
  * This class contains operations tests for Connection Factories.
@@ -330,12 +333,21 @@
             expectedBuffer.append("Connections Destroyed Count:0\n");
             expectedBuffer.append("Connections In Use Count:6\n");
 						expectedBuffer.append(".*");
+
+						// ^^^ NOT USED ^^^ //
+
+						Map<String, Object> expVals = new HashMap();
+            expVals.put("Sub Pool Count", 1);
+            expVals.put("Available Connections Count", 14);
+            expVals.put("Max Connections In Use Count", new Range(6,8)); // Give it some tolerance - sometimes we get 7 or 8 too.
+            expVals.put("Connections Destroyed Count", 0);
+            expVals.put("Connections In Use Count", 6);
             
-            String errorMessage = "Incorrect sub pool statistics";
+            String errorMessage = "Incorrect sub pool statistics ";
 
             performResourceOperationAndCheckValueBox(CF_NAV_LABEL, cfType.getLabel(),
                                                      jndiName, LIST_FORMATTED_SUB_POOL_STATISTICS,
-                                                     Boolean.TRUE, expectedBuffer, errorMessage, true);
+                                                     Boolean.TRUE, expVals, errorMessage, true);
         } finally {
             
             // Clean up
@@ -423,13 +435,15 @@
                 connections.get(i).close();
                 connections.set(i, null);
             }
-            
+
+						/*
             // Set up the expected results
             StringBuffer expectedBuffer = new StringBuffer();
             expectedBuffer.append("Sub Pool Statistics: \n");
             expectedBuffer.append("Sub Pool Count: 1\n");
             expectedBuffer.append(POOL_SEPARATOR);
             expectedBuffer.append("\n\n");
+						 */
 
 						// Deprecated property, was removed - JBAS-6918
             /*if(cfType == CFType.NO_TX_CF) {
@@ -437,18 +451,30 @@
             } else {
                 expectedBuffer.append("Track By Transaction: true\n");
             }*/
-            
+
+						/*
             expectedBuffer.append("Available Connections Count: 12\n");
             expectedBuffer.append("Max Connections In Use Count:1(0|1|2)\n"); // Sometimes old conns are counted.
             expectedBuffer.append("Connections Destroyed Count:0\n");
             expectedBuffer.append("Connections In Use Count:8");
             expectedBuffer.append(".*");
+						 */
+
+
+						Map<String, Object> expVals = new HashMap();
+						
+            expVals.put("Sub Pool Count", 1);
+            expVals.put("Available Connections Count", 12);
+            expVals.put("Max Connections In Use Count", new Range(10, 12) ); // Sometimes old conns are counted.
+            expVals.put("Connections Destroyed Count", 0);
+            expVals.put("Connections In Use Count", 8);
+
         
             String errorMessage = "Incorrect sub pool statistics";
 
             performResourceOperationAndCheckValueBox(CF_NAV_LABEL, cfType.getLabel(),
                                                      jndiName, LIST_FORMATTED_SUB_POOL_STATISTICS,
-                                                     Boolean.TRUE, expectedBuffer, errorMessage, true);
+                                                     Boolean.TRUE, expVals, errorMessage, true);
         } finally {
             
             // Clean up
@@ -501,8 +527,7 @@
         
         // Additional statistics that need to be checked
         expectedStatistics.put("criteria", "ByApplication");
-        expectedStatistics.put("name", "jboss.jca:service=ManagedConnectionFactory,name=" 
-                               + jndiName);
+        expectedStatistics.put("name", "jboss.jca:service=ManagedConnectionFactory,name=" + jndiName);
         expectedStatistics.put("subPoolCount", "0"); 
         expectedStatistics.put("totalConnectionsInUseCount", "0");
         //expectedStatistics.put("totalMaxConnectionsInUseCount", "0"); // Sometimes we get 1 - old connection is counted.
@@ -600,7 +625,7 @@
                                    + jndiName);
             expectedStatistics.put("subPoolCount", "1"); 
             expectedStatistics.put("totalConnectionsInUseCount", "6");
-            expectedStatistics.put("totalMaxConnectionsInUseCount", "6");
+            expectedStatistics.put("totalMaxConnectionsInUseCount", REGEX_PREFIX+"[678]");
               
             performResourceOperationAndCheckTable(CF_NAV_LABEL, cfType.getLabel(), jndiName,
                                                   LIST_STATISTICS, Boolean.FALSE, expectedStatistics);
@@ -706,7 +731,7 @@
                                    + jndiName);
             expectedStatistics.put("subPoolCount", "1"); 
             expectedStatistics.put("totalConnectionsInUseCount", "8");
-            expectedStatistics.put("totalMaxConnectionsInUseCount", "10");
+            expectedStatistics.put("totalMaxConnectionsInUseCount", REGEX_PREFIX+"1[01]");
             
             performResourceOperationAndCheckTable(CF_NAV_LABEL, cfType.getLabel(), jndiName,
                                                   LIST_STATISTICS, Boolean.FALSE, expectedStatistics);

Added: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/SubPoolStatsParser.java
===================================================================
--- branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/SubPoolStatsParser.java	                        (rev 0)
+++ branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connfactories/SubPoolStatsParser.java	2010-04-02 17:33:06 UTC (rev 910)
@@ -0,0 +1,52 @@
+
+package org.jboss.jopr.jsfunit.as5.connfactories;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+
+/**
+ * Parses info like this:
+ *
+		Sub Pool Statistics:
+		Sub Pool Count: 1
+		------------------------------------------------------
+
+		Available Connections Count: 12
+		Max Connections In Use Count:10
+		Connections Destroyed Count:0
+		Connections In Use Count:8
+		...
+ *
+ * @author Ondrej Zizka
+ */
+public class SubPoolStatsParser {
+
+	public static Map<String, Integer> parse( String str )
+	{
+		
+		Map<String, Integer> values = new HashMap();
+
+		StringTokenizer tok = new StringTokenizer(str, "\n\r");
+
+		while( tok.hasMoreTokens() ){
+			String line = tok.nextToken();
+			line = line.replace("-", "").trim();
+			if( line.length() == 0 ) continue;
+			
+			String[] parts = line.split(":");
+			if( parts.length < 2 ) continue;
+
+			values.put( parts[0], NumberUtils.createInteger( parts[1].trim() ) );
+		}
+
+		return values;
+
+	}
+
+
+
+	
+}// class

Added: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesMapValidator.java
===================================================================
--- branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesMapValidator.java	                        (rev 0)
+++ branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesMapValidator.java	2010-04-02 17:33:06 UTC (rev 910)
@@ -0,0 +1,61 @@
+
+package org.jboss.jopr.jsfunit.util;
+
+import java.util.Map;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+import org.jboss.util.Strings.Range;
+
+/**
+ *
+ * @author Ondrej Zizka
+ */
+public interface ValuesMapValidator {
+
+	/** Returns null if values are OK, or validation error description when validation fails. */
+	public String validate( Map<String, ? extends Object> expected,  Map<String, ? extends Object> actual );
+
+	/**  Checks whether the actual values map contains the set defined by expected values map. */
+	public static final ValuesMapValidator CONTAINS_ALL = new ValuesMapValidator() {
+		public String validate( Map<String, ? extends Object> exp,  Map<String, ? extends Object> act ){
+
+			StringBuilder sb = new StringBuilder();
+
+			for( Map.Entry<String, ? extends Object> expectedEntry : exp.entrySet() )
+			{
+				String key = expectedEntry.getKey();
+				if( !act.containsKey(key) )
+					sb.append(key+": Not found.");
+
+				Object valExp = exp.get(key);
+				Object valAct = act.get(key);
+
+				// Range
+				if( valExp instanceof Range ){
+					Long numAct = NumberUtils.createLong( ObjectUtils.toString(valAct) );
+					Range range = (Range)valExp;
+					if( numAct < range.begin || numAct > range.end )
+						sb.append( String.format( key + ": Expected between %d and %d, was '%d'.", range.begin, range.end, numAct ) );
+				}
+				// String
+				else{
+					String strExp = ObjectUtils.toString( exp.get(key), "null" );
+					String strAct = ObjectUtils.toString( act.get(key), "null" );
+
+					if( !StringUtils.equals( strExp, strAct ) ){
+						sb.append( String.format( key + ": Expected '%s', actual '%s'.\n", strExp, strAct ) );
+					}
+				}
+			}
+
+			if( sb.length() == 0 )
+				return null;
+
+			return sb.toString();
+
+		}
+	};
+
+
+}// class


Property changes on: branches/EmbJopr-1.4.0-SN-EAP5/jsfunit/testdata/war
___________________________________________________________________
Name: svn:ignore
   + HQL-error-Tomcat-WAR.png
ExpirationException.png




More information about the embjopr-commits mailing list