1 | |
package org.jbehave.core.model; |
2 | |
|
3 | |
import static java.util.regex.Pattern.DOTALL; |
4 | |
import static java.util.regex.Pattern.compile; |
5 | |
|
6 | |
import java.util.HashMap; |
7 | |
import java.util.Map; |
8 | |
import java.util.regex.Matcher; |
9 | |
import java.util.regex.Pattern; |
10 | |
|
11 | |
import org.apache.commons.lang.StringUtils; |
12 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
13 | |
import org.apache.commons.lang.builder.ToStringStyle; |
14 | |
|
15 | |
public class GivenStory { |
16 | |
|
17 | |
private final String givenStoryAsString; |
18 | 49 | private Map<String, String> parameters = new HashMap<String, String>(); |
19 | |
private String path; |
20 | |
private String anchor; |
21 | |
|
22 | 49 | public GivenStory(String givenStoryAsString) { |
23 | 49 | this.givenStoryAsString = givenStoryAsString.trim(); |
24 | 49 | parse(); |
25 | 49 | } |
26 | |
|
27 | |
private void parse() { |
28 | 49 | Pattern pattern = compile("(.*)\\#\\{(.*?)\\}", DOTALL); |
29 | 49 | Matcher matcher = pattern.matcher(givenStoryAsString.trim()); |
30 | 49 | if (matcher.matches()) { |
31 | 4 | path = matcher.group(1).trim(); |
32 | 4 | anchor = matcher.group(2).trim(); |
33 | |
} else { |
34 | 45 | path = givenStoryAsString; |
35 | 45 | anchor = ""; |
36 | |
} |
37 | 49 | } |
38 | |
|
39 | |
public String getPath() { |
40 | 11 | return path; |
41 | |
} |
42 | |
|
43 | |
public String getAnchor() { |
44 | 64 | return anchor; |
45 | |
} |
46 | |
|
47 | |
public boolean hasAnchor() { |
48 | 41 | return !StringUtils.isBlank(anchor); |
49 | |
} |
50 | |
|
51 | |
public Map<String, String> getParameters() { |
52 | 9 | return parameters; |
53 | |
} |
54 | |
|
55 | |
public void useParameters(Map<String, String> parameters) { |
56 | 59 | this.parameters = parameters; |
57 | 59 | } |
58 | |
|
59 | |
public String asString() { |
60 | 36 | return givenStoryAsString; |
61 | |
} |
62 | |
|
63 | |
public String toString() { |
64 | 5 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
65 | |
} |
66 | |
|
67 | |
} |