Search in sources :

Example 1 with DocString

use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method docstring_expression_transform_doc_string_to_json_node.

@Test
void docstring_expression_transform_doc_string_to_json_node() {
    String docString = "{\"hello\": \"world\"}";
    String contentType = "json";
    registry.defineDocStringType(new DocStringType(JsonNode.class, contentType, (String s) -> objectMapper.convertValue(docString, JsonNode.class)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", JsonNode.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", docString, contentType);
    JsonNode node = (JsonNode) match.get(0).getValue();
    assertThat(node.asText(), equalTo(docString));
}
Also used : DocStringType(io.cucumber.docstring.DocStringType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 2 with DocString

use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method docstring_expression_transform_doc_string_to_string.

@Test
void docstring_expression_transform_doc_string_to_string() {
    String docString = "A rather long and boring string of documentation";
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", String.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", docString, null);
    assertThat(match.get(0).getValue(), is(equalTo(docString)));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 3 with DocString

use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method unknown_target_type_transform_doc_string_to_doc_string.

@Test
void unknown_target_type_transform_doc_string_to_doc_string() {
    String docString = "A rather long and boring string of documentation";
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", docString, null);
    assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 4 with DocString

use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method docstring_and_datatable_match_same_step_definition.

@Test
void docstring_and_datatable_match_same_step_definition() {
    String docString = "A rather long and boring string of documentation";
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", docString, null);
    assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
    match = expression.match("Given some stuff:", table);
    assertThat(match.get(0).getValue(), is(equalTo(DataTable.create(table))));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 5 with DocString

use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.

the class JavaDocStringTypeDefinitionTest method correct_conversion_is_used_for_simple_and_complex_return_types.

@Test
public void correct_conversion_is_used_for_simple_and_complex_return_types() throws NoSuchMethodException {
    Method simpleMethod = JavaDocStringTypeDefinitionTest.class.getMethod("converts_string_to_simple_type", String.class);
    JavaDocStringTypeDefinition simpleDefinition = new JavaDocStringTypeDefinition("text/plain", simpleMethod, lookup);
    registry.defineDocStringType(simpleDefinition.docStringType());
    Method complexMethod = JavaDocStringTypeDefinitionTest.class.getMethod("converts_string_to_complex_type", String.class);
    JavaDocStringTypeDefinition complexDefinition = new JavaDocStringTypeDefinition("text/plain", complexMethod, lookup);
    registry.defineDocStringType(complexDefinition.docStringType());
    Type simpleType = Map.class;
    assertThat(converter.convert(docString, simpleType), hasEntry("some_simple_type", Collections.emptyMap()));
    Type complexType = new TypeReference<Map<String, Map<String, String>>>() {
    }.getType();
    assertThat(converter.convert(docString, complexType), hasEntry("some_complex_type", Collections.emptyMap()));
}
Also used : Type(java.lang.reflect.Type) Method(java.lang.reflect.Method) DocString(io.cucumber.docstring.DocString) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

DocString (io.cucumber.docstring.DocString)6 StepDefinition (io.cucumber.core.backend.StepDefinition)5 Test (org.junit.jupiter.api.Test)5 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)4 Type (java.lang.reflect.Type)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 EventBus (io.cucumber.core.eventbus.EventBus)1 CucumberException (io.cucumber.core.exception.CucumberException)1 Expression (io.cucumber.cucumberexpressions.Expression)1 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)1 UndefinedParameterTypeException (io.cucumber.cucumberexpressions.UndefinedParameterTypeException)1 DataTable (io.cucumber.datatable.DataTable)1 DataTableTypeRegistryTableConverter (io.cucumber.datatable.DataTableTypeRegistryTableConverter)1 DocStringType (io.cucumber.docstring.DocStringType)1 DocStringTypeRegistryDocStringConverter (io.cucumber.docstring.DocStringTypeRegistryDocStringConverter)1 Envelope (io.cucumber.messages.types.Envelope)1 UndefinedParameterType (io.cucumber.messages.types.UndefinedParameterType)1 String.format (java.lang.String.format)1 Method (java.lang.reflect.Method)1