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