[embjopr-commits] EMBJOPR SVN: r644 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5/sbm and 1 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Tue Aug 4 20:03:32 EDT 2009


Author: ozizka at redhat.com
Date: 2009-08-04 20:03:31 -0400 (Tue, 04 Aug 2009)
New Revision: 644

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesValidator.java
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/sbm/ServiceBindingManagerTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
 * Implemented the rest of JBoss Cache tests. Currently failing because of JOPR-334 and bad EJB  package in use (TBD)

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java	2009-08-05 00:02:03 UTC (rev 643)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java	2009-08-05 00:03:31 UTC (rev 644)
@@ -1,27 +1,19 @@
 package org.jboss.jopr.jsfunit.as5.jbcache;
 
-import com.gargoylesoftware.htmlunit.html.HtmlTable;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
-import org.jboss.qa.jbcache.testear.*;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
-import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
-import org.jboss.jopr.jsfunit.DebugUtils;
 import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
 import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
 import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTable;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTableRow;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NavTreeNode;
-import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NodeFinder;
 
 /**
  *
@@ -155,7 +147,7 @@
 
 		Properties props = new Properties();
 		props.setProperty("Name", "Cache");
-		ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValues(props);
+		ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValuesEqual(props);
 
 
 
@@ -166,7 +158,7 @@
      */
 		props = new Properties();
 		props.setProperty("Number of Nodes", "1");
-		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props);
+		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValuesEqual(props);
 		
 
 	}
@@ -201,7 +193,7 @@
 		props.setProperty("Sync Commit Phase?", "false");
 		props.setProperty("State", "3");
 		props.setProperty("Transaction Manager Lookup Class", "org.jboss.cache.transaction.BatchModeTransactionManagerLookup");
-		ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_TRAITS).checkValues(props);
+		ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_TRAITS).checkValuesEqual(props);
 
 
 		// Numeric metrics
@@ -214,7 +206,7 @@
 		props.setProperty("Number of Nodes", "1");
 		props.setProperty("Sync Replication Timeout", "17,500");
 		props.setProperty("State Retrieval Timeout", "60,000");
-		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props);
+		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValuesEqual(props);
 		
 	}
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java	2009-08-05 00:02:03 UTC (rev 643)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java	2009-08-05 00:03:31 UTC (rev 644)
@@ -6,12 +6,17 @@
 import javax.naming.NamingException;
 import org.jboss.qa.jbcache.testear.*;
 import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.ValuesValidator;
 
 /**
  *
  * @author Ondrej Zizka
  *
  * JBoss Cache is only present in 'all' JBoss AS profile.
+ *
+ *
+ * These tests are failing because of JOPR-334 .
+ *
  */
 public class JBossCacheInterceptorTest extends JBossCacheTestBase {
 
@@ -24,38 +29,107 @@
 		if( isJBossConfigWithoutCache() ) return;
 
 
-
 		ejtt.deployment.deployViaEmbJopr( DeployableTypes.EAR, ejtt.getTestFilePath(this.APP_TYPE, JBCACHE_TEST_EAR));
+		try {
 
+			ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
+			ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
 
+			// Gen Props - nothing useful.
+			Properties props = new Properties();
+			props.setProperty("Name", "Interceptor");
+			ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValuesEqual(props);
+
+
+			/*
+				Numeric Metrics
+					Hit/Miss Ratio	      0	     Hit/Miss Ratio
+					Read/Write Ratio	    0	     Read/Write Ratio
+					Number Of Attributes	0	     the number of cache attributes
+					Average Write Time	  0.0ms	 the average amount of time per write operation
+					Average Read Time	    0.0ms	 the average amount of time per read operation
+			 */
+			props = new Properties();
+			props.setProperty("Hit/Miss Ratio", "0");
+			props.setProperty("Read/Write Ratio", "0");
+			props.setProperty("Number Of Attributes", "0.0ms");
+			props.setProperty("Average Write Time", "0.0ms");
+			//props.setProperty("Average Read Time", "0.0ms");
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValuesEqual(props);
+
+		}
+		finally {
+			ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
+		}
+
+	}
+
+
+
+
+
+
+	/**
+	 * Interceptor Summary tab after querying Hibernate.
+	 */
+	public void testJBossCacheInterceptorSummary_AfterQuery() throws IOException, EmbJoprTestException, NamingException {
+		if( isJBossConfigWithoutCache() ) return;
+
+
+		// Go to the Interceptor's Summary tab and store the properties before query.
 		ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
 		ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+		Properties propsFirst = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).getProperties();
 
