- Revision
- 1483
- Author
- mauro
- Date
- 2009-12-28 09:32:43 -0600 (Mon, 28 Dec 2009)
Log Message
JBEHAVE-229: Refactored PatternScenarioParser to only depend on KeyWords. Configuration dependency deprecated.
Modified Paths
- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java
- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java
- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java
- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/ScenarioFileLoaderBehaviour.java
- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/MostUsefulConfiguration.java
- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java
Diff
Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java (1482 => 1483)
--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java 2009-12-28 15:18:39 UTC (rev 1482) +++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java 2009-12-28 15:32:43 UTC (rev 1483) @@ -25,7 +25,7 @@ super(new PropertyBasedConfiguration() { @Override public ScenarioDefiner forDefiningScenarios() { - return new ClasspathScenarioDefiner(converter, new PatternScenarioParser(this)); + return new ClasspathScenarioDefiner(converter, new PatternScenarioParser(keywords())); } @Override
Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java (1482 => 1483)
--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java 2009-12-28 15:18:39 UTC (rev 1482) +++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java 2009-12-28 15:32:43 UTC (rev 1483) @@ -27,7 +27,7 @@ // use underscored camel case scenario files with extension ".scenario" return new ClasspathScenarioDefiner( new UnderscoredCamelCaseResolver(".scenario"), - new PatternScenarioParser(this), classLoader); + new PatternScenarioParser(keywords()), classLoader); } @Override
Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java (1482 => 1483)
--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java 2009-12-28 15:18:39 UTC (rev 1482) +++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java 2009-12-28 15:32:43 UTC (rev 1483) @@ -8,10 +8,10 @@ import java.util.List; -import org.jbehave.scenario.PropertyBasedConfiguration; +import org.jbehave.scenario.definition.ExamplesTable; import org.jbehave.scenario.definition.ScenarioDefinition; import org.jbehave.scenario.definition.StoryDefinition; -import org.jbehave.scenario.definition.ExamplesTable; +import org.jbehave.scenario.i18n.I18nKeyWords; import org.junit.Ignore; import org.junit.Test; @@ -19,10 +19,10 @@ public class PatternScenarioParserBehaviour { private static final String NL = "\n"; + private ScenarioParser parser = new PatternScenarioParser(new I18nKeyWords()); @Test public void shouldExtractGivensWhensAndThensFromSimpleScenarios() { - ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); StoryDefinition story = parser.defineStoryFrom( "Given a scenario" + NL + "When I parse it" + NL + @@ -36,7 +36,6 @@ @Test public void shouldExtractGivensWhensAndThensFromSimpleScenariosContainingKeywordsAsPartOfTheContent() { - ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); StoryDefinition story = parser.defineStoryFrom( "Given a scenario Givenly" + NL + "When I parse it to Whenever" + NL + @@ -52,7 +51,6 @@ @Test public void shouldExtractGivensWhensAndThensFromMultilineScenarios() { - ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); String wholeStory = "Given a scenario" + NL + "with this line" + NL + @@ -82,7 +80,7 @@ "When I run the scenario" + NL + "Then I should see this in the output"; - StoryDefinition story = new PatternScenarioParser(new PropertyBasedConfiguration()).defineStoryFrom(wholeStory, null); + StoryDefinition story = parser.defineStoryFrom(wholeStory, null); ensureThat(story.getScenarios().get(0).getTitle(), equalTo("A title\n that is spread across\n multiple lines")); } @@ -94,7 +92,6 @@ "Given my scenario" + NL + NL + "Scenario: the second scenario" + NL + NL + "Given my second scenario"; - PatternScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); StoryDefinition story = parser.defineStoryFrom(wholeStory, null); ensureThat(story.getScenarios().get(0).getTitle(), equalTo("the first scenario")); @@ -128,7 +125,7 @@ "Then I should see this in the output" + NL + "And I should see this in the output" + NL; - StoryDefinition story = new PatternScenarioParser(new PropertyBasedConfiguration()).defineStoryFrom(wholeStory, null); + StoryDefinition story = parser.defineStoryFrom(wholeStory, null); ensureThat(story.getBlurb().asString(), equalTo("Story: I can output narratives" + NL + NL + "As a developer" + NL + @@ -163,14 +160,13 @@ @Test public void shouldParseLongStoryWithKeywordSplitScenarios() { - ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()); ensureLongStoryCanBeParsed(parser); } @Test @Ignore("on Windows, it should fail due to regex stack overflow") public void shouldParseLongStoryWithPatternSplitScenarios() { - ScenarioParser parser = new PatternScenarioParser(new PropertyBasedConfiguration()){ + ScenarioParser parser = new PatternScenarioParser(new I18nKeyWords()){ @Override protected List<String> splitScenarios(String allScenariosInFile) { @@ -222,7 +218,7 @@ "|a|b|c|" + NL + "|d|e|f|"; - StoryDefinition story = new PatternScenarioParser(new PropertyBasedConfiguration()).defineStoryFrom(wholeStory, null); + StoryDefinition story = parser.defineStoryFrom(wholeStory, null); ScenarioDefinition scenario = story.getScenarios().get(0); ensureThat(scenario.getTitle(), equalTo("A template scenario with table values")); @@ -257,7 +253,7 @@ "When I run the scenario of name <two>" + NL + "Then I should see <three> in the output"; - StoryDefinition story = new PatternScenarioParser(new PropertyBasedConfiguration()).defineStoryFrom(wholeStory, null); + StoryDefinition story = parser.defineStoryFrom(wholeStory, null); ScenarioDefinition scenario = story.getScenarios().get(0); ensureThat(scenario.getTitle(), equalTo("A scenario with given scenarios"));
Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/ScenarioFileLoaderBehaviour.java (1482 => 1483)
--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/ScenarioFileLoaderBehaviour.java 2009-12-28 15:18:39 UTC (rev 1482) +++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/ScenarioFileLoaderBehaviour.java 2009-12-28 15:32:43 UTC (rev 1483) @@ -6,10 +6,10 @@ import java.io.IOException; import java.io.InputStream; -import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.JUnitScenario; import org.jbehave.scenario.errors.InvalidScenarioResourceException; import org.jbehave.scenario.errors.ScenarioNotFoundException; +import org.jbehave.scenario.i18n.I18nKeyWords; import org.jbehave.scenario.parser.scenarios.MyPendingScenario; import org.junit.Test; @@ -39,7 +39,7 @@ @Test(expected = InvalidScenarioResourceException.class) public void cannotLoadScenarioForInvalidResource() { - ClasspathScenarioDefiner loader = new ClasspathScenarioDefiner(new UnderscoredCamelCaseResolver(), new PatternScenarioParser(new PropertyBasedConfiguration()), new InvalidClassLoader()); + ClasspathScenarioDefiner loader = new ClasspathScenarioDefiner(new UnderscoredCamelCaseResolver(), new PatternScenarioParser(new I18nKeyWords()), new InvalidClassLoader()); loader.loadScenarioDefinitionsFor(MyPendingScenario.class); }
Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/MostUsefulConfiguration.java (1482 => 1483)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/MostUsefulConfiguration.java 2009-12-28 15:18:39 UTC (rev 1482) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/MostUsefulConfiguration.java 2009-12-28 15:32:43 UTC (rev 1483) @@ -48,7 +48,7 @@ * camel-cased name - so MyScenario.java maps to my_scenario. */ public ScenarioDefiner forDefiningScenarios() { - return new ClasspathScenarioDefiner(new PatternScenarioParser(this)); + return new ClasspathScenarioDefiner(new PatternScenarioParser(keywords())); } /**
Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java (1482 => 1483)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2009-12-28 15:18:39 UTC (rev 1482) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2009-12-28 15:32:43 UTC (rev 1483) @@ -9,29 +9,36 @@ import java.util.regex.Pattern; import org.jbehave.scenario.Configuration; -import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.definition.Blurb; +import org.jbehave.scenario.definition.ExamplesTable; import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.definition.ScenarioDefinition; import org.jbehave.scenario.definition.StoryDefinition; -import org.jbehave.scenario.definition.ExamplesTable; +import org.jbehave.scenario.i18n.I18nKeyWords; /** - * Pattern-based scenario parser, which uses the configured keywords to find the + * Pattern-based scenario parser, which uses the keywords provided to find the * steps in the text scenarios. */ public class PatternScenarioParser implements ScenarioParser { private static final String NONE = ""; private static final String COMMA = ","; - private final Configuration configuration; + private final KeyWords keywords; public PatternScenarioParser() { - this(new PropertyBasedConfiguration()); + this(new I18nKeyWords()); } + public PatternScenarioParser(KeyWords keywords) { + this.keywords = keywords; + } + + /** + * @deprecated Since 2.4, use PatternScenarioParser(KeyWords) + */ public PatternScenarioParser(Configuration configuration) { - this.configuration = configuration; + this(configuration.keywords()); } public StoryDefinition defineStoryFrom(String wholeStoryAsString, String storyPath) { @@ -94,7 +101,7 @@ } private Blurb parseBlurbFrom(String wholeStoryAsString) { - String scenario = configuration.keywords().scenario(); + String scenario = keywords.scenario(); Pattern findStoryBlurb = compile("(.*?)(" + scenario + ").*", DOTALL); Matcher matcher = findStoryBlurb.matcher(wholeStoryAsString); if (matcher.find()) { @@ -117,7 +124,7 @@ protected List<String> splitScenariosWithKeyword(String allScenariosInFile) { List<String> scenarios = new ArrayList<String>(); - String scenarioKeyword = configuration.keywords().scenario(); + String scenarioKeyword = keywords.scenario(); String allScenarios = null; // chomp off anything before first keyword, if found @@ -163,13 +170,12 @@ } private Pattern patternToPullScenariosIntoGroupFour() { - String scenario = configuration.keywords().scenario(); + String scenario = keywords.scenario(); return compile(".*?((" + scenario + ") (.|\\s)*?)\\s*(\\Z|" + scenario + ").*", DOTALL); } private Pattern patternToPullGivenScenariosIntoGroupOne() { - KeyWords keywords = configuration.keywords(); String givenScenarios = keywords.givenScenarios(); String concatenatedKeywords = concatenateWithOr(keywords.given(), keywords.when(), keywords.then(), keywords.others()); @@ -177,13 +183,11 @@ } private Pattern patternToPullScenarioTableIntoGroupOne() { - KeyWords keywords = configuration.keywords(); String table = keywords.examplesTable(); return compile(".*"+table+"\\s*((.|\\s)*)"); } private Pattern patternToPullScenarioTitleIntoGroupOne() { - KeyWords keywords = configuration.keywords(); String scenario = keywords.scenario(); String concatenatedKeywords = concatenateWithOr(keywords.given(), keywords.when(), keywords.then(), keywords.others()); @@ -229,7 +233,6 @@ } private Pattern patternToPullOutSteps() { - KeyWords keywords = configuration.keywords(); String givenWhenThen = concatenateWithOr(keywords.given(), keywords .when(), keywords.then(), keywords.others()); String givenWhenThenSpaced = concatenateWithSpaceOr(keywords.given(),
To unsubscribe from this list please visit:
