Details
Description
The idea is to map the ExamplesTable rows to match a business object.
So, instead of having a method like this:
@Given("some $table")
public void givenAnExamplesTable(ExamplesTable table)
We'd have something like this:
@Given("some $table")
public void givenACustomBusinessObject(MyCustomObject myObject){ ... }
Or a List of business objects:
@Given("some $table")
public void givenACustomBusinessObject(List<MyCustomObject> myObjectList)
This can be done in two ways:
- Annotation-based mapping:
@AsParameters
public class MyCustomObject
- Named-based mapping, using the name of the field as the parameter name.
Activity
Mauro Talevi
made changes -
Field | Original Value | New Value |
---|---|---|
Summary | Parse ExamplesTable directly into Pojos | Allow mapping of ExamplesTable rows to annotated custom types |
Assignee | Mauro Talevi [ maurotalevi ] | |
Affects Version/s | 3.9 [ 19035 ] | |
Description |
I did it once in a team using JBehave.
The idea is to avoid manually parsing ExamplesTable using rows *Map<String, String>* to match our own business data. Instead of having a glue method like this: @Given("some $table") public void givenAnExamplesTable(ExamplesTable theScenarioTable){ ... } We'ld have something like this: @Given("some $table") public void givenACustomBusinessObject(MyCustomObject myObject){ ... } I'm going to work on this, so here's the question. Does something like this already exists? Otherwise, may I work directly in the core module, or i should start an external one to achieve such a thing? I may have to modify ExamplesTableFactory, as stated in JBEHAVE-417 This can be done in several way... Two of my favorites (i'm using fake classes/annotations for the example): * Annotations: @ExamplesTable public class MyCustomObject{ @ExamplesColumn(mappingName="column1") private String col1; @ExamplesColumn(mappingName="column2") private Boolean col2; } * Manual mapping PojoParameterConverter converter = new PojoParameterConverter<MyCustomObject>(MyCustomObject.class); converter.addMapping("column1", "col1"); converter.addMapping("column2", "col2"); |
The idea is to map the ExamplesTable rows to match a business object.
So, instead of having a method like this: @Given("some $table") public void givenAnExamplesTable(ExamplesTable table){ ... } We'd have something like this: @Given("some $table") public void givenACustomBusinessObject(MyCustomObject myObject){ ... } Or a List of business objects: @Given("some $table") public void givenACustomBusinessObject(List<MyCustomObject> myObjectList){ ... } This can be done in two ways: * Annotation-based mapping: @AsParameters public class MyCustomObject{ @Parameter(name="column1") private String col1; @Parameter(name="column2") private Boolean col2; } * Named-based mapping, using the name of the field as the parameter name. |
Mauro Talevi
made changes -
Status | Open [ 1 ] | Resolved [ 5 ] |
Resolution | Fixed [ 1 ] |
Interesting! Do you have a POC or spike of this somewhere showing it in action?