Java Code Examples for cucumber.api.DataTable#asMap()

The following examples show how to use cucumber.api.DataTable#asMap() . 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: PreparationStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Check if an existing preparation contains the same actions as the one given in parameters.
 * Be careful ! If your preparation contains lookup actions, you'll need to load your dataset by restoring a Mongo
 * dump, else the lookup_ds_id won't be the same in actions' parameter value.
 *
 * @param dataTable step parameters.
 * @throws IOException in case of exception.
 */
@Given("^A preparation with the following parameters exists :$")
public void checkPreparation(DataTable dataTable) throws IOException {
    Map<String, String> params = dataTable.asMap(String.class, String.class);
    String suffixedPrepName = getSuffixedPrepName(params.get(PREPARATION_NAME));
    String prepPath = util.extractPathFromFullName(params.get(PREPARATION_NAME));
    String prepId = context.getPreparationId(suffixedPrepName, prepPath);

    PreparationDetails prepDet = getPreparationDetails(prepId);
    Assert.assertNotNull(prepDet);
    assertEquals(prepDet.dataSetId, context.getDatasetId(suffixName(params.get(DATASET_NAME))));
    assertEquals(Integer.toString(prepDet.steps.size() - 1), params.get(NB_STEPS));

    if (params.get("actionsList") != null) {
        List<Action> actionsList = prepDet.actions;
        checkActionsListOfPrepa(actionsList, params.get("actionsList").toString());
    }
}
 
Example 2
Source File: PreparationStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Then("^The preparation \"(.*)\" should have the following quality bar characteristics on the column number \"(.*)\":$")
public void thePreparationShouldHaveThefollowingQualityBar(String preparationName, String columnNumber,
        DataTable dataTable) throws Exception {
    Response response = api.getPreparationContent(context.getPreparationId(suffixName(preparationName)),
            VERSION_HEAD, HEAD_ID, StringUtils.EMPTY);
    response.then().statusCode(OK.value());

    DatasetContent datasetContent = response.as(DatasetContent.class);

    final Map<String, String> parameters = dataTable.asMap(String.class, String.class);
    Integer validExpected = Integer.parseInt(parameters.get(VALID_CELL));
    Integer invalidExpected = Integer.parseInt(parameters.get(INVALID_CELL));
    Integer emptyExpected = Integer.parseInt(parameters.get(EMPTY_CELL));

    ContentMetadataColumn columnMetadata = datasetContent.metadata.columns.get(Integer.parseInt(columnNumber));
    assertEquals(validExpected, columnMetadata.quality.get(VALID_CELL));
    assertEquals(invalidExpected, columnMetadata.quality.get(INVALID_CELL));
    assertEquals(emptyExpected, columnMetadata.quality.get(EMPTY_CELL));
}
 
Example 3
Source File: PreparationStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Then("^The preparation \"(.*)\" should have the following invalid characteristics on the row number \"(.*)\":$")
public void thePreparationShouldHaveThefollowingInvalidCells(String preparationName, String columnNumber,
        DataTable dataTable) throws Exception {
    Response response = api.getPreparationContent(context.getPreparationId(suffixName(preparationName)),
            VERSION_HEAD, HEAD_ID, StringUtils.EMPTY);
    response.then().statusCode(OK.value());

    DatasetContent datasetContent = response.as(DatasetContent.class);

    final Map<String, String> parameters = dataTable.asMap(String.class, String.class);
    String invalidCells = parameters.get("invalidCells");

    HashMap values = (HashMap<String, String>) datasetContent.records.get(Integer.parseInt(columnNumber));
    if (!invalidCells.equals(StringUtils.EMPTY)) {
        assertEquals(invalidCells, values.get(TDP_INVALID_MARKER));
    } else {
        // there is no invalid cell
        assertNull(values.get(TDP_INVALID_MARKER));
    }
}
 
Example 4
Source File: ActionStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Given("^I update the first action with name \"(.*)\" on the preparation \"(.*)\" with the following parameters :$")
public void updateFirstActionFoundWithName(String actionName, String prepName, DataTable dataTable)
        throws IOException {
    Map<String, String> params = dataTable.asMap(String.class, String.class);
    String prepId = context.getPreparationId(suffixName(prepName));
    Action foundAction = getFirstActionWithName(prepId, actionName);
    assertTrue("No action with name \"" + actionName + "\" on the preparation named \"" + prepName + "\".",
            foundAction != null);
    // Update action
    Action action = new Action();
    action.action = actionName;
    action.id = foundAction.id;
    action.parameters = new HashMap<>(foundAction.parameters);
    action.parameters.putAll(util.mapParamsToActionParameters(params));

    Response response = api.updateAction(prepId, action.id, action);
    response.then().statusCode(200);
}
 
