Title: [1572] trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n: JBEHAVE-230: Added parseable keyword-specified narrative to story definition.

Diff

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties (1571 => 1572)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties	2010-02-20 12:15:52 UTC (rev 1572)
@@ -1,3 +1,7 @@
+Narrative=Narrativa:
+InOrderTo=Per ottenere
+AsA=Come
+IWantTo=Voglio
 Scenario=Scenario:
 GivenScenarios=Dati gli scenari:
 ExamplesTable=Esempi:

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/definition/KeywordsBehaviour.java (1571 => 1572)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/definition/KeywordsBehaviour.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/definition/KeywordsBehaviour.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -14,6 +14,7 @@
     @Test
     public void shouldHaveAllKeywordsSetByDefault() throws IOException {
         KeyWords keywords = new KeyWords();
+        assertEquals("Narrative:", keywords.narrative());
         assertEquals("Scenario:", keywords.scenario());
         assertEquals("GivenScenarios:", keywords.givenScenarios());
         assertEquals("Examples:", keywords.examplesTable());
@@ -35,7 +36,7 @@
 
     @Test(expected=InsufficientKeywordsException.class)
     public void shouldFailIfSomeKeywordIsMissingInVarargConstructor() throws IOException {
-        new KeyWords("scenario", "givenScenario", "examples", "given", "when", "then", "and", "!--");
+        new KeyWords("scenario", "givenScenario", "examples", "given", "when", "then", "and", "!--", "narrative");
     }
 
 }

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java (1571 => 1572)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -3,12 +3,16 @@
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.jbehave.Ensure.ensureThat;
 import static org.jbehave.scenario.definition.KeyWords.AND;
+import static org.jbehave.scenario.definition.KeyWords.AS_A;
 import static org.jbehave.scenario.definition.KeyWords.EXAMPLES_TABLE;
 import static org.jbehave.scenario.definition.KeyWords.EXAMPLES_TABLE_ROW;
 import static org.jbehave.scenario.definition.KeyWords.FAILED;
 import static org.jbehave.scenario.definition.KeyWords.GIVEN;
 import static org.jbehave.scenario.definition.KeyWords.GIVEN_SCENARIOS;
 import static org.jbehave.scenario.definition.KeyWords.IGNORABLE;
+import static org.jbehave.scenario.definition.KeyWords.IN_ORDER_TO;
+import static org.jbehave.scenario.definition.KeyWords.I_WANT_TO;
+import static org.jbehave.scenario.definition.KeyWords.NARRATIVE;
 import static org.jbehave.scenario.definition.KeyWords.NOT_PERFORMED;
 import static org.jbehave.scenario.definition.KeyWords.PENDING;
 import static org.jbehave.scenario.definition.KeyWords.SCENARIO;