-		// Gen Props - nothing useful.
-		Properties props = new Properties();
-		props.setProperty("Name", "Interceptor");
-		ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValues(props);
 
 
-		/*
-  		Numeric Metrics
-				Hit/Miss Ratio	      0	     Hit/Miss Ratio
-				Read/Write Ratio	    0	     Read/Write Ratio
-				Number Of Attributes	0	     the number of cache attributes
-				Average Write Time	  0.0ms	 the average amount of time per write operation
-				Average Read Time	    0.0ms	 the average amount of time per read operation
-		 */
-		props = new Properties();
-		props.setProperty("Hit/Miss Ratio", "0");
-		props.setProperty("Read/Write Ratio", "0");
-		props.setProperty("Number Of Attributes", "0.0ms");
-		props.setProperty("Average Write Time", "0.0ms");
-		props.setProperty("Average Read Time", "0.0ms");
-		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props);
+		// Deploy an EAR.
+		ejtt.deployment.deployViaEmbJopr( DeployableTypes.EAR, ejtt.getTestFilePath(this.APP_TYPE, JBCACHE_TEST_EAR));
 
+		try {
 
-		ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
 
+			// Run the test() method of the bean - performs few Hibernate operations.
+			performBeanRequest();
+
+
+			// Go back to the Interceptor's Summary tab.
+			ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
+			ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+
+			// Gen Props - nothing useful.
+			Properties props = new Properties();
+			props.setProperty("Name", "Interceptor");
+			ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValuesEqual(props);
+
+
+
+			// Check that the latter values are diffrent from the former.
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(propsFirst, ValuesValidator.NOT_EQUAL);
+
+
+			// Check that these metrics didn't stay at their init values.
+			/*
+				Numeric Metrics
+					Hit/Miss Ratio	      0	     Hit/Miss Ratio
+					Read/Write Ratio	    0	     Read/Write Ratio
+					Number Of Attributes	0	     the number of cache attributes
+					Average Write Time	  0.0ms	 the average amount of time per write operation
+					Average Read Time	    0.0ms	 the average amount of time per read operation
+			 */
+			props = new Properties();
+			props.setProperty("Hit/Miss Ratio", "0");
+			props.setProperty("Read/Write Ratio", "0");
+			props.setProperty("Number Of Attributes", "0.0ms");
+			props.setProperty("Average Write Time", "0.0ms");
+			props.setProperty("Average Read Time", "0.0ms");
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props, ValuesValidator.NOT_EQUAL);
+
+		}
+		finally {
+			ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
+		}
+
 	}
 
 
@@ -63,56 +137,89 @@
 
 
 
+
+
 	/**
-	 * Interceptor Summary tab after querying Hibernate.
+	 * Interceptor Metrics tab.
 	 */
-	public void testJBossCacheInterceptorSummary_AfterQuery() throws IOException, EmbJoprTestException, NamingException {
+	public void testJBossCacheInterceptorMetrics() throws IOException, EmbJoprTestException {
 		if( isJBossConfigWithoutCache() ) return;
 
 
 		ejtt.deployment.deployViaEmbJopr( DeployableTypes.EAR, ejtt.getTestFilePath(this.APP_TYPE, JBCACHE_TEST_EAR));
+		try {
 
+			ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
+			ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+			ejtt.tabMenu.clickMetricsTab();
 
-		final String BEAN_JNDI = "TestOperationBean/remote";
+			// Traits.
+			Properties props = new Properties();
+			props.setProperty("Statistics Enabled", "true");
+			ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_TRAITS).checkValuesEqual(props);
 
-		// Query the bean.
-		log.info("Looking up "+BEAN_JNDI+"...");
-		InitialContext ctx = new InitialContext();
-		TestOperation bean = (TestOperation) ctx.lookup(BEAN_JNDI);
+			// Numeric Metrics
+			props = getInitialMetricsProperties();
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValuesEqual(props);
 
-		log.info("Sending request...");
-		bean.test();
+		}
+		finally {
+			ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
+		}
 
+	}
 
 
 
+
+	/**
+	 * Interceptor Metrics tab after querying Hibernate.
+	 */
+	public void testJBossCacheInterceptorMetrics_AfterQuery() throws IOException, EmbJoprTestException, NamingException {
+		if( isJBossConfigWithoutCache() ) return;
+
+
+		// Go to the Interceptor's Metrics tab and store the properties before query.
 		ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
 		ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+		ejtt.tabMenu.clickMetricsTab();
+		Properties propsFirst = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).getProperties();
 
