Search in sources :

Example 1 with TableCellByTypeTransformer

use of io.cucumber.datatable.TableCellByTypeTransformer in project cucumber-jvm by cucumber.

the class StepTypeRegistryTest method should_set_default_table_entry_transformer.

@Test
void should_set_default_table_entry_transformer() {
    TableEntryByTypeTransformer expected = (entry, toValueType, tableCellByTypeTransformer) -> null;
    registry.setDefaultDataTableEntryTransformer(expected);
}
Also used : Date(java.util.Date) Expression(io.cucumber.cucumberexpressions.Expression) DataTableType(io.cucumber.datatable.DataTableType) Test(org.junit.jupiter.api.Test) ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) ParameterByTypeTransformer(io.cucumber.cucumberexpressions.ParameterByTypeTransformer) TableCellByTypeTransformer(io.cucumber.datatable.TableCellByTypeTransformer) Is.is(org.hamcrest.core.Is.is) DocStringType(io.cucumber.docstring.DocStringType) JsonNode(com.fasterxml.jackson.databind.JsonNode) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TableEntryByTypeTransformer(io.cucumber.datatable.TableEntryByTypeTransformer) ENGLISH(java.util.Locale.ENGLISH) ParameterType(io.cucumber.cucumberexpressions.ParameterType) DataTable(io.cucumber.datatable.DataTable) TableEntryByTypeTransformer(io.cucumber.datatable.TableEntryByTypeTransformer) Test(org.junit.jupiter.api.Test)

Example 2 with TableCellByTypeTransformer

use of io.cucumber.datatable.TableCellByTypeTransformer in project cucumber-jvm by cucumber.

the class StepTypeRegistryTest method should_set_default_table_cell_transformer.

@Test
void should_set_default_table_cell_transformer() {
    TableCellByTypeTransformer expected = (cell, toValueType) -> null;
    registry.setDefaultDataTableCellTransformer(expected);
}
Also used : Date(java.util.Date) Expression(io.cucumber.cucumberexpressions.Expression) DataTableType(io.cucumber.datatable.DataTableType) Test(org.junit.jupiter.api.Test) ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) ParameterByTypeTransformer(io.cucumber.cucumberexpressions.ParameterByTypeTransformer) TableCellByTypeTransformer(io.cucumber.datatable.TableCellByTypeTransformer) Is.is(org.hamcrest.core.Is.is) DocStringType(io.cucumber.docstring.DocStringType) JsonNode(com.fasterxml.jackson.databind.JsonNode) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TableEntryByTypeTransformer(io.cucumber.datatable.TableEntryByTypeTransformer) ENGLISH(java.util.Locale.ENGLISH) ParameterType(io.cucumber.cucumberexpressions.ParameterType) DataTable(io.cucumber.datatable.DataTable) TableCellByTypeTransformer(io.cucumber.datatable.TableCellByTypeTransformer) Test(org.junit.jupiter.api.Test)

Example 3 with TableCellByTypeTransformer

use of io.cucumber.datatable.TableCellByTypeTransformer in project cucumber-jvm by cucumber.

the class CachingGlue method prepareGlue.