@@ -74,6 +78,10 @@
     private void ensureKeywordsAreLocalisedFor(Locale locale, String bundleName) throws IOException {
         KeyWords keywords = keyWordsFor(locale, bundleName);
         Properties properties = bundleFor(locale);
+        ensureKeywordIs(properties, NARRATIVE, keywords.narrative());
+        ensureKeywordIs(properties, IN_ORDER_TO, keywords.inOrderTo());
+        ensureKeywordIs(properties, AS_A, keywords.asA());
+        ensureKeywordIs(properties, I_WANT_TO, keywords.iWantTo());
         ensureKeywordIs(properties, SCENARIO, keywords.scenario());
         ensureKeywordIs(properties, GIVEN_SCENARIOS, keywords.givenScenarios());
         ensureKeywordIs(properties, EXAMPLES_TABLE, keywords.examplesTable());

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/keywords_it.properties (1571 => 1572)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/keywords_it.properties	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/keywords_it.properties	2010-02-20 12:15:52 UTC (rev 1572)
@@ -1,3 +1,7 @@
+Narrative=Narrativa:
+InOrderTo=Per ottenere
+AsA=Come
+IWantTo=Voglio
 Scenario=Scenario:
 GivenScenarios=Dati gli scenari:
 ExamplesTable=Esempi:

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java (1571 => 1572)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/parser/PatternScenarioParserBehaviour.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -9,6 +9,7 @@
 import java.util.List;
 
 import org.jbehave.scenario.definition.ExamplesTable;
+import org.jbehave.scenario.definition.Narrative;
 import org.jbehave.scenario.definition.ScenarioDefinition;
 import org.jbehave.scenario.definition.StoryDefinition;
 import org.jbehave.scenario.i18n.I18nKeyWords;
@@ -102,17 +103,33 @@
         ensureThat(story.getScenarios().get(0).getSteps(), equalTo(asList("Given my scenario")));
         ensureThat(story.getScenarios().get(1).getTitle(), equalTo("the second scenario"));
         ensureThat(story.getScenarios().get(1).getSteps(), equalTo(asList("Given my second scenario")));
+    }   
+    
+    @Test
+    public void shouldParseNarrativeFromStory() {
+        StoryDefinition story = parser.defineStoryFrom(
+                "Narrative: This bit of text is ignored" + NL + 
+                "In order to renovate my house" + NL + 
+                "As a customer" + NL + 
+                "I want to get a loan" + NL + 
+                "Scenario:  A first scenario", null);
+        Narrative narrative = story.getNarrative();
+        ensureThat(narrative, not(equalTo(Narrative.EMPTY)));
+        ensureThat(narrative.inOrderTo().toString(), equalTo("renovate my house"));
+        ensureThat(narrative.asA().toString(), equalTo("customer"));
+        ensureThat(narrative.iWantTo().toString(), equalTo("get a loan"));
     }
     
     @Test
     public void shouldParseFullStory() {
         String wholeStory = 
             "Story: I can output narratives" + NL + NL +
-            
+
+            "Narrative: " + NL +
+            "In order to see what we're not delivering" + NL + NL +
             "As a developer" + NL +
             "I want to see the narrative for my story when a scenario in that story breaks" + NL +
-            "So that I can see what we're not delivering" + NL + NL +
-            
+
             "Scenario: A pending scenario" + NL +  NL +
             "Given a step that's pending" + NL +
             "When I run the scenario" + NL +
@@ -132,11 +149,12 @@
         
         StoryDefinition story = parser.defineStoryFrom(wholeStory, null);
         
-        ensureThat(story.getBlurb().asString(), equalTo("Story: I can output narratives" + NL + NL +
-                    "As a developer" + NL +
-                    "I want to see the narrative for my story when a scenario in that story breaks" + NL +
-                    "So that I can see what we're not delivering"));
+        ensureThat(story.getBlurb().asString(), equalTo("Story: I can output narratives"));
         
+        ensureThat(story.getNarrative().inOrderTo(), equalTo("see what we're not delivering"));
+        ensureThat(story.getNarrative().asA(), equalTo("developer"));
+        ensureThat(story.getNarrative().iWantTo(), equalTo("see the narrative for my story when a scenario in that story breaks"));
+        
         ensureThat(story.getScenarios().get(0).getTitle(), equalTo("A pending scenario"));
 		ensureThat(story.getScenarios().get(0).getGivenScenarios().size(), equalTo(0));
         ensureThat(story.getScenarios().get(0).getSteps(), equalTo(asList(
@@ -224,31 +242,31 @@
 	            "|a|b|c|" + NL +
 	            "|d|e|f|";
 		
-	        StoryDefinition story = parser.defineStoryFrom(wholeStory, null);
-	        
-	        ScenarioDefinition scenario = story.getScenarios().get(0);
-			ensureThat(scenario.getTitle(), equalTo("A template scenario with table values"));	        
-			ensureThat(scenario.getGivenScenarios().size(), equalTo(0));
-			ensureThat(scenario.getSteps(), equalTo(asList(
-	                "Given a step with a <one>",
-	                "When I run the scenario of name <two>",
-	                "Then I should see <three> in the output"
-	        )));
-	        ExamplesTable table = scenario.getTable();
-			ensureThat(table.toString(), equalTo(
-	        		"|one|two|three|" + NL +
-		            "|a|b|c|" + NL +
-		            "|d|e|f|"));	        
-	        ensureThat(table.getRowCount(), equalTo(2));
-	        ensureThat(table.getRow(0), not(nullValue()));
-	        ensureThat(table.getRow(0).get("one"), equalTo("a"));
-	        ensureThat(table.getRow(0).get("two"), equalTo("b"));
-	        ensureThat(table.getRow(0).get("three"), equalTo("c"));
-	        ensureThat(table.getRow(1), not(nullValue()));
-	        ensureThat(table.getRow(1).get("one"), equalTo("d"));
-	        ensureThat(table.getRow(1).get("two"), equalTo("e"));
-	        ensureThat(table.getRow(1).get("three"), equalTo("f"));
-	    }
+        StoryDefinition story = parser.defineStoryFrom(wholeStory, null);
+        
+        ScenarioDefinition scenario = story.getScenarios().get(0);
+        ensureThat(scenario.getTitle(), equalTo("A template scenario with table values"));          
+        ensureThat(scenario.getGivenScenarios().size(), equalTo(0));
+        ensureThat(scenario.getSteps(), equalTo(asList(
+                "Given a step with a <one>",
+                "When I run the scenario of name <two>",
+                "Then I should see <three> in the output"
+        )));
+        ExamplesTable table = scenario.getTable();
+        ensureThat(table.toString(), equalTo(
+                "|one|two|three|" + NL +
+                "|a|b|c|" + NL +
+                "|d|e|f|"));            
+        ensureThat(table.getRowCount(), equalTo(2));
+        ensureThat(table.getRow(0), not(nullValue()));
+        ensureThat(table.getRow(0).get("one"), equalTo("a"));
+        ensureThat(table.getRow(0).get("two"), equalTo("b"));
+        ensureThat(table.getRow(0).get("three"), equalTo("c"));
+        ensureThat(table.getRow(1), not(nullValue()));
+        ensureThat(table.getRow(1).get("one"), equalTo("d"));
+        ensureThat(table.getRow(1).get("two"), equalTo("e"));
+        ensureThat(table.getRow(1).get("three"), equalTo("f"));
+	}
 	
 	@Test
 	public void shouldParseStoryWithGivenScenarios() {
@@ -259,19 +277,19 @@
 	            "When I run the scenario of name <two>" + NL +
 	            "Then I should see <three> in the output";
 		
-	        StoryDefinition story = parser.defineStoryFrom(wholeStory, null);
-	        
-	        ScenarioDefinition scenario = story.getScenarios().get(0);
-			ensureThat(scenario.getTitle(), equalTo("A scenario with given scenarios"));	        
-			ensureThat(scenario.getGivenScenarios(), equalTo(asList(
-	                "path/to/one",
-	                "path/to/two")));   
-	        ensureThat(scenario.getSteps(), equalTo(asList(
-	                "Given a step with a <one>",
-	                "When I run the scenario of name <two>",
-	                "Then I should see <three> in the output"
-	        )));
+        StoryDefinition story = parser.defineStoryFrom(wholeStory, null);
+        
+        ScenarioDefinition scenario = story.getScenarios().get(0);
+        ensureThat(scenario.getTitle(), equalTo("A scenario with given scenarios"));            
+        ensureThat(scenario.getGivenScenarios(), equalTo(asList(
+                "path/to/one",
+                "path/to/two")));   
+        ensureThat(scenario.getSteps(), equalTo(asList(
+                "Given a step with a <one>",
+                "When I run the scenario of name <two>",
+                "Then I should see <three> in the output"
+        )));
 
-	    }
+	}
 	    
 }

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java (1571 => 1572)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -22,6 +22,7 @@
 import org.jbehave.scenario.Scenario;
 import org.jbehave.scenario.definition.Blurb;
 import org.jbehave.scenario.definition.ExamplesTable;
