- Revision
- 894
- Author
- mauro
- Date
- 2008-08-26 02:59:25 -0500 (Tue, 26 Aug 2008)
Log Message
Enhanced trader example to use list-based step arguments and the print stream monitor. Made gameoflife scenario runnable by maven build.
Modified Paths
- trunk/examples/gameoflife/pom.xml
- trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/ICanToggleACell.java
- trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/TheGridStartsEmpty.java
- trunk/examples/pom.xml
- trunk/examples/trader/pom.xml
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/model/Stock.java
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario
- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario
Added Paths
- trunk/examples/gameoflife/scenarios/
- trunk/examples/gameoflife/scenarios/pom.xml
Diff
Modified: trunk/examples/gameoflife/pom.xml (893 => 894)
--- trunk/examples/gameoflife/pom.xml 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/gameoflife/pom.xml 2008-08-26 07:59:25 UTC (rev 894) @@ -1,4 +1,5 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.jbehave</groupId> @@ -10,5 +11,9 @@ <dependencies> </dependencies> - + + <build> + <sourceDirectory>src/java</sourceDirectory> + <testSourceDirectory>src/behaviour</testSourceDirectory> + </build> </project> \ No newline at end of file
Property changes: trunk/examples/gameoflife/scenarios
Name: svn:ignore
+ target
Added: trunk/examples/gameoflife/scenarios/pom.xml (0 => 894)
--- trunk/examples/gameoflife/scenarios/pom.xml (rev 0) +++ trunk/examples/gameoflife/scenarios/pom.xml 2008-08-26 07:59:25 UTC (rev 894) @@ -0,0 +1,53 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-examples</artifactId> + <version>2.0-SNAPSHOT</version> + </parent> + <artifactId>jbehave-gameoflife-example-scenarios</artifactId> + <name>JBehave Game of Life Example Scenarios</name> + + <dependencies> + <dependency> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-gameoflife-example</artifactId> + <version>${pom.version}</version> + </dependency> + </dependencies> + + <build> + <sourceDirectory>${basedir}/../src/scenario</sourceDirectory> + <resources> + <resource> + <directory>${basedir}/../src/scenario</directory> + <filtering>false</filtering> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-maven-plugin</artifactId> + <executions> + <execution> + <id>run-scenarios-listed</id> + <phase>integration-test</phase> + <configuration> + <scenarioClassNames> + <scenarioClassName>com.lunivore.gameoflife.ICanToggleACell</scenarioClassName> + <scenarioClassName>com.lunivore.gameoflife.TheGridStartsEmpty</scenarioClassName> + </scenarioClassNames> + </configuration> + <goals> + <goal>run-scenarios</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file
Modified: trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/ICanToggleACell.java (893 => 894)
--- trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/ICanToggleACell.java 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/ICanToggleACell.java 2008-08-26 07:59:25 UTC (rev 894) @@ -1,13 +1,26 @@ package com.lunivore.gameoflife; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; +import org.jbehave.scenario.parser.PatternScenarioParser; +import org.jbehave.scenario.parser.ScenarioFileLoader; +import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver; import com.lunivore.gameoflife.steps.GridSteps; public class ICanToggleACell extends Scenario { - - @SuppressWarnings("unchecked") + public ICanToggleACell() { super(new GridSteps()); } + + public ICanToggleACell(final ClassLoader classLoader) { + super(new PropertyBasedConfiguration() { + @Override + public ScenarioFileLoader forDefiningScenarios() { + return new ScenarioFileLoader(new UnderscoredCamelCaseResolver(), classLoader, + new PatternScenarioParser()); + } + }, new GridSteps()); + } }
Modified: trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/TheGridStartsEmpty.java (893 => 894)
--- trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/TheGridStartsEmpty.java 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/gameoflife/src/scenario/com/lunivore/gameoflife/TheGridStartsEmpty.java 2008-08-26 07:59:25 UTC (rev 894) @@ -1,13 +1,26 @@ package com.lunivore.gameoflife; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; +import org.jbehave.scenario.parser.PatternScenarioParser; +import org.jbehave.scenario.parser.ScenarioFileLoader; +import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver; import com.lunivore.gameoflife.steps.GridSteps; public class TheGridStartsEmpty extends Scenario { - - @SuppressWarnings("unchecked") + public TheGridStartsEmpty() { super(new GridSteps()); } + + public TheGridStartsEmpty(final ClassLoader classLoader) { + super(new PropertyBasedConfiguration() { + @Override + public ScenarioFileLoader forDefiningScenarios() { + return new ScenarioFileLoader(new UnderscoredCamelCaseResolver(), classLoader, + new PatternScenarioParser()); + } + }, new GridSteps()); + } }
Modified: trunk/examples/pom.xml (893 => 894)
--- trunk/examples/pom.xml 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/pom.xml 2008-08-26 07:59:25 UTC (rev 894) @@ -12,6 +12,7 @@ <modules> <module>gameoflife</module> + <module>gameoflife/scenarios</module> <module>trader</module> </modules> @@ -30,5 +31,37 @@ <directory>${basedir}/src/scenario</directory> </resource> </resources> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-maven-plugin</artifactId> + <version>${pom.version}</version> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <groupId>org.jbehave</groupId> + <artifactId>jbehave-maven-plugin</artifactId> + <executions> + <execution> + <id>run-scenarios-found</id> + <phase>integration-test</phase> + <configuration> + <scenarioIncludes> + <scenarioInclude>**/scenario/*.java</scenarioInclude> + </scenarioIncludes> + <scenarioExcludes> + <scenarioExclude>**/*Steps.java</scenarioExclude> + </scenarioExcludes> + </configuration> + <goals> + <goal>run-scenarios</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> </build> </project>
Modified: trunk/examples/trader/pom.xml (893 => 894)
--- trunk/examples/trader/pom.xml 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/trader/pom.xml 2008-08-26 07:59:25 UTC (rev 894) @@ -29,19 +29,6 @@ <version>${pom.version}</version> <executions> <execution> - <id>run-scenarios-listed</id> - <phase>integration-test</phase> - <configuration> - <scenarioClassNames> - <scenarioClassName>org.jbehave.examples.trader.scenarios.StatusAlertCanBeActivated</scenarioClassName> - <scenarioClassName>org.jbehave.examples.trader.scenarios.StatusAlertIsNeverActivated</scenarioClassName> - </scenarioClassNames> - </configuration> - <goals> - <goal>run-scenarios</goal> - </goals> - </execution> - <execution> <id>run-scenarios-found</id> <phase>integration-test</phase> <configuration>
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/model/Stock.java (893 => 894)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/model/Stock.java 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/model/Stock.java 2008-08-26 07:59:25 UTC (rev 894) @@ -3,27 +3,29 @@ import static org.jbehave.examples.trader.model.Stock.AlertStatus.OFF; import static org.jbehave.examples.trader.model.Stock.AlertStatus.ON; +import java.util.List; + public class Stock { public enum AlertStatus { ON, OFF }; - private double price; + private List<Double> prices; private double alertPrice; private AlertStatus status = OFF; - public Stock(double price, double alertPrice) { - this.price = price; + public Stock(List<Double> prices, double alertPrice) { + this.prices = prices; this.alertPrice = alertPrice; } - public double getPrice() { - return price; + public List<Double> getPrices() { + return prices; } public void tradeAt(double price) { - this.price = price; + this.prices.add(price); if (price > alertPrice) { status = ON; }
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java (893 => 894)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/StockSteps.java 2008-08-26 07:59:25 UTC (rev 894) @@ -1,34 +1,38 @@ package org.jbehave.examples.trader.scenarios; - import static org.hamcrest.CoreMatchers.equalTo; import static org.jbehave.Ensure.ensureThat; +import java.util.List; + import org.jbehave.examples.trader.model.Stock; import org.jbehave.scenario.annotations.Given; import org.jbehave.scenario.annotations.Then; import org.jbehave.scenario.annotations.When; +import org.jbehave.scenario.parser.PrefixCapturingPatternBuilder; +import org.jbehave.scenario.steps.PrintStreamStepMonitor; import org.jbehave.scenario.steps.Steps; public class StockSteps extends Steps { - + private double threshold; private Stock stock; - - public StockSteps(double threshold){ + + public StockSteps(double threshold) { + super(new PrefixCapturingPatternBuilder(), new PrintStreamStepMonitor(), "Given", "When", "Then", "And"); this.threshold = threshold; } - - @Given("a stock of price $price") - public void aStockOfPrice(double price) { - stock = new Stock(price, threshold); + + @Given("a stock of prices $prices") + public void aStockOfPrice(List<Double> prices) { + stock = new Stock(prices, threshold); } - + @When("the stock is traded at $price") public void theStockIsTradedAt(double price) { stock.tradeAt(price); } - + @Then("the alert status should be $status") public void theAlertStatusShouldBe(String status) { ensureThat(stock.getStatus().name(), equalTo(status));
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario (893 => 894)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_can_be_activated.scenario 2008-08-26 07:59:25 UTC (rev 894) @@ -1,4 +1,4 @@ -Given a stock of price 1.0 +Given a stock of prices 0.5,1.0 When the stock is traded at 2.0 Then the alert status should be OFF When the stock is traded at 5.0
Modified: trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario (893 => 894)
--- trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario 2008-08-25 17:34:58 UTC (rev 893) +++ trunk/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/status_alert_is_never_activated.scenario 2008-08-26 07:59:25 UTC (rev 894) @@ -1,4 +1,4 @@ -Given a stock of price 1.0 +Given a stock of prices 0.5,1.0 When the stock is traded at 2.0 Then the alert status should be OFF When the stock is traded at 5.0
To unsubscribe from this list please visit:
