Search in sources :

Example 16 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.

the class AliasTable method alias.

public DataTable alias(DataTable dataTable) {
    Set<Integer> columnsToAlias = Sets.newHashSet();
    Map<Pair<Integer, Integer>, String> aliasMatrix = Maps.newHashMap();
    for (int i = 0; i < dataTable.getGherkinRows().size(); i++) {
        DataTableRow row = dataTable.getGherkinRows().get(i);
        for (int j = 0; j < row.getCells().size(); j++) {
            String cell = row.getCells().get(j);
            if (i != 0 && columnsToAlias.contains(j) && !isNumber(cell) && !isBoolean(cell)) {
                // not header
                aliasMatrix.put(Pair.newPair(i, j), getAlias(cell));
            }
            if (i == 0) {
                // only for header
                boolean isPartnerField = cell.equalsIgnoreCase(I18N.CONSTANTS.partner() + " " + I18N.CONSTANTS.name());
                if (!ChooseColumnsDialog.BUILT_IN_COLUMNS.contains(cell) || isPartnerField) {
                    columnsToAlias.add(j);
                }
                if (!ChooseColumnsDialog.BUILT_IN_COLUMNS.contains(cell)) {
                    aliasMatrix.put(Pair.newPair(i, j), getAlias(cell));
                }
            }
        }
    }
    for (Map.Entry<Pair<Integer, Integer>, String> entry : aliasMatrix.entrySet()) {
        Integer row = entry.getKey().getFirst();
        Integer column = entry.getKey().getSecond();
        dataTable.getGherkinRows().get(row).getCells().set(column, entry.getValue());
    }
    return dataTable;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) DataTableRow(gherkin.formatter.model.DataTableRow) Pair(org.activityinfo.model.util.Pair)

Example 17 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.

the class BsTable method assertRowsPresent.

public BsTable assertRowsPresent(DataTable dataTable) {
    List<DataTableRow> matched = Lists.newArrayList();
    List<DataTableRow> notMatched = Lists.newArrayList();
    List<Row> rows = rows();
    int expectedRows = dataTable.getGherkinRows().size() - 2;
    if (rows.size() != expectedRows) {
        throw new AssertionError("Number of rows do not match, found on UI: " + rows.size() + ", expected: " + expectedRows);
    }
    for (Row row : rows) {
        for (int i = 2; i < dataTable.getGherkinRows().size(); i++) {
            DataTableRow gherkinRow = dataTable.getGherkinRows().get(i);
            if (matched(row.getCells(), gherkinRow)) {
                matched.add(gherkinRow);
            } else {
                notMatched.add(gherkinRow);
            }
        }
    }
    if (matched.size() == expectedRows) {
        // all are matched
        return this;
    }
    throw new AssertionError("Unable to find match for field values: " + notMatched);
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 18 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.

the class RelevanceDialog method set.

public RelevanceDialog set(DataTable dataTable, AliasTable alias) {
    for (int i = 0; i < dataTable.getGherkinRows().size(); i++) {
        DataTableRow row = dataTable.getGherkinRows().get(i);
        List<String> cells = row.getCells();
        Preconditions.checkState(cells.size() == 4);
        String fieldLabel = alias.getAlias(cells.get(0));
        String operation = cells.get(1);
        String value = cells.get(2);
        String controlType = cells.get(3);
        if ("radio".equals(controlType)) {
            value = alias.getAlias(value);
        }
        FluentElement lastRow = lastRow();
        List<FluentElement> select = lastRow.find().select().waitForList().list();
        Select fieldSelector = new Select(select.get(1).element());
        fieldSelector.selectByVisibleText(fieldLabel);
        Select operationSelector = new Select(select.get(2).element());
        operationSelector.selectByVisibleText(operation);
        switch(controlType) {
            case "radio":
                FluentElement radioLabel = lastRow().find().label(XPathBuilder.withText(value)).first();
                radioLabel.clickWhenReady();
                break;
        }
    }
    return save();
}
Also used : FluentElement(org.activityinfo.test.pageobject.api.FluentElement) Select(org.openqa.selenium.support.ui.Select) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 19 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project alien4cloud by alien4cloud.

the class EditorStepDefinitions method i_execute_the_operation.

@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);
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow) Given(cucumber.api.java.en.Given)

Example 20 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project alien4cloud by alien4cloud.

the class CrudCSARSStepDefinition method I_should_have_a_delete_csar_response_with_related_resources.

@Then("^The delete csar response should contains the following related resources$")
public void I_should_have_a_delete_csar_response_with_related_resources(DataTable usageDT) throws Throwable {
    RestResponse<?> restResponse = JsonUtil.read(Context.getInstance().getRestResponse());
    Assert.assertNotNull(restResponse);
    List<Usage> resultData = JsonUtil.toList(JsonUtil.toString(restResponse.getData()), Usage.class);
    boolean isPresent;
    for (Usage usage : resultData) {
        isPresent = false;
        for (DataTableRow row : usageDT.getGherkinRows()) {
            if (usage.getResourceName().equals(row.getCells().get(0)) && usage.getResourceType().equals(row.getCells().get(1))) {
                isPresent = true;
                break;
            }
        }
        if (!isPresent) {
            Assert.assertFalse("Test failed : one of expected usage is not found : " + usage.getResourceName() + " : " + usage.getResourceType(), true);
        }
    }
}
Also used : Usage(alien4cloud.model.common.Usage) DataTableRow(gherkin.formatter.model.DataTableRow) Then(cucumber.api.java.en.Then)

Aggregations

DataTableRow (gherkin.formatter.model.DataTableRow)46 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)9 List (java.util.List)6 And (cucumber.api.java.en.And)5 DataTable (cucumber.api.DataTable)4 DocString (gherkin.formatter.model.DocString)4 Step (gherkin.formatter.model.Step)4 Given (cucumber.api.java.en.Given)3 Then (cucumber.api.java.en.Then)3 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)3 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)3 Argument (gherkin.formatter.Argument)2 Arrays.asList (java.util.Arrays.asList)2 Map (java.util.Map)2 Pair (org.activityinfo.model.util.Pair)2 Usage (alien4cloud.model.common.Usage)1 Delta (cucumber.deps.difflib.Delta)1 I18n (gherkin.I18n)1 Row (gherkin.formatter.model.Row)1