- Revision
- 1506
- Author
- mauro
- Date
- 2010-01-09 05:48:51 -0600 (Sat, 09 Jan 2010)
Log Message
JBEHAVE-231: Updated documentation
Modified Paths
Diff
Modified: trunk/core/distribution/src/site/content/candidate-steps.html (1505 => 1506)
--- trunk/core/distribution/src/site/content/candidate-steps.html 2010-01-08 18:36:04 UTC (rev 1505) +++ trunk/core/distribution/src/site/content/candidate-steps.html 2010-01-09 11:48:51 UTC (rev 1506) @@ -14,11 +14,12 @@ href="" Each candidate step corresponds to one Java method and to one <a href="" -A candidate step holds the regex pattern contained in the annotation value, which -is used to do the matching with the textual steps in the scenario.</p> +A candidate step holds the regex pattern contained in the annotation +value, which is used to do the matching with the textual steps in the +scenario.</p> <p>Let's look at a concrete example:</p> <pre class="brush: java"> -public class TraderSteps extends Steps { +public class TraderSteps { // It does not have to extend Steps, but it could private Stock stock; @@ -84,6 +85,28 @@ } </pre> +<p>Note that in the example above <b>TraderSteps</b> is a POJO, i.e. +it does not extend the <a + href="" +class. In this case, we need to use the <a + href="" +to create <a + href="" +to associate to the <b>Scenario</b> class. The factory creates an +instance of <b>Steps</b> which wraps the POJO instance. But, in addition +to the the composition model, JBehave also supports the inheritance +model, in which the steps class would simply extend <b>Steps</b>. The only difference is +in how the steps are registered with the <b>Scenario</b>:</p> +<pre class="brush: java"> +public class TraderScenario extends JUnitScenario { + + public TraderScenario() { + addSteps(new TraderSteps()); // if TraderSteps extends Steps + addSteps(new StepsFactory().createCandidateSteps(new TraderSteps())); // if TraderSteps is a POJO + } +} +</pre> + <div class="clear"> <hr /> </div>
Modified: trunk/core/distribution/src/site/content/developing-scenarios.html (1505 => 1506)
--- trunk/core/distribution/src/site/content/developing-scenarios.html 2010-01-08 18:36:04 UTC (rev 1505) +++ trunk/core/distribution/src/site/content/developing-scenarios.html 2010-01-09 11:48:51 UTC (rev 1506) @@ -8,8 +8,9 @@ <h2>Writing Textual Scenarios</h2> -<p><a href="" Development</a> encourages you to start defining the scenarios that -express the desired behaviour in a textual format, e.g.:</p> +<p><a href="" Development</a> +encourages you to start defining the scenarios that express the desired +behaviour in a textual format, e.g.:</p> <pre class="brush: bdd"> Given a stock of symbol STK1 and a threshold of 10.0 When the stock is traded at 5.0 @@ -27,13 +28,13 @@ <h2>Mapping Textual Scenario Steps to Java Methods via annotations</h2> -<p>JBehave maps textual steps to Java methods via a <a - href="" -instance. The scenario writer need only extend the default -implementation <a - href="" -and provide annotated methods that match, by regex patterns, the textual -steps:</p> +<p>JBehave maps textual steps to Java methods via <a + href="" +The scenario writer need only provide annotated methods that match, by +regex patterns, the textual steps. One way this can be done is by +extending the default implementation <a + href="" +</p> <pre class="brush: java"> public class TraderSteps extends Steps { @@ -56,6 +57,39 @@ } </pre> +<p>Equivalently, as composition is often preferrable to inheritance, +the scenario writer can use a POJO (i.e. without extending Steps)</p> +<pre class="brush: java"> +public class TraderSteps { // look, Ma, I'm a POJO!! + + private Stock stock; + + @Given("a stock of symbol $symbol and a threshold of $threshold") + public void aStock(String symbol, double threshold) { + stock = new Stock(symbol, 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)); + } + +} +</pre> +<p>If POJOs are used we need to create <a + href="" +via the <a + href="" +</p> +<pre class="brush: java"> + StepsConfiguration configuration = ... // optional configuration + new StepsFactory(configuration).createCandidateSteps(new TraderSteps())); +</pre> <p>Each step is annotated with one of the <a href="" annotations</a>, each holding a regex pattern as value. The pattern is used to match the method in the Steps class with the appropriate parameters. @@ -85,26 +119,23 @@ such as <a href="" </p> <p>Must provide a default constructor.</p> -<p>(Only when running via Maven) Must provide an additional +<p>(Only when running with external resources) Must provide an additional constructor with a ClassLoader parameter.</p> <p>Thus in our case the example Scenario would look like:</p> <pre class="brush: java"> -public class TraderIsAletedOfStatus extends JUnitScenario { +public class TraderScenario extends JUnitScenario { - public TraderIsAletedOfStatus() { - this(Thread.currentThread().getContextClassLoader()); - } - - public TraderIsAletedOfStatus(final ClassLoader classLoader) { + public TraderScenario() { super(new MostUsefulConfiguration() { public ScenarioDefiner forDefiningScenarios() { return new ClasspathScenarioDefiner(new UnderscoredCamelCaseResolver(".scenario"), - new PatternScenarioParser(new PropertyBasedConfiguration()), classLoader); + new PatternScenarioParser(keywords())); } - }, new TraderSteps()); + }); + addSteps(new TraderSteps()); // if TraderSteps extends Steps + addSteps(new StepsFactory().createCandidateSteps(new TraderSteps())); // if TraderSteps is a POJO } - } </pre>
Modified: trunk/core/distribution/src/site/content/faq.html (1505 => 1506)
--- trunk/core/distribution/src/site/content/faq.html 2010-01-08 18:36:04 UTC (rev 1505) +++ trunk/core/distribution/src/site/content/faq.html 2010-01-09 11:48:51 UTC (rev 1506) @@ -112,5 +112,19 @@ <p>Alternatively, you can use <a href="" setting system property <b>"org.jbehave.outputall"</b>.</p> + +<h3>Can my steps classes be POJOs?</h3> + +<p>Yes, one can write steps as POJOs and then create an instance of +<a href="" +via the <a href="" +<pre class="brush: java"> + StepsConfiguration configuration = ... // optional configuration + new StepsFactory(configuration).createCandidateSteps(new TraderSteps())); +</pre> + +<p>Alternatively, one can extend the <a + href="" class.</p> + </body> </html> \ No newline at end of file
Modified: trunk/core/distribution/src/site/content/release-notes.html (1505 => 1506)
--- trunk/core/distribution/src/site/content/release-notes.html 2010-01-08 18:36:04 UTC (rev 1505) +++ trunk/core/distribution/src/site/content/release-notes.html 2010-01-09 11:48:51 UTC (rev 1506) @@ -5,6 +5,86 @@ </head> <body> +<h1>JBehave Core - Version 2.3.2 (Nov 3, 2009)</h1> + +<h2> Bug +</h2> +<ul> +<li>[<a href="" - Candidate step does not match AND steps +</li> +</ul> + +<h2> Improvement +</h2> +<ul> +<li>[<a href="" - Allow ScenarioClassLoader to instantiate scenarios using default constructor +</li> +<li>[<a href="" - Allow class loader injection to be optional in scenario classes when running in command line +</li> +</ul> + + +<h1>JBehave Core - Version 2.3.1 (Oct 31, 2009)</h1> + +<h2> Bug +</h2> +<ul> +<li>[<a href="" - I18n keywords resource bundle not found by Ant task +</li> +</ul> + +<h2> Improvement +</h2> +<ul> +<li>[<a href="" - Add support for BigDecimal and BigInteger parameters +</li> +<li>[<a href="" - Candidate steps should be aware of the method annotation type when matching textual steps +</li> +</ul> + +<h2> Task +</h2> +<ul> +<li>[<a href="" - Improve documentation of candidate steps and aliases in reference guide +</li> +</ul> + + +<h1>JBehave Core - Version 2.3 (Oct 10, 2009)</h1> + +<h2> Improvement +</h2> +<ul> +<li>[<a href="" - I18N Keywords +</li> +<li>[<a href="" - Support annotated named parameters in Steps methods +</li> +<li>[<a href="" - Improve documentation +</li> +<li>[<a href="" - Allow output patterns to be overridden and localised in PrintStreamScenarioReporter +</li> +</ul> + +<h2> New Feature +</h2> +<ul> +<li>[<a href="" - GivenScenarios +</li> +<li>[<a href="" - Table examples include +</li> +<li>[<a href="" - Support named parameters in Steps methods via Paranamer +</li> +</ul> + +<h2> Task +</h2> +<ul> +<li>[<a href="" - Provide BNF for BDD grammar +</li> +<li>[<a href="" - Upgrade to JUnit 4.5 +</li> +</ul> + <h1>JBehave Core - Version 2.2.1 (Aug 25, 2009)</h1> <h2> Improvement
To unsubscribe from this list please visit:
