]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/OverrideContextAware.java
Adds Unit Tests for ExcelGeneratorSource and AutouiRunnableFactory
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / OverrideContextAware.java
1 package org.argeo.slc.core.execution.tasks;
2
3 import org.argeo.slc.SlcException;
4 import org.argeo.slc.core.test.context.SimpleContextAware;
5 import org.argeo.slc.test.context.ContextAware;
6
7 /**
8 * Overrides Values and Expected values of a target
9 * <code>SimpleContextAware</code> with the corresponding
10 * values and expected values of a source <code>ContextAware</code>
11 *
12 */
13 public class OverrideContextAware implements Runnable {
14
15 private ContextAware source;
16
17 private SimpleContextAware target;
18
19 /**
20 * Whether an exception shall be thrown if a value
21 * or expected value of the source is not defined
22 * in the target
23 */
24 private Boolean failIfUndefinedInSource = true;
25
26 public void run() {
27 // override values
28 if(source.getValues() != null)
29 for(String key : source.getValues().keySet()) {
30 if(failIfUndefinedInSource && !target.getValues().containsKey(key)) {
31 throw new SlcException("No entry in target values for key '" + key + "'");
32 }
33 target.getValues().put(key, source.getValues().get(key));
34 }
35
36 // override expected values
37 if(source.getExpectedValues() != null)
38 for(String key : source.getExpectedValues().keySet()) {
39 if(failIfUndefinedInSource && !target.getExpectedValues().containsKey(key)) {
40 throw new SlcException("No entry in target expected values for key '" + key + "'");
41 }
42 target.getExpectedValues().put(key, source.getExpectedValues().get(key));
43 }
44 }
45
46 public void setSource(ContextAware source) {
47 this.source = source;
48 }
49
50 public void setTarget(SimpleContextAware target) {
51 this.target = target;
52 }
53
54 public void setFailIfUndefinedInSource(Boolean failIfUndefinedInSource) {
55 this.failIfUndefinedInSource = failIfUndefinedInSource;
56 }
57 }