+import org.jbehave.scenario.definition.Narrative;
 import org.jbehave.scenario.definition.ScenarioDefinition;
 import org.jbehave.scenario.definition.StoryDefinition;
 import org.jbehave.scenario.i18n.I18nKeyWords;
@@ -192,7 +193,7 @@
 
     private void narrateAnInterestingStory(ScenarioReporter reporter) {
         StoryDefinition story = new StoryDefinition(new Blurb("An interesting story"),
-                "/path/to/story", new ArrayList<ScenarioDefinition>());
+                new Narrative("renovate my house", "customer", "get a loan"), "/path/to/story", new ArrayList<ScenarioDefinition>());
         boolean embeddedStory = true;
         reporter.beforeStory(story, embeddedStory);
         String title = "I ask for a loan";

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java (1571 => 1572)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -16,6 +16,10 @@
  */
 public class KeyWords {
 
+    public static final String NARRATIVE = "Narrative";
+    public static final String IN_ORDER_TO = "InOrderTo";
+    public static final String AS_A = "AsA";
+    public static final String I_WANT_TO = "IWantTo";
     public static final String SCENARIO = "Scenario";
     public static final String GIVEN_SCENARIOS = "GivenScenarios";
     public static final String EXAMPLES_TABLE = "ExamplesTable";
@@ -28,9 +32,14 @@
     public static final String NOT_PERFORMED = "NotPerformed";
     public static final String FAILED = "Failed";
     public static final String EXAMPLES_TABLE_ROW = "ExamplesTableRow";
-    public static final List<String> KEYWORDS = asList(SCENARIO, GIVEN_SCENARIOS, EXAMPLES_TABLE, GIVEN, WHEN, THEN,
-            AND, IGNORABLE, PENDING, NOT_PERFORMED, FAILED, EXAMPLES_TABLE_ROW);
+    public static final List<String> KEYWORDS = asList(NARRATIVE, IN_ORDER_TO, AS_A, I_WANT_TO, SCENARIO,
+            GIVEN_SCENARIOS, EXAMPLES_TABLE, GIVEN, WHEN, THEN, AND, IGNORABLE, PENDING, NOT_PERFORMED, FAILED,
+            EXAMPLES_TABLE_ROW);
 
+    private final String narrative;
+    private final String inOrderTo;
+    private final String asA;
+    private final String iWantTo;
     private final String scenario;
     private final String givenScenarios;
     private final String examplesTable;
@@ -48,6 +57,10 @@
 
     public static Map<String, String> defaultKeywords() {
         Map<String, String> keywords = new HashMap<String, String>();
+        keywords.put(NARRATIVE, "Narrative:");
+        keywords.put(IN_ORDER_TO, "In order to:");
+        keywords.put(AS_A, "As a:");
+        keywords.put(I_WANT_TO, "I want to:");
         keywords.put(SCENARIO, "Scenario:");
         keywords.put(GIVEN_SCENARIOS, "GivenScenarios:");
         keywords.put(EXAMPLES_TABLE, "Examples:");
@@ -80,12 +93,16 @@
     }
 
     /**
-     * Creates a KeyWords from the map provided.  
+     * Creates a KeyWords from the map provided.
      * 
      * @param keywords the Map of keywords indexed by their name
      * @param encoder the StringEncoder used to encode the values
      */
     public KeyWords(Map<String, String> keywords, StringEncoder encoder) {
+        this.narrative = keyword(NARRATIVE, keywords);
+        this.inOrderTo = keyword(IN_ORDER_TO, keywords);
+        this.asA = keyword(AS_A, keywords);
+        this.iWantTo = keyword(I_WANT_TO, keywords);
         this.scenario = keyword(SCENARIO, keywords);
         this.givenScenarios = keyword(GIVEN_SCENARIOS, keywords);
         this.examplesTable = keyword(EXAMPLES_TABLE, keywords);
@@ -112,8 +129,9 @@
 
     /**
      * Legacy constructor for KeyWords that provids explicitly the keywords
-     * values. The {...@link others} vararg must include 6 additional keywords
-     * (and, ignorable, pending, notPerformed, failed, examplesTableRow).
+     * values. The {...@link others} vararg must include 10 additional keywords
+     * (and, ignorable, pending, notPerformed, failed, examplesTableRow,
+     * narrative, inOrderTo, asA, iWantTo).
      * 
      * @param scenario
      * @param givenScenarios
@@ -122,7 +140,6 @@
      * @param when
      * @param then
      * @param others
-     * 
      * @deprecated Use KeyWords(Map<String,String>, StringEncoder)
      */
     public KeyWords(String scenario, String givenScenarios, String examplesTable, String given, String when,
@@ -133,7 +150,7 @@
         this.given = given;
         this.when = when;
         this.then = then;
-        if (others.length < 6) {
+        if (others.length < 7) {
             throw new InsufficientKeywordsException(others);
         }
         this.and = others[0];
@@ -142,9 +159,29 @@
         this.notPerformed = others[3];
         this.failed = others[4];
         this.examplesTableRow = others[5];
+        this.narrative = others[6];
+        this.inOrderTo = others[7];
+        this.asA = others[8];
+        this.iWantTo = others[9];
         this.others = others;
     }
 
+    public String narrative() {
+        return narrative;
+    }
+
+    public String inOrderTo() {
+        return inOrderTo;
+    }
+
+    public String asA() {
+        return asA;
+    }
+
+    public String iWantTo() {
+        return iWantTo;
+    }
+
     public String scenario() {
         return scenario;
     }
@@ -217,9 +254,8 @@
     public static final class InsufficientKeywordsException extends RuntimeException {
 
         public InsufficientKeywordsException(String... others) {
-            super("Insufficient keywords: " + asList(others) + ", but requires another " + (6 - others.length));
+            super("Insufficient keywords: " + asList(others) + ", but requires another " + (10 - others.length));
         }
 
     }
-
 }

Added: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/Narrative.java (0 => 1572)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/Narrative.java	                        (rev 0)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/Narrative.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -0,0 +1,37 @@
+package org.jbehave.scenario.definition;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+public class Narrative {
+
+    public static final Narrative EMPTY = new Narrative("", "", "");
+
+    private final String inOrderTo;
+    private final String asA;
+    private final String iWantTo;
+
+    public Narrative(String inOrderTo, String asA, String iWantTo) {
+        this.inOrderTo = inOrderTo;
+        this.asA = asA;
+        this.iWantTo = iWantTo;
+    }
+
+    public String inOrderTo() {
+        return inOrderTo;
+    }
+
+    public String asA() {
+        return asA;
+    }
+
+    public String iWantTo() {
+        return iWantTo;
+    }
+    
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+    }
+
+}

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/StoryDefinition.java (1571 => 1572)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/StoryDefinition.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/StoryDefinition.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -8,6 +8,7 @@
 public class StoryDefinition {
 
     private final Blurb blurb;
+    private final Narrative narrative;
     private final List<ScenarioDefinition> scenarioDefinitions;
     private String name = "Story";
     private String path = "";
@@ -17,19 +18,20 @@
     }
 
     public StoryDefinition(List<ScenarioDefinition> scenarioDefinitions) {
-        this(Blurb.EMPTY, scenarioDefinitions);
+        this(Blurb.EMPTY, Narrative.EMPTY, scenarioDefinitions);
     }
 
     public StoryDefinition(Blurb blurb, ScenarioDefinition... scenarioDefinitions) {
-        this(blurb, asList(scenarioDefinitions));
+        this(blurb, Narrative.EMPTY, asList(scenarioDefinitions));
     }
 
-    public StoryDefinition(Blurb blurb, List<ScenarioDefinition> scenarioDefinitions) {
-        this(blurb, "", scenarioDefinitions);
+    public StoryDefinition(Blurb blurb, Narrative narrative, List<ScenarioDefinition> scenarioDefinitions) {
+        this(blurb, narrative, "", scenarioDefinitions);
     }
 
-    public StoryDefinition(Blurb blurb, String path, List<ScenarioDefinition> scenarioDefinitions) {
+    public StoryDefinition(Blurb blurb, Narrative narrative, String path, List<ScenarioDefinition> scenarioDefinitions) {
         this.blurb = blurb;
+        this.narrative = narrative;
         this.path = path;
         this.scenarioDefinitions = scenarioDefinitions;
     }
@@ -38,6 +40,10 @@
         return blurb;
     }
 
+    public Narrative getNarrative() {
+        return narrative;
+    }
+
     public List<ScenarioDefinition> getScenarios() {
         return unmodifiableList(scenarioDefinitions);
     }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/keywords_en.properties (1571 => 1572)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/keywords_en.properties	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/keywords_en.properties	2010-02-20 12:15:52 UTC (rev 1572)
@@ -1,3 +1,7 @@
+Narrative=Narrative:
+InOrderTo=In order to
+AsA=As a
+IWantTo=I want to
 Scenario=Scenario:
 GivenScenarios=GivenScenarios:
 ExamplesTable=Examples:

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java (1571 => 1572)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java	2010-02-19 10:22:24 UTC (rev 1571)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/parser/PatternScenarioParser.java	2010-02-20 12:15:52 UTC (rev 1572)
@@ -12,6 +12,7 @@
 import org.jbehave.scenario.definition.Blurb;
 import org.jbehave.scenario.definition.ExamplesTable;
 import org.jbehave.scenario.definition.KeyWords;
+import org.jbehave.scenario.definition.Narrative;
 import org.jbehave.scenario.definition.ScenarioDefinition;
 import org.jbehave.scenario.definition.StoryDefinition;
 import org.jbehave.scenario.i18n.I18nKeyWords;
@@ -47,11 +48,44 @@
     
 	public StoryDefinition defineStoryFrom(String wholeStoryAsText, String storyPath) {
 		Blurb blurb = parseBlurbFrom(wholeStoryAsText);
+        Narrative narrative = parseNarrativeFrom(wholeStoryAsText);
 		List<ScenarioDefinition> scenarioDefinitions = parseScenariosFrom(wholeStoryAsText);
-		return new StoryDefinition(blurb, storyPath, scenarioDefinitions);
+        return new StoryDefinition(blurb, narrative, storyPath, scenarioDefinitions);
 	}
 
-	private List<ScenarioDefinition> parseScenariosFrom(
+    private Blurb parseBlurbFrom(String wholeStoryAsString) {
+        String concatenatedKeywords = concatenateWithOr(keywords.narrative(), keywords.scenario());
+        Pattern findBlurb = compile("(.*?)(" + concatenatedKeywords + ").*", DOTALL);
+        Matcher findingBlurb = findBlurb.matcher(wholeStoryAsString);
+        if (findingBlurb.matches()) {
+            return new Blurb(findingBlurb.group(1).trim());
+        }
+        return Blurb.EMPTY;
+    }
+
+    private Narrative parseNarrativeFrom(String wholeStoryAsString) {
+        Pattern findNarrative = compile(".*" + keywords.narrative() + "(.*?)\\s*(" + keywords.scenario() + ").*", DOTALL);
+        Matcher findingNarrative = findNarrative.matcher(wholeStoryAsString);
+        if ( findingNarrative.matches() ){
+            String narrative = findingNarrative.group(1).trim();
+            return createNarrative(narrative);
+        }
+        return Narrative.EMPTY;
+    }
+
+    private Narrative createNarrative(String narrative) {
+        Pattern findElements = compile(".*" + keywords.inOrderTo() + "(.*)\\s*" + keywords.asA() + "(.*)\\s*" + keywords.iWantTo() + "(.*)", DOTALL);
+        Matcher findingElements = findElements.matcher(narrative);
+        if (findingElements.matches()) {
+            String inOrderTo = findingElements.group(1).trim();
+            String asA = findingElements.group(2).trim();
+            String iWantTo = findingElements.group(3).trim();
+            return new Narrative(inOrderTo, asA, iWantTo);
+        }
+        return Narrative.EMPTY;
+    }
+
+    private List<ScenarioDefinition> parseScenariosFrom(
 			String wholeStoryAsString) {
 		List<ScenarioDefinition> scenarioDefinitions = new ArrayList<ScenarioDefinition>();
 		List<String> scenarios = splitScenarios(wholeStoryAsString);
@@ -104,17 +138,6 @@
 		return steps;
 	}
 
-	private Blurb parseBlurbFrom(String wholeStoryAsString) {
-		String scenario = keywords.scenario();
-		Pattern findStoryBlurb = compile("(.*?)(" + scenario + ").*", DOTALL);
-		Matcher matcher = findStoryBlurb.matcher(wholeStoryAsString);
-		if (matcher.find()) {
-			return new Blurb(matcher.group(1).trim());
-		} else {
-			return Blurb.EMPTY;
-		}
-	}
-
 	@SuppressWarnings("serial")
 	public static class InvalidPatternException extends RuntimeException {
 		public InvalidPatternException(String message, Throwable cause) {


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to