/*\r
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
+ * Copyright (C) 2007-2012 Mathieu Baudier\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
*/\r
-\r
package org.argeo.slc.core.test.context;\r
\r
import java.util.Map;\r
\r
import org.apache.commons.logging.Log;\r
import org.apache.commons.logging.LogFactory;\r
-\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.structure.StructureAware;\r
-import org.argeo.slc.structure.StructureElement;\r
-import org.argeo.slc.structure.StructureRegistry;\r
import org.argeo.slc.test.TestResult;\r
import org.argeo.slc.test.TestStatus;\r
import org.argeo.slc.test.context.ContextAware;\r
import org.argeo.slc.test.context.ParentContextAware;\r
\r
+/** Utilities for comparing and synchronising contexts. */\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
+ TestResult testResult) {\r
for (String key : contextAware.getExpectedValues().keySet()) {\r
\r
// Compare expected values with reached ones\r
continue;\r
}\r
\r
- // Register in structure\r
- registerInStructure(testResult, treeSRelated, key);\r
-\r
if (contextAware.getValues().containsKey(key)) {\r
Object reachedValue = contextAware.getValues().get(key);\r
\r
TestStatus.FAILED, "No value reached for key '" + key\r
+ "'"));\r
}\r
- resetStructure(testResult, treeSRelated);\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- private static void registerInStructure(TestResult testResult,\r
- TreeSRelated treeSRelated, String key) {\r
- if (treeSRelated != null) {\r
- if (treeSRelated.getBasePath() != null) {\r
- TreeSPath path = treeSRelated.getBasePath().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).notifyCurrentPath(\r
- registry, path);\r
-\r
- if (log.isDebugEnabled())\r
- log.debug("Checking key " + key + " for path " + path);\r
- }\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- private static void resetStructure(TestResult testResult,\r
- TreeSRelated treeSRelated) {\r
- if (treeSRelated != null) {\r
- if (treeSRelated.getBasePath() != null) {\r
- if (testResult instanceof StructureAware) {\r
- ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(\r
- treeSRelated.getRegistry(), treeSRelated\r
- .getBasePath());\r
- }\r
- }\r
}\r
}\r
\r
// same keys\r
Map<String, Object> expectedValuesCommonChild = new TreeMap<String, Object>(\r
expectedValuesCommon);\r
- putNotContained(expectedValuesCommonChild, child\r
- .getExpectedValues());\r
+ putNotContained(expectedValuesCommonChild,\r
+ child.getExpectedValues());\r
\r
if (child instanceof ParentContextAware) {\r
// Recursive sync\r