cucumber.api.DataTable类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(243)

本文整理了Java中cucumber.api.DataTable类的一些代码示例,展示了DataTable类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataTable类的具体详情如下:
包路径:cucumber.api.DataTable
类名称:DataTable

DataTable介绍

[英]replaces cucumber-jvm code
[中]替换jvm代码

代码示例

代码示例来源:origin: serenity-bdd/serenity-cucumber

private List<Map<String,String>> mapped(DataTable expectedCost) {
    return expectedCost.asMaps(String.class, String.class);
  }
}

代码示例来源:origin: com.foreach.cwb/cwb-core

@Then("^ensure that \"([^\"]*)\" (?:contains|should contain):$")
public void ensure_that_contains( String spelExpressionOne, DataTable dataTable ) throws Throwable {
  Object entity = spel.getValue( spelExpressionOne );
  int numberOfCells = dataTable.topCells().size();
  if ( numberOfCells != 1 && numberOfCells != 2 ) {
    fail( "should not contain only supports tables of 1 or 2 columns" );
  }
  Map<String, String> values = new HashMap<String, String>();
  if ( numberOfCells == 1 ) {
    List<String> datatablecells = dataTable.asList( String.class );
    for ( String cell : datatablecells ) {
      values.put( cell, null );
    }
  }
  if ( numberOfCells == 2 ) {
    values = dataTable.asMap( String.class, String.class );
  }
  Map entities = new BeanMap( entity );
  mapChecker.contains( entities, values, true );
}

代码示例来源:origin: se.redmind/rmtest-cucumber-selenium

@Given("^the aliases defined in the file " + QUOTED_CONTENT + "$")
public void the_aliases_defined_in_the_file(String fileName) throws IOException {
  Splitter splitter = Splitter.on("|").trimResults().omitEmptyStrings();
  List<String> lines = Files.readLines(new File(fileName), Charset.defaultCharset());
  List<List<String>> rows = lines.stream().map(splitter::splitToList).collect(Collectors.toList());
  these_aliases(DataTable.create(rows).asMaps(String.class, String.class));
}

代码示例来源:origin: serenity-bdd/serenity-cucumber

public void match(List<Map<String, String>> expectedOutcomes) {
  DataTable actualOutcomesTable = DataTable.create(actualOutcomes);
  DataTable expectedOutcomesTable = DataTable.create(expectedOutcomes);
  actualOutcomesTable.diff(expectedOutcomesTable);
}

代码示例来源:origin: alien4cloud/alien4cloud

private List<SubstitutionSetting> convertSubtitution(DataTable expectedSettings) {
  List<List<String>> raw = Lists.newArrayList(expectedSettings.raw());
  raw.add(0, Lists.newArrayList("templateNme", "resourceName", "resourceType"));
  DataTable toConvert = expectedSettings.toTable(raw);
  return toConvert.asList(SubstitutionSetting.class);
}

代码示例来源:origin: alfa-laboratory/akita

/**
 * Выполняется чтение файла с шаблоном и заполнение его значениями из таблицы
 */
@И("^шаблон \"([^\"]*)\" заполнен данными из таблицы и сохранён в переменную \"([^\"]*)\"$")
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);
}

代码示例来源:origin: Appendium/objectlabkit

public static <T> List<T> convertDataTable(final DataTable table, final Class<T> typeOfT, final List<String> propertiesToCopy) {
  return table.asList(typeOfT).stream().map(t -> copyFields(t, typeOfT, propertiesToCopy)).collect(Collectors.toList());
}

代码示例来源:origin: Appendium/objectlabkit

private static <T> String convertToString(final List<T> actualRowValues, final List<String> propertiesToCompare) {
  final List<List<Object>> rawRows = new ArrayList<>();
  rawRows.add(propertiesToCompare.stream().collect(Collectors.toList()));
  for (final T actualRow : actualRowValues) {
    final BeanWrapper src = new BeanWrapperImpl(actualRow);
    rawRows.add(propertiesToCompare.stream().map(p -> {
      final Object propertyValue = src.getPropertyValue(p);
      if (propertyValue == null) {
        return "";
      } else if (src.getPropertyTypeDescriptor(p).getObjectType().isAssignableFrom(BigDecimal.class)) {
        return ((BigDecimal) propertyValue).stripTrailingZeros().toPlainString();
      }
      return propertyValue;
    }).collect(Collectors.toList()));
  }
  return DataTable.create(rawRows).toString();
}

代码示例来源:origin: viltgroup/minium

