| 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 | |
|
| 21 | |
public Story() { |
| 22 | 6 | this(Arrays.<Scenario>asList()); |
| 23 | 6 | } |
| 24 | |
|
| 25 | |
public Story(String path) { |
| 26 | 13 | this(path, Description.EMPTY, Narrative.EMPTY, Arrays.<Scenario>asList()); |
| 27 | 13 | } |
| 28 | |
|
| 29 | |
public Story(List<Scenario> scenarios) { |
| 30 | 15 | this(Description.EMPTY, Narrative.EMPTY, scenarios); |
| 31 | 15 | } |
| 32 | |
|
| 33 | |
public Story(Description description, Narrative narrative, List<Scenario> scenarios) { |
| 34 | 22 | this((String)null, description, narrative, scenarios); |
| 35 | 22 | } |
| 36 | |
|
| 37 | |
public Story(String path, Description description, Narrative narrative, List<Scenario> scenarios) { |
| 38 | 37 | this(path, description, Meta.EMPTY, narrative, scenarios); |
| 39 | 37 | } |
| 40 | |
|
| 41 | 89 | public Story(String path, Description description, Meta meta, Narrative narrative, List<Scenario> scenarios) { |
| 42 | 89 | this.path = (path != null ? path : ""); |
| 43 | 89 | this.description = description; |
| 44 | 89 | this.narrative = narrative; |
| 45 | 89 | this.meta = meta; |
| 46 | 89 | this.scenarios = scenarios; |
| 47 | 89 | } |
| 48 | |
|
| 49 | |
public String getPath() { |
| 50 | 159 | return path; |
| 51 | |
} |
| 52 | |
|
| 53 | |
public Description getDescription() { |
| 54 | 37 | return description; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public Narrative getNarrative() { |
| 58 | 47 | return narrative; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public Meta asMeta(String prefix){ |
| 62 | 26 | Properties p = new Properties(); |
| 63 | 26 | p.setProperty(prefix+"path", path); |
| 64 | 26 | p.setProperty(prefix+"description", description.asString()); |
| 65 | 26 | p.setProperty(prefix+"narrative", narrative.toString()); |
| 66 | 26 | return new Meta(p); |
| 67 | |
} |
| 68 | |
|
| 69 | |
public Meta getMeta() { |
| 70 | 112 | return meta; |
| 71 | |
} |
| 72 | |
|
| 73 | |
public List<Scenario> getScenarios() { |
| 74 | 88 | return unmodifiableList(scenarios); |
| 75 | |
} |
| 76 | |
|
| 77 | |
public String getName() { |
| 78 | 12 | return (name != null ? name : path); |
| 79 | |
} |
| 80 | |
|
| 81 | |
public void namedAs(String name) { |
| 82 | 35 | this.name = name; |
| 83 | 35 | } |
| 84 | |
|
| 85 | |
@Override |
| 86 | |
public String toString() { |
| 87 | 5 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | |
} |