-		// Gen Props - nothing useful.
-		Properties props = new Properties();
-		props.setProperty("Name", "Interceptor");
-		ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValues(props);
 
 
-		/*
-  		Numeric Metrics
-				Hit/Miss Ratio	      0	     Hit/Miss Ratio
-				Read/Write Ratio	    0	     Read/Write Ratio
-				Number Of Attributes	0	     the number of cache attributes
-				Average Write Time	  0.0ms	 the average amount of time per write operation
-				Average Read Time	    0.0ms	 the average amount of time per read operation
-		 */
-		props = new Properties();
-		props.setProperty("Hit/Miss Ratio", "0");
-		props.setProperty("Read/Write Ratio", "0");
-		props.setProperty("Number Of Attributes", "0.0ms");
-		props.setProperty("Average Write Time", "0.0ms");
-		props.setProperty("Average Read Time", "0.0ms");
-		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props);
+		// Deploy an EAR.
+		ejtt.deployment.deployViaEmbJopr( DeployableTypes.EAR, ejtt.getTestFilePath(this.APP_TYPE, JBCACHE_TEST_EAR));
 
-		ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
-		
+		try {
+
+
+			// Run the test() method of the bean - performs few Hibernate operations.
+			performBeanRequest();
+
+
+			// Go back to the Interceptor's Metrics tab.
+			ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
+			ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+
+			// Gen Props - nothing useful.
+			Properties props = new Properties();
+			props.setProperty("Name", "Interceptor");
+			ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValuesEqual(props);
+
+
+			// Check that the latter values are diffrent from the former.
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(propsFirst, ValuesValidator.NOT_EQUAL);
+
+
+			// Check that these metrics didn't stay at their init values.
+			props = getInitialMetricsProperties();
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props, ValuesValidator.NOT_EQUAL);
+
+		}
+		finally {
+			ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
+		}
+
 	}
 
 
@@ -122,5 +229,127 @@
 
 
 
+	/**
+	 * Interceptor Control tab after querying Hibernate.
+	 */
+	public void testJBossCacheInterceptorControl_AfterQuery() throws IOException, EmbJoprTestException, NamingException {
+		if( isJBossConfigWithoutCache() ) return;
 
+
+		// Go to the Interceptor's Control tab and store the properties before query.
+		ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
+		ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+		ejtt.tabMenu.clickMetricsTab();
+		Properties propsFirst = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).getProperties();
+
+
+		// Deploy an EAR.
+		ejtt.deployment.deployViaEmbJopr( DeployableTypes.EAR, ejtt.getTestFilePath(this.APP_TYPE, JBCACHE_TEST_EAR));
+
+		try {
+
+
+			// Run the test() method of the bean - performs few Hibernate operations.
+			performBeanRequest();
+
+
+			// Go back to the Interceptor's Control tab and reset the statistics.
+			ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
+			ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
+			ejtt.tabMenu.clickMetricsTab();
+			Properties propsSecond = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).getProperties();
+
+			ejtt.tabMenu.clickControlTab();
+
+			ejtt.tabMenu.getTabContentBox().getButtonByLabel("Reset Statistics");
+
+			// Check that these metrics didn't stay at their previous values.
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(propsSecond, ValuesValidator.NOT_EQUAL);
+
+			// Check that these metrics are back at their initial values.
+			ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues( this.getInitialMetricsProperties(), ValuesValidator.EQUAL);
+
+		}
+		finally {
+			ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
+		}
+
+	}
+
+
+
+
+
+	// ------ Helper methods ------ //
+
+
+
+	/** Initial metrics values  - should be there after start or reset. */
+	private Properties getInitialMetricsProperties(){
+			/*
+				Numeric Metrics
+						Name	Value	Description
+					Category: performance
+						Evictions         0	the number of cache eviction operations
+						Hit/Miss Ratio    0	Hit/Miss Ratio
+						Read/Write Ratio  0	Read/Write Ratio
+						NumberOfNodes     1	the number of nodes in the cache
+						Hits              0	the number of cache attribute hits
+						Number Of Attributes	0	the number of cache attributes
+						Misses                1	the number of cache attribute misses
+						Average Write Time    0.0ms	the average amount of time per write operation
+						Stores                0	the number of cache attribute put operations
+						Average Read Time	    18.0ms	the average amount of time per read operation
+					Category: utilization
+						Elapsed Time          9.1m	the time elapsed since the cache was started
+						Time Since Reset      9.1m	the time elapsed since the cache statistics were last reset
+			 */
+			Properties props = new Properties();
+			props.setProperty("Evictions", "0");
+			props.setProperty("NumberOfNodes", "1");
+			props.setProperty("Hits", "0");
+			props.setProperty("Misses", "1");
+			props.setProperty("Stores", "0");
+			props.setProperty("Hit/Miss Ratio", "0");
+			props.setProperty("Read/Write Ratio", "0");
+			props.setProperty("Number Of Attributes", "0");
+			props.setProperty("Average Write Time", "0.0ms");
+			//props.setProperty("Average Read Time", "18.0"); // Not zero after startup.
+
+			props.setProperty("Elapsed Time", "0.0");
+			props.setProperty("Time Since Reset", "0.0m");
+
+			return props;
+	}
+
+
+
+
+
+
+
+	
+
+
+	/**
+	 * Calls the test bean's methods which do some JPA entities manipulation.
+	 * @throws javax.naming.NamingException
+	 */
+	private void performBeanRequest() throws NamingException{
+			final String BEAN_JNDI = "TestOperationBean/remote";
+
+			// Query the bean.
+			log.info("Looking up "+BEAN_JNDI+"...");
+			InitialContext ctx = new InitialContext();
+			TestOperation bean = (TestOperation) ctx.lookup(BEAN_JNDI);
+
+			log.info("Sending request...");
+			bean.test();
+	}
+
+
+
+
+
+
 }// class

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/sbm/ServiceBindingManagerTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/sbm/ServiceBindingManagerTest.java	2009-08-05 00:02:03 UTC (rev 643)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/sbm/ServiceBindingManagerTest.java	2009-08-05 00:03:31 UTC (rev 644)
@@ -32,7 +32,7 @@
 		// Go to Service Binding Managers node.
 		ejtt.navTree.getNodeByLabel(NAV_SBM).click();
 
