1 | |
package org.jbehave.core.model; |
2 | |
|
3 | |
import java.util.Arrays; |
4 | |
import java.util.List; |
5 | |
import java.util.Properties; |
6 | |
|
7 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
8 | |
import org.apache.commons.lang.builder.ToStringStyle; |
9 | |
|
10 | |
import static java.util.Collections.unmodifiableList; |
11 | |
|
12 | |
public class Story { |
13 | |
|
14 | |
private final String path; |
15 | |
private final Description description; |
16 | |
private final Narrative narrative; |
17 | |
private final Meta meta; |
18 | |
private final List<Scenario> scenarios; |
19 | |
private String name; |
20 | |
private final GivenStories givenStories; |
21 | |
|
22 | |
public Story() { |
23 | 6 | this(Arrays.<Scenario>asList()); |
24 | 6 | } |
25 | |
|
26 | |
public Story(String path) { |
27 | 13 | this(path, Description.EMPTY, Narrative.EMPTY, Arrays.<Scenario>asList()); |
28 | 13 | } |
29 | |
|
30 | |
public Story(List<Scenario> scenarios) { |
31 | 15 | this(Description.EMPTY, Narrative.EMPTY, scenarios); |
32 | 15 | } |
33 | |
|
34 | |
public Story(Description description, Narrative narrative, List<Scenario> scenarios) { |
35 | 21 | this((String)null, description, narrative, scenarios); |
36 | 21 | } |
37 | |
|
38 | |
public Story(String path, Description description, Narrative narrative, List<Scenario> scenarios) { |
39 | 35 | this(path, description, Meta.EMPTY, narrative, scenarios); |
40 | 35 | } |
41 | |
|
42 | |
public Story(String path, Description description, Meta meta, Narrative narrative, List<Scenario> scenarios) { |
43 | 63 | this(path, description, meta, narrative, GivenStories.EMPTY, scenarios); |
44 | 63 | } |
45 | |
|
46 | |
|
47 | 90 | public Story(String path, Description description, Meta meta, Narrative narrative, GivenStories givenStories, List<Scenario> scenarios) { |
48 | 90 | this.path = (path != null ? path : ""); |
49 | 90 | this.description = description; |
50 | 90 | this.narrative = narrative; |
51 | 90 | this.meta = meta; |
52 | 90 | this.givenStories = givenStories; |
53 | 90 | this.scenarios = scenarios; |
54 | 90 | } |
55 | |
|
56 | |
public String getPath() { |
57 | 163 | return path; |
58 | |
} |
59 | |
|
60 | |
public Description getDescription() { |
61 | 37 | return description; |
62 | |
} |
63 | |
|
64 | |
public Narrative getNarrative() { |
65 | 49 | return narrative; |
66 | |
} |
67 | |
|
68 | |
public Meta asMeta(String prefix){ |
69 | 27 | Properties p = new Properties(); |
70 | 27 | p.setProperty(prefix+"path", path); |
71 | 27 | p.setProperty(prefix+"description", description.asString()); |
72 | 27 | p.setProperty(prefix+"narrative", narrative.toString()); |
73 | 27 | return new Meta(p); |
74 | |
} |
75 | |
|
76 | |
public Meta getMeta() { |
77 | 114 | return meta; |
78 | |
} |
79 | |
|
80 | |
public GivenStories getGivenStories(){ |
81 | 23 | return givenStories; |
82 | |
} |
83 | |
|
84 | |
public List<Scenario> getScenarios() { |
85 | 88 | return unmodifiableList(scenarios); |
86 | |
} |
87 | |
|
88 | |
public String getName() { |
89 | 12 | return (name != null ? name : path); |
90 | |
} |
91 | |
|
92 | |
public void namedAs(String name) { |
93 | 36 | this.name = name; |
94 | 36 | } |
95 | |
|
96 | |
@Override |
97 | |
public String toString() { |
98 | 5 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
99 | |
} |
100 | |
|
101 | |
|
102 | |
} |