import org.argeo.slc.core.test.context.SimpleContextAware;\r
import org.argeo.slc.test.context.ContextAware;\r
\r
+/**\r
+ * Overrides Values and Expected values of a target \r
+ * <code>SimpleContextAware</code> with the corresponding\r
+ * values and expected values of a source <code>ContextAware</code>\r
+ *\r
+ */\r
public class OverrideContextAware implements Runnable {\r
\r
private ContextAware source;\r
\r
private SimpleContextAware target;\r
\r
-\r
- public void setSource(ContextAware source) {\r
- this.source = source;\r
- }\r
-\r
-\r
- public void setTarget(SimpleContextAware target) {\r
- this.target = target;\r
- }\r
-\r
-\r
+ /**\r
+ * Whether an exception shall be thrown if a value\r
+ * or expected value of the source is not defined\r
+ * in the target\r
+ */\r
+ private Boolean failIfUndefinedInSource = true;\r
+ \r
public void run() {\r
// override values\r
if(source.getValues() != null)\r
for(String key : source.getValues().keySet()) {\r
- if(!target.getValues().containsKey(key)) {\r
+ if(failIfUndefinedInSource && !target.getValues().containsKey(key)) {\r
throw new SlcException("No entry in target values for key '" + key + "'");\r
}\r
target.getValues().put(key, source.getValues().get(key));\r
// override expected values\r
if(source.getExpectedValues() != null)\r
for(String key : source.getExpectedValues().keySet()) {\r
- if(!target.getExpectedValues().containsKey(key)) {\r
+ if(failIfUndefinedInSource && !target.getExpectedValues().containsKey(key)) {\r
throw new SlcException("No entry in target expected values for key '" + key + "'");\r
}\r
target.getExpectedValues().put(key, source.getExpectedValues().get(key));\r
} \r
} \r
+ \r
+ public void setSource(ContextAware source) {\r
+ this.source = source;\r
+ }\r
+\r
+ public void setTarget(SimpleContextAware target) {\r
+ this.target = target;\r
+ }\r
+\r
+ public void setFailIfUndefinedInSource(Boolean failIfUndefinedInSource) {\r
+ this.failIfUndefinedInSource = failIfUndefinedInSource;\r
+ } \r
}\r