-		ejtt.tabMenu.getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValues( new SingleProperties("Name", NAV_SBM) );
+		ejtt.tabMenu.getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValuesEqual( new SingleProperties("Name", NAV_SBM) );
 
 	}
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-08-05 00:02:03 UTC (rev 643)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-08-05 00:03:31 UTC (rev 644)
@@ -1357,7 +1357,7 @@
 		 * Checks that name/value pairs in this table mach the given values.
 		 * @throws EmbJoprTestException  if any of given values does not match with the value in this table.
 		 */
-		public void checkValues( Properties propsExpected ) throws EmbJoprTestException {
+		public void checkValuesEqual( Properties propsExpected ) throws EmbJoprTestException {
 
 			// Get this tables properties. Different table types can override this.
 			Properties propsActual = this.getProperties();
@@ -1394,13 +1394,56 @@
 			}
 		}
 
+		/**
+		 * Checks that name/value pairs in this table mach the given values.
+		 * @throws EmbJoprTestException  if any of given values does not match with the value in this table.
+		 */
+		public void checkValues( Properties propsExpected, ValuesValidator validator ) throws EmbJoprTestException {
 
+			// Get this tables properties. Different table types can override this.
+			Properties propsActual = this.getProperties();
 
+			// List the actual properties.
+			for( Object key : propsActual.keySet() ){
+				String propName = (String)key;
+				log.info("Actual property: '"+propName+"': '"+propsActual.getProperty(propName)+"'");
+			}
+
+			// List of non-equal properties.
+			List<String> failures = new ArrayList<String>();
+
+			// Check all the properties.
+			for( Object key : propsExpected.keySet() ){
+				String propName = (String)key;
+				log.info("Checking '"+propName+"'...");
+				String exp = propsExpected.getProperty(propName);
+				String act = propsActual.getProperty(propName);
+
+				exp = EmbjoprTestCase.normalizeIfNumber(exp);
+				act = EmbjoprTestCase.normalizeIfNumber(act);
+
+				String validationError = validator.validate( exp, act );
+				if( null != validationError ){
+					// If this table has a name, use it in the exception message.
+					String msgFormat = (null == this.getTableName() ? "%2$s: " : "%s - %s: ");
+					failures.add( String.format(msgFormat, this.getTableName(), propName) + validationError );
+				}
+
+				// If some did not match, throw an exception with their list.
+				if( failures.size() != 0 ){
+					throw new EmbJoprTestException( String.format("Non-matching properties: (%d of %d expected):\n", failures.size(), propsExpected.size()) + StringUtils.join(failures, "\n") );
+				}
+			}
+		}
+
+
 	}// inner class ContentTable
 
 
 
 
+
+
 	/**
 	 * Creates a data table wrapper for first found element with one of these IDs:
 	 * ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesValidator.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesValidator.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ValuesValidator.java	2009-08-05 00:03:31 UTC (rev 644)
@@ -0,0 +1,38 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jboss.jopr.jsfunit.util;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Value validators.
+ * @author Ondrej Zizka
+ */
+public interface ValuesValidator {
+	/** Returns null if values are OK, or validation error description when validation fails. */
+	public String validate( String a, String b );
+
+	public static final ValuesValidator EQUAL = new ValuesValidator() {
+		public String validate( String exp, String act ){
+			if( !StringUtils.equals( exp, act ) ){
+				return String.format( "Expected '%s', actual '%s'.", exp, act );
+			}
+			return null;
+		}
+	};
+
+
+	public static final ValuesValidator NOT_EQUAL = new ValuesValidator() {
+		public String validate( String exp, String act ){
+			if( StringUtils.equals( exp, act ) ){
+				return String.format( "Expected different values, but both were '%s'.", act );
+			}
+			return null;
+		}
+	};
+
+}
+



More information about the embjopr-commits mailing list