1 | |
package org.jbehave.core.embedder; |
2 | |
|
3 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
4 | |
import org.apache.commons.lang.builder.ToStringStyle; |
5 | |
import org.jbehave.core.steps.ParameterConverters; |
6 | |
|
7 | 1 | public class PropertyBasedEmbedderControls extends EmbedderControls { |
8 | |
|
9 | |
public static final String BATCH = "BATCH"; |
10 | |
public static final String IGNORE_FAILURE_IN_VIEW = "IGNORE_FAILURE_IN_VIEW"; |
11 | |
public static final String IGNORE_FAILURE_IN_STORIES = "IGNORE_FAILURE_IN_STORIES"; |
12 | |
public static final String GENERATE_VIEW_AFTER_STORIES = "GENERATE_VIEW_AFTER_STORIES"; |
13 | |
public static final String SKIP = "SKIP"; |
14 | |
public static final String VERBOSE_FAILURES = "VERBOSE_FAILURES"; |
15 | |
public static final String VERBOSE_FILTERING = "VERBOSE_FILTERING"; |
16 | |
public static final String STORY_TIMEOUTS = "STORY_TIMEOUTS"; |
17 | |
public static final String STORY_TIMEOUT_IN_SECS = "STORY_TIMEOUT_IN_SECS"; |
18 | |
public static final String STORY_TIMEOUT_IN_SECS_BY_PATH = "STORY_TIMEOUT_IN_SECS_BY_PATH"; |
19 | |
public static final String FAIL_ON_STORY_TIMEOUT = "FAIL_ON_STORY_TIMEOUT"; |
20 | |
public static final String THREADS = "THREADS"; |
21 | |
|
22 | 1 | private ParameterConverters converters = new ParameterConverters(); |
23 | |
|
24 | |
@Override |
25 | |
public boolean batch() { |
26 | 3 | return propertyAs(BATCH, Boolean.class, super.batch()); |
27 | |
} |
28 | |
|
29 | |
@Override |
30 | |
public boolean ignoreFailureInView() { |
31 | 3 | return propertyAs(IGNORE_FAILURE_IN_VIEW, Boolean.class, super.ignoreFailureInView()); |
32 | |
} |
33 | |
|
34 | |
@Override |
35 | |
public boolean ignoreFailureInStories() { |
36 | 3 | return propertyAs(IGNORE_FAILURE_IN_STORIES, Boolean.class, super.ignoreFailureInStories()); |
37 | |
} |
38 | |
|
39 | |
@Override |
40 | |
public boolean generateViewAfterStories() { |
41 | 3 | return propertyAs(GENERATE_VIEW_AFTER_STORIES, Boolean.class, super.generateViewAfterStories()); |
42 | |
} |
43 | |
|
44 | |
@Override |
45 | |
public boolean skip() { |
46 | 3 | return propertyAs(SKIP, Boolean.class, super.skip()); |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
public boolean verboseFailures() { |
51 | 3 | return propertyAs(VERBOSE_FAILURES, Boolean.class, super.verboseFailures()); |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public boolean verboseFiltering() { |
56 | 3 | return propertyAs(VERBOSE_FILTERING, Boolean.class, super.verboseFiltering()); |
57 | |
} |
58 | |
|
59 | |
@Override |
60 | |
public String storyTimeouts() { |
61 | 4 | return propertyAs(STORY_TIMEOUTS, String.class, super.storyTimeouts()); |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public long storyTimeoutInSecs() { |
66 | 3 | return propertyAs(STORY_TIMEOUT_IN_SECS, Long.class, super.storyTimeoutInSecs()); |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
public String storyTimeoutInSecsByPath() { |
71 | 3 | return propertyAs(STORY_TIMEOUT_IN_SECS_BY_PATH, String.class, super.storyTimeoutInSecsByPath()); |
72 | |
} |
73 | |
|
74 | |
@Override |
75 | |
public boolean failOnStoryTimeout() { |
76 | 2 | return propertyAs(FAIL_ON_STORY_TIMEOUT, Boolean.class, super.failOnStoryTimeout()); |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public int threads() { |
81 | 3 | return propertyAs(THREADS, Integer.class, super.threads()); |
82 | |
} |
83 | |
|
84 | |
@SuppressWarnings("unchecked") |
85 | |
private <T> T propertyAs(String name, Class<T> type, T defaultValue) { |
86 | 36 | String property = System.getProperty(name); |
87 | 36 | if ( property == null ){ |
88 | 25 | return defaultValue; |
89 | |
} |
90 | 11 | return (T) converters.convert(property, type); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public String toString() { |
95 | |
|
96 | |
|
97 | 1 | return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) |
98 | 1 | .append("batch", batch()) |
99 | 1 | .append("skip", skip()) |
100 | 1 | .append("generateViewAfterStories", generateViewAfterStories()) |
101 | 1 | .append("ignoreFailureInStories", ignoreFailureInStories()) |
102 | 1 | .append("ignoreFailureInView", ignoreFailureInView()) |
103 | 1 | .append("verboseFailures", verboseFailures()) |
104 | 1 | .append("verboseFiltering", verboseFiltering()) |
105 | 1 | .append("storyTimeoutInSecs", storyTimeoutInSecs()) |
106 | 1 | .append("storyTimeoutInSecsByPath", storyTimeoutInSecsByPath()) |
107 | 1 | .append("threads", threads()) |
108 | 1 | .toString(); |
109 | |
} |
110 | |
|
111 | |
} |