Thanks Mauro,

Here details:
Which story are you trying to run the story?

Scenario: To print tabular data

Given the traders:
|name|rank|
|Larry|Stooge 3|
|Moe|Stooge 1|
|Curly|Stooge 2|

When a wildcard search ".*y" is executed"

Then the traders returned are:
|name|rank|
|Larry|Stooge 3|
|Curly|Stooge 2|

And how are you trying to run it - Maven or Eclipse?   What is your env,
JDK, Eclipse, mvn etc ... ?
Eclipse Helios
env. Java 1.7

Also, given the example code is available to everybody on source control,
there is no need to copy it in the email.
Attached.

On Tue, Oct 16, 2012 at 12:45 PM, Mauro Talevi
<[email protected]>wrote:

>  Hi Gopu,
>
> you need to give us more details for us to help.
>
> Which story are you trying to run the story?  And how are you trying to
> run it - Maven or Eclipse?   What is your env, JDK, Eclipse, mvn etc ... ?
>
> Also, given the example code is available to everybody on source control,
> there is no need to copy it in the email.
>
> Cheers
>
>
> On 16/10/2012 18:59, Gopu Shrestha wrote:
>
> I am trying to run Trader Example to implement ExampleTable for
> Parameterized Tabular Data. I am getting an error of "No runnable methods".
>
> Can anybody help me, please.
>
> my story:
> Scenario: To print tabular data
>
> Given the traders:
>   name rank  Larry Stooge 3  Moe Stooge 1  Curly Stooge 2
>
> When a wildcard search ".*y" is executed"
>
> Then the traders returned are:
>   name rank  Larry Stooge 3  Curly Stooge 2
>
> package com.BaseStory;
>
> import java.util.ArrayList;
> import java.util.Collections;
> import java.util.List;
> import java.util.Map;
>
> import org.jbehave.core.annotations.Given;
> import org.jbehave.core.annotations.Then;
> import org.jbehave.core.annotations.When;
> import org.jbehave.core.model.ExamplesTable;
> import java.util.ArrayList;
> import java.util.Collections;
> import java.util.List;
> import java.util.Map;
> import static org.junit.Assert.*;
> import model.Stock;
> import model.Trader;
> import model.Stock.AlertStatus;
> import service.TradingService;
>
> public class TraderSteps {
>
> private TradingService service;
> private Stock stock;
> private Trader trader;
> private List<Trader> traders = new ArrayList<Trader>();
> private List<Trader> searchedTraders;
>
> @Given("the traders: %tradersTable")
> public void theTraders(ExamplesTable tradersTable) { traders.clear();
> traders.addAll(toTraders(tradersTable)); }
>
> @When("a wildcard search \"%regex\" is executed")
> public void aWildcardSearchIsExecuted(String regex) {
> searchedTraders = new ArrayList<Trader>();
> for (Trader trader : traders) {
> if ( trader.getName().matches(regex) ){ searchedTraders.add(trader); }
> }
> }
>
> @Then("the traders returned are: %tradersTable")
> public void theTradersReturnedAre(ExamplesTable tradersTable) {
> List<Trader> expected = toTraders(tradersTable);
> assertEquals(expected.toString(), searchedTraders.toString()); }
>
> private List<Trader> toTraders(ExamplesTable table) {
> List<Trader> traders = new ArrayList<Trader>();
> List<Map<String, String>> rows = table.getRows();
> for (Map<String, String> row : rows) { String name = row.get("name");
> String rank = row.get("rank"); traders.add(service.newTrader(name, rank)); }
> Collections.sort(traders);
> return traders;
> }
>
> }
>
>
>
package com.BaseStory;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Properties;

import org.jbehave.core.Embeddable;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.i18n.LocalizedKeywords;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.model.ExamplesTableFactory;
import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser;
import org.jbehave.core.parsers.RegexStoryParser;
import org.jbehave.core.reporters.ConsoleOutput;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.CandidateSteps;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.jbehave.core.steps.ParameterConverters;
import org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter;
import org.jbehave.core.steps.ParameterConverters.ParameterConverter;
import org.jbehave.core.steps.ParameterConverters.DateConverter;

import freemarker.core.SimpleCharStream;
import freemarker.template.Configuration;

abstract public class BaseStories extends JUnitStories {

        private final CrossReference xref = new CrossReference();

        public BaseStories() {

                configuredEmbedder().embedderControls()
                                .doGenerateViewAfterStories(true)
                                
.doIgnoreFailureInStories(true).doIgnoreFailureInView(true)
                                .useThreads(2).useStoryTimeoutInSecs(60);
        }

