You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2014/08/20 08:42:32 UTC

[19/50] [abbrv] Progress on dispatcher request / response tests

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/fc96a5ea/portlet-tck_3.0/common/src/main/java/javax/portlet/tck/beans/CompareUtils.java
----------------------------------------------------------------------
diff --git a/portlet-tck_3.0/common/src/main/java/javax/portlet/tck/beans/CompareUtils.java b/portlet-tck_3.0/common/src/main/java/javax/portlet/tck/beans/CompareUtils.java
index 992bab2..7537324 100644
--- a/portlet-tck_3.0/common/src/main/java/javax/portlet/tck/beans/CompareUtils.java
+++ b/portlet-tck_3.0/common/src/main/java/javax/portlet/tck/beans/CompareUtils.java
@@ -23,6 +23,7 @@ import java.util.Enumeration;
 import java.util.Formatter;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 
 /** Contains some useful comparison methods 
@@ -54,6 +55,33 @@ public class CompareUtils {
    }
 
    /**
+    * Compares two strings and sets the test result accordingly. 
+    * If both strings are null, comparison is successful.
+    * 
+    * @param asrc Source of 1st string to compare
+    * @param a    1st string to compare
+    * @param bsrc Source of 2nd string to compare
+    * @param b    2nd string to compare
+    * @param tr   test result to be updated
+    */
+   static public void stringsEqual(String asrc, String a, String bsrc, String b, TestResult tr) {
+      boolean ok = (a==null) && (b == null);
+      if (!ok) {
+         if ((a != null) && (b != null)) {
+            ok = a.equals(b);
+         }
+         if (!ok) {
+            a = (a==null) ? "null" : ("\"" + a + "\"");
+            b = (b==null) ? "null" : ("\"" + b + "\"");
+            String str = "Error: " + a + "from " + asrc + " does not equal " + 
+                         b + " from " + bsrc + ".";
+            tr.appendTcDetail(str);
+         }
+      }
+      tr.setTcSuccess(ok);
+   }
+
+   /**
     * Compares two Enumerations and sets the test result accordingly. 
     * If both strings are empty, comparison is successful.
     * 
@@ -101,7 +129,9 @@ public class CompareUtils {
 
    /**
     * Compares two Map<String, String[]>s and sets the test result accordingly. 
-    * If both strings are empty, comparison is successful.
+    * If both maps are empty, comparison is successful.
+    * 
+    * This compares only the map keys, not the values.
     * 
     * @param aname   Name of 1st Map<String, String[]> to compare
     * @param a       1st Map<String, String[]> to compare
@@ -137,4 +167,45 @@ public class CompareUtils {
       }
       tr.setTcSuccess(ok);
    }
+
+   /**
+    * Compares two Sets and generates the test result accordingly. 
+    * If both sets are empty, comparison is successful.
+    * 
+    * @param aname   name of 1st Set to compare
+    * @param a       1st Set to compare
+    * @param bname   name of 2nd Set to compare
+    * @param b       2nd Set to compare
+    * @param tr      test result to be updated
+    */
+   @SuppressWarnings({ "rawtypes", "unchecked" })
+   static public void setsEqual(String aname, Set<? extends Object> a, 
+                                String bname, Set<? extends Object> b, TestResult tr) {
+
+      boolean ok = a.equals(b);
+      
+      // if not OK, write debug output:
+      if (!ok) {
+         StringBuffer sb = new StringBuffer(256);
+         Formatter fmtr = new Formatter(sb);
+         String str = "<br/>In %1$s but not in %2$s: <br/>\n";
+         fmtr.format(str, aname, bname);
+         HashSet diffs = new HashSet();
+         diffs.addAll(a);
+         diffs.removeAll(b);
+         for (Object key : diffs) {
+            sb.append(key.toString() + "<br/>\n");
+         }
+         fmtr.format(str, bname, aname);
+         diffs.clear();
+         diffs.addAll(b);
+         diffs.removeAll(a);
+         for (Object key : diffs) {
+            sb.append(key.toString() + "<br/>\n");
+         }
+         fmtr.close();
+         tr.appendTcDetail(sb.toString());
+      }
+      tr.setTcSuccess(ok);
+   }
 }