Example 5
Source File: FilterStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Then("^The characteristics of the dataset \"(.*)\" match:$")
public void checkFilterAppliedOnDataSet(String datasetName, DataTable dataTable) throws Exception {
    Map<String, String> expected = dataTable.asMap(String.class, String.class);

    DatasetContent datasetContent = (DatasetContent) context.getObject("dataSetContent");
    if (datasetContent == null) {
        datasetContent = getDatasetContent(context.getDatasetId(suffixName(datasetName)), null);
    }

    if (expected.get("records") != null) {
        checkRecords(datasetContent.records, expected.get("records"));
    }

    if (expected.get("sample_records_count") != null) {
        checkSampleRecordsCount(datasetContent.metadata.records, expected.get("sample_records_count"));
    }

    if (expected.get("quality") != null) {
        checkQualityPerColumn(datasetContent.metadata.columns, expected.get("quality"));
    }
}
 
Example 6
Source File: ActionStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Then("^I update the first step like \"(.*)\" on the preparation \"(.*)\" with the following parameters :$")
public void updateStep(String stepName, String prepName, DataTable dataTable) throws IOException {
    Map<String, String> params = dataTable.asMap(String.class, String.class);
    String prepId = context.getPreparationId(suffixName(prepName));
    Action storedAction = context.getAction(stepName);
    assertTrue("No Action on the step named \"" + stepName + "\" has been retrieve in the context.",
            storedAction != null);
    List<Action> actions = getActionsFromStoredAction(prepId, storedAction);
    assertTrue("Action list on the preparation named \"" + prepName + "\" is empty.", actions.size() > 0);
    // update stored action parameters
    storedAction.parameters.putAll(util.mapParamsToActionParameters(params));
    storedAction.id = actions.get(0).id;
    Response response = api.updateAction(prepId, storedAction.id, storedAction);
    response.then().statusCode(200);
}
 
Example 7
Source File: AggregateStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@When("^I apply an aggregation \"(.*)\" on the preparation \"(.*)\" with parameters :$")
public void applyAnAggregationOnPreparation(String aggregationName, String preparationName, DataTable dataTable)
        throws Exception {
    Map<String, String> params = new HashMap<>(dataTable.asMap(String.class, String.class));
    params.put(PREPARATION_ID, context.getPreparationId(suffixName(preparationName)));

    Aggregate aggregate = createAggregate(params);

    Response response = api.applyAggragate(aggregate);
    response.then().statusCode(OK.value());

    context.storeObject(suffixName(aggregationName),
            objectMapper.readValue(response.body().print(), new TypeReference<List<AggregateResult>>() {
            }));
}
 
Example 8
Source File: AggregateStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
private void aggregationFailed(String preparationName, String dataSetName, DataTable dataTable, int value)
        throws Exception {
    Map<String, String> params = new HashMap<>(dataTable.asMap(String.class, String.class));
    if (preparationName != null) {
        params.put(PREPARATION_ID, context.getPreparationId(suffixName(preparationName)));
    }
    if (dataSetName != null) {
        params.put(DATA_SET_ID, context.getDatasetId(suffixName(dataSetName)));
    }

    Aggregate aggregate = createAggregate(params);

    Response response = api.applyAggragate(aggregate);
    response.then().statusCode(value);
}
 
Example 9
Source File: AggregateStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Then("^The aggregation \"(.*)\" results with the operator \"(.*)\" is :$")
public void testAggregate(String aggregationName, String operator, DataTable dataTable) throws Exception {
    Map<String, String> params = dataTable.asMap(String.class, String.class);

    List<AggregateResult> aggregateResults =
            (List<AggregateResult>) (context.getObject(suffixName(aggregationName)));
    assertEquals(toAggregateResult(params, operator), aggregateResults);
}
 
Example 10
Source File: AggregateStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@When("^I apply an aggregation \"(.*)\" on the dataSet \"(.*)\" with parameters :$")
public void applyAnAggregationOnDataSet(String aggregationName, String dataSetName, DataTable dataTable)
        throws Exception {
    Map<String, String> params = new HashMap<>(dataTable.asMap(String.class, String.class));
    params.put(DATA_SET_ID, context.getDatasetId(suffixName(dataSetName)));

    Aggregate aggregate = createAggregate(params);

    Response response = api.applyAggragate(aggregate);
    response.then().statusCode(OK.value());

    context.storeObject(suffixName(aggregationName),
            objectMapper.readValue(response.body().print(), new TypeReference<List<AggregateResult>>() {
            }));
}
 
Example 11
Source File: DataPrepStep.java    From data-prep with Apache License 2.0 4 votes vote down vote up
public void checkContent(PreparationContent preparation, DataTable dataTable) throws Exception {
    Map<String, String> expected = dataTable.asMap(String.class, String.class);
    checkRecords(preparation.records, expected.get("records"));
    checkQualityPerColumn(preparation.metadata.columns, expected.get("quality"));
    checkSampleRecordsCount(preparation.metadata.records, expected.get("sample_records_count"));
}