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_TIMEOUT_IN_SECS = "STORY_TIMEOUT_IN_SECS"; |
17 | |
public static final String FAIL_ON_STORY_TIMEOUT = "FAIL_ON_STORY_TIMEOUT"; |
18 | |
public static final String THREADS = "THREADS"; |
19 | |
|
20 | 1 | private ParameterConverters converters = new ParameterConverters(); |
21 | |
|
22 | |
@Override |
23 | |
public boolean batch() { |
24 | 2 | return propertyAs(BATCH, Boolean.class, super.batch()); |
25 | |
} |
26 | |
|
27 | |
@Override |
28 | |
public boolean ignoreFailureInView() { |
29 | 2 | return propertyAs(IGNORE_FAILURE_IN_VIEW, Boolean.class, super.ignoreFailureInView()); |
30 | |
} |
31 | |
|
32 | |
@Override |
33 | |
public boolean ignoreFailureInStories() { |
34 | 2 | return propertyAs(IGNORE_FAILURE_IN_STORIES, Boolean.class, super.ignoreFailureInStories()); |
35 | |
} |
36 | |
|
37 | |
@Override |
38 | |
public boolean generateViewAfterStories() { |
39 | 2 | return propertyAs(GENERATE_VIEW_AFTER_STORIES, Boolean.class, super.generateViewAfterStories()); |
40 | |
} |
41 | |
|
42 | |
@Override |
43 | |
public boolean skip() { |
44 | 2 | return propertyAs(SKIP, Boolean.class, super.skip()); |
45 | |
} |
46 | |
|
47 | |
@Override |
48 | |
public boolean verboseFailures() { |
49 | 2 | return propertyAs(VERBOSE_FAILURES, Boolean.class, super.verboseFailures()); |
50 | |
} |
51 | |
|
52 | |
@Override |
53 | |
public boolean verboseFiltering() { |
54 | 2 | return propertyAs(VERBOSE_FILTERING, Boolean.class, super.verboseFiltering()); |
55 | |
} |
56 | |
|
57 | |
@Override |
58 | |
public long storyTimeoutInSecs() { |
59 | 2 | return propertyAs(STORY_TIMEOUT_IN_SECS, Long.class, super.storyTimeoutInSecs()); |
60 | |
} |
61 | |
|
62 | |
|
63 | |
@Override |
64 | |
public boolean failOnStoryTimeout() { |
65 | 2 | return propertyAs(FAIL_ON_STORY_TIMEOUT, Boolean.class, super.failOnStoryTimeout()); |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public int threads() { |
70 | 2 | return propertyAs(THREADS, Integer.class, super.threads()); |
71 | |
} |
72 | |
|
73 | |
@SuppressWarnings("unchecked") |
74 | |
private <T> T propertyAs(String name, Class<T> type, T defaultValue) { |
75 | 20 | String property = System.getProperty(name); |
76 | 20 | if ( property == null ){ |
77 | 10 | return defaultValue; |
78 | |
} |
79 | 10 | return (T) converters.convert(property, type); |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public String toString() { |
84 | 1 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
85 | |
} |
86 | |
|
87 | |
} |