Title: [1247] trunk/core/examples: Added i18n trader scenario.

Diff

Modified: trunk/core/examples/pom.xml (1246 => 1247)

--- trunk/core/examples/pom.xml	2009-09-13 13:39:53 UTC (rev 1246)
+++ trunk/core/examples/pom.xml	2009-09-14 15:15:24 UTC (rev 1247)
@@ -58,7 +58,7 @@
             <phase>integration-test</phase>
             <configuration>
               <scenarioIncludes>
-                <scenarioInclude>**/scenario/*.java</scenarioInclude>
+                <scenarioInclude>${scenario.includes}</scenarioInclude>
               </scenarioIncludes>
               <scenarioExcludes>
                 <scenarioExclude>**/*Steps.java</scenarioExclude>
@@ -72,4 +72,7 @@
       </plugin>
     </plugins>
   </build>
+  <properties>
+    <scenario.includes>**/scenario/*.java</scenario.includes>
+  </properties>
 </project>

Modified: trunk/core/examples/trader/pom.xml (1246 => 1247)

--- trunk/core/examples/trader/pom.xml	2009-09-13 13:39:53 UTC (rev 1246)
+++ trunk/core/examples/trader/pom.xml	2009-09-14 15:15:24 UTC (rev 1247)
@@ -31,7 +31,7 @@
             <phase>integration-test</phase>
             <configuration>
               <scenarioIncludes>
-                <scenarioInclude>org/jbehave/examples/trader/scenarios/*.java</scenarioInclude>
+                <scenarioInclude>**/scenarios/I18n*.java</scenarioInclude>
               </scenarioIncludes>
               <scenarioExcludes>
                 <scenarioExclude>**/*Steps.java</scenarioExclude>

Added: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/ItTraderScenario.java (0 => 1247)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/ItTraderScenario.java	                        (rev 0)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/ItTraderScenario.java	2009-09-14 15:15:24 UTC (rev 1247)
@@ -0,0 +1,47 @@
+package org.jbehave.examples.trader;
+
+import java.util.Locale;
+
+import org.jbehave.scenario.JUnitScenario;
+import org.jbehave.scenario.PropertyBasedConfiguration;
+import org.jbehave.scenario.definition.KeyWords;
+import org.jbehave.scenario.i18n.I18nKeyWords;
+import org.jbehave.scenario.parser.ClasspathScenarioDefiner;
+import org.jbehave.scenario.parser.PatternScenarioParser;
+import org.jbehave.scenario.parser.ScenarioDefiner;
+import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver;
+import org.jbehave.scenario.reporters.PrintStreamScenarioReporter;
+import org.jbehave.scenario.reporters.ScenarioReporter;
+
+public class ItTraderScenario extends JUnitScenario {
+
+	public ItTraderScenario() {
+		this(Thread.currentThread().getContextClassLoader());
+	}
+
+	public ItTraderScenario(final ClassLoader classLoader) {
+		super(new PropertyBasedConfiguration() {
+			@Override
+			public ScenarioDefiner forDefiningScenarios() {
+				// use underscored camel case scenario files with extension ".scenario"
+				return new ClasspathScenarioDefiner(
+						new UnderscoredCamelCaseResolver(".scenario"),
+						new PatternScenarioParser(this), classLoader);
+			}
+
+			@Override
+			public ScenarioReporter forReportingScenarios() {
+				// report outcome in Italian (to System.out)
+				return new PrintStreamScenarioReporter(new I18nKeyWords(new Locale("it")));
+			}
+
+			@Override
+			public KeyWords keywords() {
+				// use Italian for keywords
+				return new I18nKeyWords(new Locale("it"));
+			}
+
+		}, new ItTraderSteps(classLoader));
+	}
+
+}

Added: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/ItTraderSteps.java (0 => 1247)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/ItTraderSteps.java	                        (rev 0)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/ItTraderSteps.java	2009-09-14 15:15:24 UTC (rev 1247)
@@ -0,0 +1,41 @@
+package org.jbehave.examples.trader;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.jbehave.Ensure.ensureThat;
+
+import java.util.Locale;
+
+import org.jbehave.examples.trader.model.Stock;
+import org.jbehave.scenario.annotations.Given;
+import org.jbehave.scenario.annotations.Named;
+import org.jbehave.scenario.annotations.Then;
+import org.jbehave.scenario.annotations.When;
+import org.jbehave.scenario.i18n.I18nKeyWords;
+import org.jbehave.scenario.steps.Steps;
+import org.jbehave.scenario.steps.StepsConfiguration;
+
+public class ItTraderSteps extends Steps {
+
+    private Stock stock;
+
+    public ItTraderSteps(ClassLoader classLoader) {
+    	// Use Italian for keywords
+        super(new StepsConfiguration(new I18nKeyWords(new Locale("it"))));
+    }
+
+    @Given("ho un'azione con simbolo $symbol e una soglia di $threshold")
+    public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
+        stock = new Stock(symbol, threshold);
+    }
+
+    @When("l'azione e' scambiata al prezzo di $price")
+    public void stockIsTraded(@Named("price") double price) {
+        stock.tradeAt(price);
+    }
+
+    @Then("lo status di allerta e' $status")
+    public void alertStatusIs(@Named("status") String status) {
+        ensureThat(stock.getStatus().name(), equalTo(status));
+    }
+
+}

Added: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/ItTraderIsAlertedOfStatus.java (0 => 1247)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/ItTraderIsAlertedOfStatus.java	                        (rev 0)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/ItTraderIsAlertedOfStatus.java	2009-09-14 15:15:24 UTC (rev 1247)
@@ -0,0 +1,16 @@
+package org.jbehave.examples.trader.scenarios;
+
+import org.jbehave.examples.trader.ItTraderScenario;
+
+
+public class ItTraderIsAlertedOfStatus extends ItTraderScenario {
+
+    public ItTraderIsAlertedOfStatus() {
+        this(Thread.currentThread().getContextClassLoader());
+    }
+
+    public ItTraderIsAlertedOfStatus(final ClassLoader classLoader) {
+    	super(classLoader);
+    }
+
+}

Added: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/it_trader_is_alerted_of_status.scenario (0 => 1247)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/it_trader_is_alerted_of_status.scenario	                        (rev 0)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/it_trader_is_alerted_of_status.scenario	2009-09-14 15:15:24 UTC (rev 1247)
@@ -0,0 +1,14 @@
+Scenario: 
+Per assicurare una risposta rapida
+In qualita' di trader che parla italiano
+Voglio controllare i prezzi delle azioni
+
+Dato che ho un'azione con simbolo STK1 e una soglia di 15.0
+Quando l'azione e' scambiata al prezzo di 5.0
+Allora lo status di allerta e' OFF
+Quando l'azione e' scambiata al prezzo di 11.0
+Allora lo status di allerta e' OFF
+Quando l'azione e' scambiata al prezzo di 16.0
+Allora lo status di allerta e' ON
+Quando l'azione e' scambiata al prezzzzzzzzo di 20.0
+Allora lo status di allerta e' ON
\ No newline at end of file

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java (1246 => 1247)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2009-09-13 13:39:53 UTC (rev 1246)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2009-09-14 15:15:24 UTC (rev 1247)
@@ -16,10 +16,10 @@
  * Scenario reporter that outputs to a PrintStream, defaulting to System.out.
  * </p>
  * <p>
- * The output of each reported event is (optionally) configurable via two means:
+ * The output of the reported event is also configurable via two other means:
  * <ul>
- * <li>custom output patterns</li>
- * <li>keywords in different languages</li>
+ * <li>custom output patterns, providing only the patterns that differ from default</li>
+ * <li>keywords in different languages, providing the i18n locale</li>
  * </ul>
  * </p>
  * <p>
@@ -34,8 +34,9 @@
  * </pre>
  * 
  * The pattern is by default processed and formatted by the
- * {...@link MessageFormat}.  Both the {...@link #format()} and {...@link #lookupPattern()} methods are overrideable
- * and a different formatter or pattern lookup can be used by subclasses.
+ * {...@link MessageFormat}. Both the {...@link #format()} and
+ * {...@link #lookupPattern()} methods are overrideable and a different formatter
+ * or pattern lookup can be used by subclasses.
  * </p>
  * <p>
  * If the keyword "FAILED" (or any other keyword used by the reporter) needs to
@@ -43,7 +44,7 @@
  * instance of {...@link I18nKeyWords} using the appropriate {...@link Locale}, e.g.
  * 
  * <pre>
- *   KeyWords keywords = new I18nKeyWords(new Locale(&quot;it&quot;);
+ * KeyWords keywords = new I18nKeyWords(new Locale(&quot;it&quot;);
  * </pre>
  * 
  * </p>
@@ -64,6 +65,14 @@
 		this(output, new Properties(), new I18nKeyWords(), false);
 	}
 
+	public PrintStreamScenarioReporter(Properties outputPatterns) {
+		this(System.out, outputPatterns, new I18nKeyWords(), false);
+	}
+
+	public PrintStreamScenarioReporter(KeyWords keywords) {
+		this(System.out, new Properties(), keywords, false);
+	}
+
 	public PrintStreamScenarioReporter(PrintStream output,
 			Properties outputPatterns, KeyWords keywords, boolean reportErrors) {
 		this.output = output;


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to