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 GivenStories givenStories; |
19 | |
private final Lifecycle lifecycle; |
20 | |
private final List<Scenario> scenarios; |
21 | |
private String name; |
22 | |
|
23 | |
public Story() { |
24 | 6 | this(Arrays.<Scenario>asList()); |
25 | 6 | } |
26 | |
|
27 | |
public Story(String path) { |
28 | 16 | this(path, Description.EMPTY, Narrative.EMPTY, Arrays.<Scenario>asList()); |
29 | 16 | } |
30 | |
|
31 | |
public Story(List<Scenario> scenarios) { |
32 | 15 | this(Description.EMPTY, Narrative.EMPTY, scenarios); |
33 | 15 | } |
34 | |
|
35 | |
public Story(Description description, Narrative narrative, List<Scenario> scenarios) { |
36 | 23 | this((String)null, description, narrative, scenarios); |
37 | 23 | } |
38 | |
|
39 | |
public Story(String path, Description description, Narrative narrative, List<Scenario> scenarios) { |
40 | 40 | this(path, description, Meta.EMPTY, narrative, scenarios); |
41 | 40 | } |
42 | |
|
43 | |
public Story(String path, Description description, Meta meta, Narrative narrative, List<Scenario> scenarios) { |
44 | 68 | this(path, description, meta, narrative, GivenStories.EMPTY, scenarios); |
45 | 68 | } |
46 | |
|
47 | |
public Story(String path, Description description, Meta meta, Narrative narrative, GivenStories givenStories, List<Scenario> scenarios) { |
48 | 70 | this(path, description, meta, narrative, givenStories, Lifecycle.EMPTY, scenarios); |
49 | 70 | } |
50 | |
|
51 | 105 | public Story(String path, Description description, Meta meta, Narrative narrative, GivenStories givenStories, Lifecycle lifecycle, List<Scenario> scenarios) { |
52 | 105 | this.path = (path != null ? path : ""); |
53 | 105 | this.description = description; |
54 | 105 | this.narrative = narrative; |
55 | 105 | this.meta = meta; |
56 | 105 | this.givenStories = givenStories; |
57 | 105 | this.lifecycle = lifecycle; |
58 | 105 | this.scenarios = scenarios; |
59 | 105 | } |
60 | |
|
61 | |
public String getPath() { |
62 | 181 | return path; |
63 | |
} |
64 | |
|
65 | |
public Description getDescription() { |
66 | 43 | return description; |
67 | |
} |
68 | |
|
69 | |
public Narrative getNarrative() { |
70 | 54 | return narrative; |
71 | |
} |
72 | |
|
73 | |
public Meta asMeta(String prefix){ |
74 | 34 | Properties p = new Properties(); |
75 | 34 | p.setProperty(prefix+"path", path); |
76 | 34 | p.setProperty(prefix+"description", description.asString()); |
77 | 34 | p.setProperty(prefix+"narrative", narrative.toString()); |
78 | 34 | return new Meta(p); |
79 | |
} |
80 | |
|
81 | |
public Meta getMeta() { |
82 | 134 | return meta; |
83 | |
} |
84 | |
|
85 | |
public GivenStories getGivenStories(){ |
86 | 32 | return givenStories; |
87 | |
} |
88 | |
|
89 | |
public Lifecycle getLifecycle(){ |
90 | 65 | return lifecycle; |
91 | |
} |
92 | |
|
93 | |
public List<Scenario> getScenarios() { |
94 | 104 | return unmodifiableList(scenarios); |
95 | |
} |
96 | |
|
97 | |
public String getName() { |
98 | 12 | return (name != null ? name : path); |
99 | |
} |
100 | |
|
101 | |
public void namedAs(String name) { |
102 | 44 | this.name = name; |
103 | 44 | } |
104 | |
|
105 | |
@Override |
106 | |
public String toString() { |
107 | 6 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
} |