private void createDataTableAttachment(final List<DataTableRow> dataTableRows) { if (dataTableRows != null && !dataTableRows.isEmpty()) { final StringBuilder dataTableCsv = new StringBuilder(); for (DataTableRow row : dataTableRows) { dataTableCsv.append(StringUtils.join(row.getCells().toArray(), "\t")); dataTableCsv.append('\n'); } ALLURE_LIFECYCLE.fire(new MakeAttachmentEvent(dataTableCsv.toString().getBytes(), "Data table", "text/tab-separated-values")); } }
private void createDataTableAttachment(final List<DataTableRow> dataTableRows) { final StringBuilder dataTableCsv = new StringBuilder(); if (dataTableRows != null && !dataTableRows.isEmpty()) { dataTableRows.forEach(dataTableRow -> { dataTableCsv.append(String.join("\t", dataTableRow.getCells())); dataTableCsv.append('\n'); }); final String attachmentSource = lifecycle .prepareAttachment("Data table", "text/tab-separated-values", "csv"); lifecycle.writeAttachment(attachmentSource, new ByteArrayInputStream(dataTableCsv.toString().getBytes(Charset.forName("UTF-8")))); } }
private DataTable.Row convertRow(DataTableRow row) { return new DataTable.Row(row.getCells(), convertComments(row.getComments())); }
@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); }
public DataTableRowDTO(DataTableRow row) { cells = row.getCells(); comments = CommentDTO.fromGherkinComments(row.getComments()); line = row.getLine(); diffType = row.getDiffType(); }
/** * Allow to parse a table of key value to a map and it supports the key being an environment variable * @param table a data table * @return a map */ public static Map<String, Object> dataTableToMap(DataTable table) { Map<String, Object> configuration = new HashMap<>(); table.getGherkinRows().forEach(dataTableRow -> { String key = dataTableRow.getCells().get(0); String value = dataTableRow.getCells().get(1); Object processedValue = System.getenv(value); if (processedValue == null || ((String) processedValue).isEmpty()) { processedValue = value; } // Convert to raw boolean or integer if possible. if (processedValue.equals("true")) { processedValue = true; } else if (processedValue.equals("false")) { processedValue = false; } else { try { processedValue = Integer.valueOf((String) processedValue); } catch (NumberFormatException e) { } } configuration.put(key, processedValue); }); return configuration; } }
@Then("^I should have a latest audit trace with a query defined below and whose secret \"([^\"]*)\" defined in requestBody should be hidden:$") public void iShouldHaveAuditTracesInAlienAndWhoseSecretDefinedInRequestBodyShouldBeHidden(String secretFieldName, DataTable table) throws Throwable { LinkedHashMap<String, String[]> queryMap = new LinkedHashMap<>(); table.getGherkinRows().forEach(dataTableRow -> { queryMap.put(dataTableRow.getCells().get(0), new String[] { dataTableRow.getCells().get(1) }); }); List<AuditTrace> auditTraces = searchAuditLogs("", 0, 1, queryMap, false); Map<String, Object> bodyMap = JsonUtil.toMap(auditTraces.get(0).getRequestBody()); Assert.assertEquals(true, ((String) bodyMap.get(secretFieldName)).contains("**********")); } }
@And("^I update configuration for orchestrator with name \"([^\"]*)\"$") public void updateOrchestratorConfiguration(String orchestratorName, DataTable table) throws Throwable { String orchestratorId = Context.getInstance().getOrchestratorId(orchestratorName); Map<String, Object> config = Context.getInstance().getOrchestratorConfiguration(); table.getGherkinRows().stream().forEach(dataTableRow -> { String key = dataTableRow.getCells().get(0); String value = dataTableRow.getCells().get(1); Object processedValue = System.getenv(value); if (processedValue == null || ((String) processedValue).isEmpty()) { processedValue = value; } // Convert to raw boolean or integer if possible. if (processedValue.equals("true")) { processedValue = true; } else if (processedValue.equals("false")) { processedValue = false; } else { try { processedValue = Integer.valueOf((String) processedValue); } catch (NumberFormatException e) { } } config.put(key, processedValue); }); Context.getInstance().setOrchestratorConfiguration(config); String restResponse = Context.getRestClientInstance().putJSon("/rest/v1/orchestrators/" + orchestratorId + "/configuration", JsonUtil.toString(config)); Context.getInstance().registerRestResponse(restResponse); }
@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); } } }