+/*\r
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\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
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
package org.argeo.slc.core.execution.tasks;\r
\r
import org.argeo.slc.SlcException;\r
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