Java Code Examples for cucumber.api.DataTable#raw()
The following examples show how to use
cucumber.api.DataTable#raw() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiSteps.java From akita with Apache License 2.0 | 6 votes |
/** * В json строке, сохраннённой в переменной, происходит поиск значений по jsonpath из первого столбца таблицы. * Полученные значения сохраняются в переменных. Название переменной указывается во втором столбце таблицы. * Шаг работает со всеми типами json элементов: объекты, массивы, строки, числа, литералы true, false и null. */ @Тогда("^значения из json (?:строки|файла) \"([^\"]*)\", найденные по jsonpath из таблицы, сохранены в переменные$") @Then("^values from json (?:string|file) named \"([^\"]*)\" has been found via jsonpaths from the table and saved to the variables$") public void getValuesFromJsonAsString(String jsonVar, DataTable dataTable) { String strJson = loadValueFromFileOrPropertyOrVariableOrDefault(jsonVar); Gson gsonObject = new Gson(); ReadContext ctx = JsonPath.parse(strJson, createJsonPathConfiguration()); boolean error = false; for (List<String> row : dataTable.raw()) { String jsonPath = row.get(0); String varName = row.get(1); JsonElement jsonElement; try { jsonElement = gsonObject.toJsonTree(ctx.read(jsonPath)); } catch (PathNotFoundException e) { error = true; continue; } akitaScenario.setVar(varName, jsonElement.toString()); akitaScenario.write("JsonPath: " + jsonPath + ", значение: " + jsonElement + ", записано в переменную: " + varName); } if (error) throw new RuntimeException("В json не найдено значение по заданному jsonpath"); }
Example 2
Source File: RoundUpSteps.java From akita with Apache License 2.0 | 6 votes |
/** * Выполняется чтение файла с шаблоном и заполнение его значениями из таблицы */ @И("^шаблон \"([^\"]*)\" заполнен данными из таблицы и сохранён в переменную \"([^\"]*)\"$") @And("^template named \"([^\"]*)\" has been filled with data from the table and saved to the variable \"([^\"]*)\"$") public void fillTemplate(String templateName, String varName, DataTable table) { String template = loadValueFromFileOrPropertyOrVariableOrDefault(templateName); boolean error = false; for (List<String> list : table.raw()) { String regexp = list.get(0); String replacement = list.get(1); if (template.contains(regexp)) { template = template.replaceAll(regexp, replacement); } else { akitaScenario.write("В шаблоне не найден элемент " + regexp); error = true; } } if (error) throw new RuntimeException("В шаблоне не найдены требуемые регулярные выражения"); akitaScenario.setVar(varName, template); }
Example 3
Source File: ThenSpec.java From Decision with Apache License 2.0 | 6 votes |
@Then("^the stream '(.*?)' has this columns \\(with name and type\\):$") public void assertStreamColumns(String streamName, DataTable data) throws StratioEngineOperationException { commonspec.getLogger().info("Verifying stream columns"); List<ColumnNameTypeValue> columns = commonspec.getStratioStreamingAPI() .columnsFromStream(streamName); List<ColumnNameTypeValue> expectedColumns = new ArrayList<ColumnNameTypeValue>(); for (List<String> row : data.raw()) { ColumnNameTypeValue expectedCol = new ColumnNameTypeValue( row.get(0), ColumnType.valueOf(row.get(1).toUpperCase()), null); expectedColumns.add(expectedCol); } assertThat(commonspec.getStratioStreamingAPI().columnsFromStream(streamName)) .as("Unexpected column count at stream " + streamName).hasSize(data.raw().size()); assertThat(columns).as("Unexpected columns at stream " + streamName).isEqualTo(expectedColumns); }
Example 4
Source File: WhenSpec.java From Decision with Apache License 2.0 | 6 votes |
@When("^I insert into a stream with name '(.*?)' this data:$") public void insertData( @Transform(NullableStringConverter.class) String streamName, DataTable table) { commonspec.getLogger().info("Inserting into stream {}", streamName); List<ColumnNameValue> streamData = new ArrayList<ColumnNameValue>(); for (List<String> row : table.raw()) { ColumnNameValue columnValue = new ColumnNameValue(row.get(0), row.get(1)); streamData.add(columnValue); } try { commonspec.getStratioStreamingAPI().insertData(streamName, streamData); } catch (Exception e) { commonspec.getExceptions().add(e); commonspec .getLogger() .info("Caught an exception whilst inserting data into the stream {} : {}", streamName, e); } }
Example 5
Source File: ApiSteps.java From akita with Apache License 2.0 | 5 votes |
/** * В json строке, сохраннённой в переменной, происходит поиск значений по jsonpath из первого столбца таблицы. * Полученные значения сравниваются с ожидаемым значением во втором столбце таблицы. * Шаг работает со всеми типами json элементов: объекты, массивы, строки, числа, литералы true, false и null. */ @Тогда("^в json (?:строке|файле) \"([^\"]*)\" значения, найденные по jsonpath, равны значениям из таблицы$") @Then("^values from json (?:string|file) named \"([^\"]*)\" found via jsonpath are equal to the values from the table$") public void checkValuesInJsonAsString(String jsonVar, DataTable dataTable) { String strJson = loadValueFromFileOrPropertyOrVariableOrDefault(jsonVar); Gson gsonObject = new Gson(); JsonParser parser = new JsonParser(); ReadContext ctx = JsonPath.parse(strJson, createJsonPathConfiguration()); boolean error = false; for (List<String> row : dataTable.raw()) { String jsonPath = row.get(0); JsonElement actualJsonElement; try { actualJsonElement = gsonObject.toJsonTree(ctx.read(jsonPath)); } catch (PathNotFoundException e) { error = true; continue; } JsonElement expectedJsonElement = parser.parse(row.get(1)); if (!actualJsonElement.equals(expectedJsonElement)) { error = true; } akitaScenario.write("JsonPath: " + jsonPath + ", ожидаемое значение: " + expectedJsonElement + ", фактическое значение: " + actualJsonElement); } if (error) throw new RuntimeException("Ожидаемые и фактические значения в json не совпадают"); }
Example 6
Source File: RedisSteps.java From redisq with MIT License | 5 votes |
@And("^with these values:$") public void with_these_values(DataTable expected) throws Throwable { Map<String, String> actuals = currentCheckedHash; List<List<String>> keyValues = expected.raw(); for (List<String> keyValue : keyValues) { String lookupKey = keyValue.get(0); String expectedValue = keyValue.get(1); assertThat(actuals, hasEntry(lookupKey, expectedValue)); } }
Example 7
Source File: GraphGlue.java From vertexium with Apache License 2.0 | 5 votes |
@Given("^parameters are:$") public void givenParametersAre(DataTable parameters) { for (List<String> parameterRow : parameters.raw()) { String key = parameterRow.get(0); String valueString = parameterRow.get(1); Object value = parseParameterValue(valueString); ctx.setParameter(key, value); } }
Example 8
Source File: GraphGlue.java From vertexium with Apache License 2.0 | 5 votes |
@Then("^the side effects should be:$") public void thenTheSideEffectsShouldBe(DataTable table) { for (List<String> tableRow : table.raw()) { if (tableRow.size() == 2 && tableRow.get(0).equals("+nodes")) { int plusNodes = Integer.parseInt(tableRow.get(1)); assertEquals("+nodes", plusNodes, ctx.getPlusNodeCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("+relationships")) { int plusRelationships = Integer.parseInt(tableRow.get(1)); assertEquals("+relationships", plusRelationships, ctx.getPlusRelationshipCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("+labels")) { int plusLabels = Integer.parseInt(tableRow.get(1)); assertEquals("+labels", plusLabels, ctx.getPlusLabelCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("+properties")) { int plusProperties = Integer.parseInt(tableRow.get(1)); assertEquals("+properties", plusProperties, ctx.getPlusPropertyCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("-nodes")) { int minusNodes = Integer.parseInt(tableRow.get(1)); assertEquals("-nodes", minusNodes, ctx.getMinusNodeCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("-relationships")) { int minusRelationships = Integer.parseInt(tableRow.get(1)); assertEquals("-relationships", minusRelationships, ctx.getMinusRelationshipCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("-labels")) { int minusLabels = Integer.parseInt(tableRow.get(1)); assertEquals("-labels", minusLabels, ctx.getMinusLabelCount()); } else if (tableRow.size() == 2 && tableRow.get(0).equals("-properties")) { int minusProperties = Integer.parseInt(tableRow.get(1)); assertEquals("-properties", minusProperties, ctx.getMinusPropertyCount()); } else { fail("Unhandled side effect row: " + tableRow.stream().collect(Collectors.joining(","))); } } }
Example 9
Source File: CucumberTestFixture.java From senbot with MIT License | 5 votes |
@When("^I visit the pages:$") public void the_pages_have_been_visited(DataTable arguments) throws IOException { List<List<String>> asList = arguments.raw(); for(List<String> row : asList) { seleniumNavigationService.navigate_to_url(row.get(0)); } }
Example 10
Source File: MySeleniumStepDefinitions.java From senbot with MIT License | 5 votes |
@When("^I visit the pages:$") public void the_pages_have_been_visited(DataTable arguments) throws IOException { List<List<String>> asList = arguments.raw(); for(List<String> row : asList) { seleniumNavigationService.navigate_to_url(row.get(0)); } }
Example 11
Source File: ConvertCucumberDataTable.java From serenity-cucumber-bdd-screenplay with Apache License 2.0 | 4 votes |
private ConvertCucumberDataTable(DataTable dataTable) { this.rows = dataTable.raw(); this.headers = this.rows.get(0); this.flatMap = new LinkedHashMap<>(); }