Introduce TreeRelatedHelper
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 15 Jan 2008 18:51:19 +0000 (18:51 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 15 Jan 2008 18:51:19 +0000 (18:51 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@921 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java [new file with mode: 0644]
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextHelper.java [deleted file]
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java [new file with mode: 0644]
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/package.html [new file with mode: 0644]

diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRelatedHelper.java
new file mode 100644 (file)
index 0000000..6e3a53a
--- /dev/null
@@ -0,0 +1,27 @@
+package org.argeo.slc.core.structure.tree;\r
+\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
+\r
+/**\r
+ * Provides default implementations of some methods of\r
+ * <code>TreeSRelated</code>.\r
+ */\r
+public abstract class TreeSRelatedHelper implements TreeSRelated {\r
+       private TreeSPath basePath;\r
+       private StructureRegistry<TreeSPath> registry;\r
+\r
+\r
+       public TreeSPath getBasePath() {\r
+               return basePath;\r
+       }\r
+\r
+       public StructureRegistry<TreeSPath> getRegistry() {\r
+               return registry;\r
+       }\r
+\r
+       public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,\r
+                       TreeSPath path) {\r
+               basePath = path;\r
+               this.registry = registry;\r
+       }\r
+}\r
diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextHelper.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextHelper.java
deleted file mode 100644 (file)
index d14e67b..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-package org.argeo.slc.core.test.context;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-\r
-import org.argeo.slc.core.structure.StructureAware;\r
-import org.argeo.slc.core.structure.StructureElement;\r
-import org.argeo.slc.core.structure.StructureRegistry;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.structure.tree.TreeSRelated;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.TestResult;\r
-import org.argeo.slc.core.test.TestStatus;\r
-\r
-public class ContextHelper {\r
-       private final static Log log = LogFactory.getLog(ContextHelper.class);\r
-\r
-       public static void compareReachedExpected(ContextAware contextAware,\r
-                       TestResult testResult, TreeSRelated treeSRelated) {\r
-               for (String key : contextAware.getExpectedValues().keySet()) {\r
-\r
-                       // Register in structure\r
-                       if (treeSRelated != null) {\r
-                               if (treeSRelated.getBasePath() != null) {\r
-                                       TreeSPath path = treeSRelated.getBasePath()\r
-                                                       .createChild(key);\r
-                                       StructureRegistry<TreeSPath> registry = treeSRelated\r
-                                                       .getRegistry();\r
-                                       final StructureElement element = treeSRelated\r
-                                                       .getStructureElement(key);\r
-                                       registry.register(path, element);\r
-                                       if (testResult instanceof StructureAware)\r
-                                               ((StructureAware<TreeSPath>) testResult)\r
-                                                               .notifyCurrentPath(registry, path);\r
-\r
-                                       if (log.isDebugEnabled())\r
-                                               log.debug("Checking key " + key + " for path " + path);\r
-                               }\r
-                       }\r
-\r
-                       // Compare expected values with reached ones\r
-                       Object expectedValue = contextAware.getExpectedValues().get(key);\r
-\r
-                       if (contextAware.getValues().containsKey(key)) {\r
-                               Object reachedValue = contextAware.getValues().get(key);\r
-\r
-                               if (expectedValue.equals(reachedValue)) {\r
-                                       testResult.addResultPart(new SimpleResultPart(\r
-                                                       TestStatus.PASSED, "Values matched for key '" + key\r
-                                                                       + "'"));\r
-                               } else {\r
-                                       testResult.addResultPart(new SimpleResultPart(\r
-                                                       TestStatus.FAILED, "Mismatch for key '" + key\r
-                                                                       + "': expected '" + expectedValue\r
-                                                                       + "' but reached '" + reachedValue + "'"));\r
-                               }\r
-                       } else {\r
-                               testResult.addResultPart(new SimpleResultPart(\r
-                                               TestStatus.FAILED, "No value reached for key '" + key\r
-                                                               + "'"));\r
-                       }\r
-\r
-                       if (treeSRelated != null) {\r
-                               if (treeSRelated.getBasePath() != null) {\r
-                                       if (testResult instanceof StructureAware) {\r
-                                               ((StructureAware<TreeSPath>) testResult)\r
-                                                               .notifyCurrentPath(treeSRelated.getRegistry(),\r
-                                                                               treeSRelated.getBasePath());\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-}\r
diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java
new file mode 100644 (file)
index 0000000..4f9d6ea
--- /dev/null
@@ -0,0 +1,79 @@
+package org.argeo.slc.core.test.context;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+import org.argeo.slc.core.structure.StructureAware;\r
+import org.argeo.slc.core.structure.StructureElement;\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
+import org.argeo.slc.core.structure.tree.TreeSPath;\r
+import org.argeo.slc.core.structure.tree.TreeSRelated;\r
+import org.argeo.slc.core.test.SimpleResultPart;\r
+import org.argeo.slc.core.test.TestResult;\r
+import org.argeo.slc.core.test.TestStatus;\r
+\r
+public class ContextUtils {\r
+       private final static Log log = LogFactory.getLog(ContextUtils.class);\r
+\r
+       public static void compareReachedExpected(ContextAware contextAware,\r
+                       TestResult testResult, TreeSRelated treeSRelated) {\r
+               for (String key : contextAware.getExpectedValues().keySet()) {\r
+\r
+                       // Register in structure\r
+                       if (treeSRelated != null) {\r
+                               if (treeSRelated.getBasePath() != null) {\r
+                                       TreeSPath path = treeSRelated.getBasePath()\r
+                                                       .createChild(key);\r
+                                       StructureRegistry<TreeSPath> registry = treeSRelated\r
+                                                       .getRegistry();\r
+                                       final StructureElement element = treeSRelated\r
+                                                       .getStructureElement(key);\r
+                                       registry.register(path, element);\r
+                                       if (testResult instanceof StructureAware)\r
+                                               ((StructureAware<TreeSPath>) testResult)\r
+                                                               .notifyCurrentPath(registry, path);\r
+\r
+                                       if (log.isDebugEnabled())\r
+                                               log.debug("Checking key " + key + " for path " + path);\r
+                               }\r
+                       }\r
+\r
+                       // Compare expected values with reached ones\r
+                       Object expectedValue = contextAware.getExpectedValues().get(key);\r
+\r
+                       if (contextAware.getValues().containsKey(key)) {\r
+                               Object reachedValue = contextAware.getValues().get(key);\r
+\r
+                               if (expectedValue.equals(reachedValue)) {\r
+                                       testResult.addResultPart(new SimpleResultPart(\r
+                                                       TestStatus.PASSED, "Values matched for key '" + key\r
+                                                                       + "'"));\r
+                               } else {\r
+                                       testResult.addResultPart(new SimpleResultPart(\r
+                                                       TestStatus.FAILED, "Mismatch for key '" + key\r
+                                                                       + "': expected '" + expectedValue\r
+                                                                       + "' but reached '" + reachedValue + "'"));\r
+                               }\r
+                       } else {\r
+                               testResult.addResultPart(new SimpleResultPart(\r
+                                               TestStatus.FAILED, "No value reached for key '" + key\r
+                                                               + "'"));\r
+                       }\r
+\r
+                       if (treeSRelated != null) {\r
+                               if (treeSRelated.getBasePath() != null) {\r
+                                       if (testResult instanceof StructureAware) {\r
+                                               ((StructureAware<TreeSPath>) testResult)\r
+                                                               .notifyCurrentPath(treeSRelated.getRegistry(),\r
+                                                                               treeSRelated.getBasePath());\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       /** Makes sure this cannot be instantiated. */\r
+       private ContextUtils() {\r
+\r
+       }\r
+}\r
diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/package.html b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/package.html
new file mode 100644 (file)
index 0000000..cd08d63
--- /dev/null
@@ -0,0 +1,6 @@
+<html>\r
+<head></head>\r
+<body>\r
+Context variables to be passed between parts of tests.\r
+</body>\r
+</html>
\ No newline at end of file