-
-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add datatable/java #291
add datatable/java #291
Conversation
@@ -68,21 +68,16 @@ private String buildCaptureRegexp(List<String> regexps) { | |||
} | |||
|
|||
@Override | |||
public List<Argument<?>> match(String text, final DataTable argument) { | |||
public List<Argument<?>> match(String text, List<List<String>> tableArgument) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the to match(String text, List<List<String>> tableArgument)
so callers don't have to provide their own data table with converter which needs a parameter type registry instance. This simplifies the logistics of using Expressions.
public Expression createExpression(String expressionString, final Type tableType) { | ||
if (tableType == null) throw new CucumberExpressionException("tableType can not be null"); | ||
|
||
return createExpression(expressionString, new Transformer<List<List<String>>, Object>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract the Transformer
and leave its creation to the caller. If we also provide the default table transform we can cut the dependency between datatable and cucumber-expressions.
88a2e1c
to
9efd98f
Compare
I've opted to use composition instead of extension. Javas type system isn't quite powerful enough to create a sufficiently generic parameter type. So there are now two separate type registries and a third one to tie them together. This makes things allot simpler. We now have a concept of a StepExpression in cucumber-jvm which is a CucumberExpression + an optional tableOrDocStringType. |
Map<K, V> map = new LinkedHashMap<>(); | ||
int i = 0; | ||
for (String cell : valueRow) { | ||
map.put(keys.get(i), valueConverter.transform(singletonList(cell))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. We should use the match method first and pass that result list to the value converter.
9efd98f
to
c7e312e
Compare
I've come to the conclusion that adding a default object mapper will run us into the same problems and complexity as we've had with XStream. It binds both cucumber and and its user to a specific mapper and requires that our users follow the conventions and ceremonies of that mapper. This makes it harder to use business objects objects in cucumber. On other other hand by moving the object mapper into the parameter type configuration the end user can decide which mapper to use and use one that works in conjunction with his own business objects. So if the user is using jackson in his domain he can use jackson in cucumber. If the user is using something else, he can use that. This adds a little verbosity but with java 8 it already folds up nicely:
|
90e1801
to
2647dac
Compare
575461e
to
e248260
Compare
To make development a bit easier I've moved the datatable code into the cucumber-expressions branch of cucumber-jvm. In hindsight the datatable to list objects scenario is a bit silly. It has the same type as toLists so it would be impossible to disambiguate. |
I want to have a cross-platform implementation of data tables, just like cucumber-expressions and tag-expressions. Part of that is a shared test suite and synchronised releases. This becomes harder if it’s moved to What became easier by moving it? |
Refactoring and integrating with the existing code. IDEA can't refactor over multiple projects. As I hadn't quite untangled the DataTable from the StepExpression from the StepDefinition yet I ended up in a cycle of refactor-compile-fix-the-other-project. By putting the data tables and step expression into cucumber-jvm the tooling works and it the refactorings happen instantly. Once cucumber expressions is done but before it is merged I reckon we can extract data tables out again. |
a99516a
to
512e328
Compare
@aslakhellesoy I've put the code is back in. The good parts to review are |
3059679
to
c836278
Compare
Adding extra constructors to ParameterType allows users to directly define a transform without wrapping it in a single transformer. Allowing checked exceptions to be thrown while transforming parameters reduces the complexity of the transform. Removed unused parameters from the factory
99b3bf4
to
0399c9c
Compare
2c97277
to
c2accf4
Compare
9384fc2
to
c8d217e
Compare
* Implements Cucumber expressions * Removes XStream * Adds DataTables from cucumber/common#291 * Introduces the concept of StepExpressions which combines a CucumberExpression and DataTable expression. Currently data table expressions are limited to a java type. Currently only the implicit type derived from the method argument is used. For a working example check the calculator examples.
* Implements Cucumber expressions * Removes XStream * Adds DataTables from cucumber/common#291 * Introduces the concept of StepExpressions which combines a CucumberExpression and DataTable expression. Currently data table expressions are limited to a java type. Currently only the implicit type derived from the method argument is used. For a working example check the calculator examples.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
DataTable is a simple data structure that allows the use and transformation of Gherkin data tables in cucumber without directly using the table from Gherkin.
It also features a type registry similar to that of cucumber expressions to assist the transformation of a data table into other types and data structure. I believe that it currently can handle the transformation of a data table to any reasonable combination of lists, lists of lists, lists of maps, maps, maps of lists and maps of maps.
It does not (yet) feature the automagic conversion currently present in Cucumber JVM. This is a feature that may be added at a later date.
For more usage see the
datatable/README.md
anddatatable/java/README.md
This PR is needed to support the implementation of Cucumber Expressions in Cucumber JVM. As such it also includes several fixes for
cucumber-expressions
.