void prepareGlue(StepTypeRegistry stepTypeRegistry) throws DuplicateStepDefinitionException {
    StepExpressionFactory stepExpressionFactory = new StepExpressionFactory(stepTypeRegistry, bus);
    // TODO: separate prepared and unprepared glue into different classes
    parameterTypeDefinitions.forEach(ptd -> {
        ParameterType<?> parameterType = ptd.parameterType();
        stepTypeRegistry.defineParameterType(parameterType);
        emitParameterTypeDefined(parameterType);
    });
    dataTableTypeDefinitions.forEach(dtd -> stepTypeRegistry.defineDataTableType(dtd.dataTableType()));
    docStringTypeDefinitions.forEach(dtd -> stepTypeRegistry.defineDocStringType(dtd.docStringType()));
    if (defaultParameterTransformers.size() == 1) {
        DefaultParameterTransformerDefinition definition = defaultParameterTransformers.get(0);
        ParameterByTypeTransformer transformer = definition.parameterByTypeTransformer();
        stepTypeRegistry.setDefaultParameterTransformer(transformer);
    } else if (defaultParameterTransformers.size() > 1) {
        throw new DuplicateDefaultParameterTransformers(defaultParameterTransformers);
    }
    if (defaultDataTableEntryTransformers.size() == 1) {
        DefaultDataTableEntryTransformerDefinition definition = defaultDataTableEntryTransformers.get(0);
        TableEntryByTypeTransformer transformer = definition.tableEntryByTypeTransformer();
        stepTypeRegistry.setDefaultDataTableEntryTransformer(transformer);
    } else if (defaultDataTableEntryTransformers.size() > 1) {
        throw new DuplicateDefaultDataTableEntryTransformers(defaultDataTableEntryTransformers);
    }
    if (defaultDataTableCellTransformers.size() == 1) {
        DefaultDataTableCellTransformerDefinition definition = defaultDataTableCellTransformers.get(0);
        TableCellByTypeTransformer transformer = definition.tableCellByTypeTransformer();
        stepTypeRegistry.setDefaultDataTableCellTransformer(transformer);
    } else if (defaultDataTableCellTransformers.size() > 1) {
        throw new DuplicateDefaultDataTableCellTransformers(defaultDataTableCellTransformers);
    }
    // TODO: Redefine hooks for each scenario, similar to how we're doing
    // for CoreStepDefinition
    beforeHooks.forEach(this::emitHook);
    beforeStepHooks.forEach(this::emitHook);
    stepDefinitions.forEach(stepDefinition -> {
        StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
        CoreStepDefinition coreStepDefinition = new CoreStepDefinition(bus.generateId(), stepDefinition, expression);
        CoreStepDefinition previous = stepDefinitionsByPattern.get(stepDefinition.getPattern());
        if (previous != null) {
            throw new DuplicateStepDefinitionException(previous, stepDefinition);
        }
        stepDefinitionsByPattern.put(coreStepDefinition.getExpression().getSource(), coreStepDefinition);
        emitStepDefined(coreStepDefinition);
    });
    afterStepHooks.forEach(this::emitHook);
    afterHooks.forEach(this::emitHook);
}
Also used : DefaultDataTableCellTransformerDefinition(io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) ParameterByTypeTransformer(io.cucumber.cucumberexpressions.ParameterByTypeTransformer) TableEntryByTypeTransformer(io.cucumber.datatable.TableEntryByTypeTransformer) DefaultParameterTransformerDefinition(io.cucumber.core.backend.DefaultParameterTransformerDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) DefaultDataTableEntryTransformerDefinition(io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition) TableCellByTypeTransformer(io.cucumber.datatable.TableCellByTypeTransformer)

Aggregations

ParameterByTypeTransformer (io.cucumber.cucumberexpressions.ParameterByTypeTransformer)3 TableCellByTypeTransformer (io.cucumber.datatable.TableCellByTypeTransformer)3 TableEntryByTypeTransformer (io.cucumber.datatable.TableEntryByTypeTransformer)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Expression (io.cucumber.cucumberexpressions.Expression)2 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)2 ParameterType (io.cucumber.cucumberexpressions.ParameterType)2 DataTable (io.cucumber.datatable.DataTable)2 DataTableType (io.cucumber.datatable.DataTableType)2 DocStringType (io.cucumber.docstring.DocStringType)2 Date (java.util.Date)2 ENGLISH (java.util.Locale.ENGLISH)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Is.is (org.hamcrest.core.Is.is)2 Test (org.junit.jupiter.api.Test)2 DefaultDataTableCellTransformerDefinition (io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition)1 DefaultDataTableEntryTransformerDefinition (io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition)1 DefaultParameterTransformerDefinition (io.cucumber.core.backend.DefaultParameterTransformerDefinition)1 StepExpression (io.cucumber.core.stepexpression.StepExpression)1 StepExpressionFactory (io.cucumber.core.stepexpression.StepExpressionFactory)1