        @Override
        public org.jbehave.core.configuration.Configuration configuration() {
                Class<? extends Embeddable> embeddableClass = this.getClass();
                Properties viewResources = new Properties();
                viewResources.put("decorateNonHtml", "true");
                ParameterConverters parameterConverters = new 
ParameterConverters();

                LocalizedKeywords keywords = new LocalizedKeywords();

                ExamplesTableFactory exampleTableFactory = new 
ExamplesTableFactory(
                                keywords, new 
LoadFromClasspath(embeddableClass),
                                parameterConverters);

                parameterConverters.addConverters(new DateConverter(
                                new SimpleDateFormat("yyyy-MM-dd")),
                                new 
ExamplesTableConverter(exampleTableFactory));

                return new MostUsefulConfiguration()
                                .useStoryLoader(new 
LoadFromClasspath(embeddableClass))
                                .useStoryParser(
                                                new RegexStoryParser(keywords, 
exampleTableFactory))
                                .useDefaultStoryReporter(new 
ConsoleOutput(keywords))
                                .useStoryReporterBuilder(
                                                new StoryReporterBuilder()
                                                                
.withCodeLocation(
                                                                                
CodeLocations
                                                                                
                .codeLocationFromClass(embeddableClass))
                                                                
.withDefaultFormats().withKeywords(keywords)
                                                                
.withViewResources(viewResources)
                                                                
.withFormats(Format.CONSOLE, Format.HTML)
                                                                
.withFailureTrace(true)
                                                                
.withFailureTraceCompression(true)
                                                                
.withCrossReference(xref))
                                .useParameterConverters(parameterConverters)
                                .useStepPatternParser(
                                                new 
RegexPrefixCapturingPatternParser("%"))
                                .useStepMonitor(xref.getStepMonitor());

        }

        @Override
        public InjectableStepsFactory stepsFactory() {
                return new InstanceStepsFactory(configuration(), createSteps());
        }

        abstract protected List<Object> createSteps();

        @Override
        public List<String> storyPaths() {

                return new 
StoryFinder().findPaths(CodeLocations.codeLocationFromPath("/JbehaveParameter/src/"),
 
                                "**/*.story", "**/failing_before*.story");
        }
}
package model;

import java.util.ArrayList;
import java.util.List;

import model.Stock.AlertStatus;

public class Stock {

    public enum AlertStatus {
        ON, OFF
    }

        private static final AlertStatus OFF = null;
        private static final AlertStatus ON = null;;

        private String symbol;
    private double alertPrice;
    private AlertStatus status = OFF;
    private List<Double> prices = new ArrayList<Double>();

    public Stock(String symbol, double alertPrice) {
        this.symbol = symbol;
        this.alertPrice = alertPrice;
    }

    public String getSymbol(){
        return symbol;
    }
    
    public void tradeAt(double price) {
        this.prices.add(price);
        if (price > alertPrice) {
            status = ON;
        }
    }

    public List<Double> getPrices() {
        return prices;
    }

    public void resetAlert() {
        status = OFF;
    }

    public AlertStatus getStatus() {
        return status;
    }

}
package model;

import static java.util.Arrays.asList;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class Trader implements Comparable<Trader>{

    private final String name;
    private String rank = "";
    private List<Stock> stocks = new ArrayList<Stock>();

    public Trader(String name, String rank) {
        this.name = name;
        this.rank = rank;
    }

    public Trader(String name, List<Stock> stocks) {
        this.name = name;
        this.stocks = stocks;
    }

    public String getName() {
        return name;
    }
    
    public String getRank() {
        return rank;
    }

    public List<Stock> getStocks() {
        return stocks;
    }

    public void addStocks(List<Stock> stocks) {
        this.stocks.addAll(stocks);
    }

    public void sellAllStocks(){
        this.stocks = asList(new Stock[]{});
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, 
ToStringStyle.SHORT_PREFIX_STYLE);
    }

    public int compareTo(Trader o) {
        return CompareToBuilder.reflectionCompare(this, o);
    }
    
}
package com.BaseStory;


import java.util.ArrayList;
import java.util.List;

public class TraderExecution extends BaseStories {

        @Override
        protected List<Object> createSteps() {
                List<Object> steps = new ArrayList<Object>();
                steps.add(new TraderSteps());
                return steps;
        }

        @Override
        public void run() throws Throwable {
                
                super.run();
        }
}
package com.BaseStory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.model.ExamplesTable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
import model.Stock;
import model.Trader;
import model.Stock.AlertStatus;
import service.TradingService;

public class TraderSteps {

    private TradingService service;    
    private Stock stock;
    private Trader trader;
    private List<Trader> traders = new ArrayList<Trader>();
    private List<Trader> searchedTraders;
        
    @Given("the traders: $tradersTable")
    public void theTraders(ExamplesTable tradersTable) {
        traders.clear();
        traders.addAll(toTraders(tradersTable));
    }

    @When("a wildcard search \"%regex\" is executed")
    public void aWildcardSearchIsExecuted(String regex) {
        searchedTraders = new ArrayList<Trader>();
        for (Trader trader : traders) {
            if ( trader.getName().matches(regex) ){
                searchedTraders.add(trader);
            }
        }
    }
    
    @Then("the traders returned are: $tradersTable")
    public void theTradersReturnedAre(ExamplesTable tradersTable) {
        List<Trader> expected = toTraders(tradersTable);
        assertEquals(expected.toString(), searchedTraders.toString());
    }

    private List<Trader> toTraders(ExamplesTable table) {
        List<Trader> traders = new ArrayList<Trader>();
        List<Map<String, String>> rows = table.getRows();
        for (Map<String, String> row : rows) {
            String name = row.get("name");
            String rank = row.get("rank");
            traders.add(service.newTrader(name, rank));
        }
        Collections.sort(traders);
        return traders;
    }
    
}
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to