public DataTableDTO(DataTable dataTable) {
  List<DataTableRow> gherkinRows = dataTable.getGherkinRows();
  for (DataTableRow gherkinRow : gherkinRows) {
    rows.add(new DataTableRowDTO(gherkinRow));
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

@Given("^I have applications with names and descriptions and a topology containing a nodeTemplate \"([^\"]*)\" related to \"([^\"]*)\"$")
public void I_have_applications_with_names_and_description_containing_nodetemplate(String nodeName, String componentType,
    Map<String, String> applicationRequests) throws Throwable {
  CURRENT_APPLICATIONS.clear();
  // Prepare a cucumber data table using the node infos.
  List<String> nodeData = Lists.newArrayList(nodeName, componentType);
  List<List<String>> raw = Lists.newArrayList();
  raw.add(nodeData);
  DataTable dataTable = DataTable.create(raw);
  // Create each application and store in CURRENT_APPS
  for (java.util.Map.Entry<String, String> request : applicationRequests.entrySet()) {
    I_create_a_new_application_with_name_and_description_and_node_templates(request.getKey(), request.getValue(), dataTable);
    CURRENT_APPLICATIONS.put(request.getKey(), CURRENT_APPLICATION);
  }
  assertEquals(CURRENT_APPLICATIONS.size(), applicationRequests.size());
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Then("^\"([^\"]*)\" should see message \"([^\"]*)\" in mailboxes:$")
public void assertMailboxesOfMessage(String user, String messageId, DataTable userMailboxes) throws Exception {
  userStepdefs.execWithUser(user, () -> postWithAListOfIds(ImmutableList.of(messageId)));
  List<String> mailboxIds = userMailboxes.asMap(String.class, String.class).entrySet().stream()
    .map(Throwing.function(userMailbox ->
      mainStepdefs
        .getMailboxId(userMailbox.getKey(), userMailbox.getValue())
        .serialize()))
    .distinct()
    .collect(Guavate.toImmutableList());
  assertThat(httpClient.jsonPath.<JSONArray>read(FIRST_MESSAGE + ".mailboxIds"))
    .containsExactlyInAnyOrder(mailboxIds.toArray());
}

代码示例来源:origin: viltgroup/minium

public DataTable toDataTable(TableConverter tableConverter) {
    List<DataTableRow> gherkinRows = new ArrayList<DataTableRow>();
    for (DataTableRowDTO row : rows) {
      gherkinRows.add(row.toDataTableRow());
    }
    return new DataTable(gherkinRows, tableConverter);
  }
}

代码示例来源:origin: Appendium/objectlabkit

public static <T> void compareResults(final Class<T> classType, final List<T> actual, final DataTable expected) {
  final List<String> fieldsToCompare = expected.topCells();
  final T[] expectedEntities = convertDataTableToExpected(classType, expected, fieldsToCompare);
  final List<T> actualEntities = actual.stream().map(sea -> copyFieldValues(fieldsToCompare, sea, classType)).collect(Collectors.toList());
  try {
    assertThat(actualEntities).usingElementComparator(comparator(buildExclusionFields(classType, fieldsToCompare)))
        .containsOnly(expectedEntities);
  } catch (final java.lang.AssertionError e) {
    final String actualDataAsStr = convertToString(actual, fieldsToCompare);
    throw new ComparisonFailure("Table comparison for " + classType.getSimpleName() + " does not match\n", expected.toString(),
        actualDataAsStr);
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

private Set<String> getExpectedNames(DataTable rawExpected) {
  return rawExpected.raw().stream().map(line -> StringUtils.trim(line.get(0))).collect(Collectors.toSet());
}

代码示例来源:origin: alien4cloud/alien4cloud

private List<LocationPolicySetting> convert(DataTable expectedSettings) {
  List<List<String>> raw = Lists.newArrayList(expectedSettings.raw());
  raw.add(0, Lists.newArrayList("groupName", "orchestratorName", "locationName"));
  DataTable toCenvert = expectedSettings.toTable(raw);
  return toCenvert.asList(LocationPolicySetting.class);
}

代码示例来源:origin: serenity-bdd/serenity-cucumber

public void match(DataTable expectedOutcomes) {
    DataTable.create(actualOutcomes).diff(expectedOutcomes);
  }
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

private void assertAttachment(String attachment, DataTable attachmentProperties) {
  attachmentProperties.asList(TableRow.class)
    .forEach(entry -> assertThat(httpClient.jsonPath.<Object>read(attachment + "." + entry.getKey())).isEqualTo(entry.getValue()));
}

代码示例来源:origin: alien4cloud/alien4cloud

@Given("^I execute the operation$")
public void i_execute_the_operation(DataTable operationDT) throws Throwable {
  Map<String, String> operationMap = Maps.newLinkedHashMap();
  for (DataTableRow row : operationDT.getGherkinRows()) {
    operationMap.put(row.getCells().get(0), row.getCells().get(1));
  }
  do_i_execute_the_operation(operationMap);
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Then("^the headers of the message contains:$")
public void assertHeadersOfTheFirstMessage(DataTable headers) {
  assertThat(httpClient.jsonPath.<Map<String, String>>read(FIRST_MESSAGE + ".headers")).containsAllEntriesOf(headers.asMap(String.class, String.class));
}

代码示例来源:origin: alfa-laboratory/akita

public static DataTable dataTableFromLists(List<List<String>> lists) {
    List<PickleRow> rows = new ArrayList<>();
    lists.forEach(list -> {
      List<PickleCell> cells = new ArrayList<>();
      list.forEach(string -> {
        cells.add(new PickleCell(null,string));
      });
      rows.add(new PickleRow(cells));
    });
    return new DataTable(new PickleTable(rows), null);
  }
}

相关文章