public DataTableRowDTO(DataTableRow row) { cells = row.getCells(); comments = CommentDTO.fromGherkinComments(row.getComments()); line = row.getLine(); diffType = row.getDiffType(); }
public void row(List<Comment> comments, List<String> cells, Integer line, String id) { if (rows == null) { rows = new ArrayList<DataTableRow>(); } rows.add(new DataTableRow(comments, cells, line)); }
private DataTable.Row convertRow(DataTableRow row) { return new DataTable.Row(row.getCells(), convertComments(row.getComments())); }
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")); } }
List<Comment> comments = dtr.getComments(); if (comments != null) { for (Comment comment : comments) { createLine(sb, dtr.getLine(), RESULT_TYPE.NO_RESULT); int colwidth = 100 / (dtr.getCells().size()); for (String cell : dtr.getCells()) { if (firstRow) { sb.append("<th width=\"").append(colwidth).append("%\">");
@Override public void step(Step step) { if (lineOffset != 0 && isPreview) { int newLine = step.getLine().intValue() + lineOffset.intValue(); featureLineOffset.put(step.getLine().intValue(), newLine); step = new Step(step.getComments(), step.getKeyword(), step.getName(), newLine, step.getRows(), step.getDocString()); } if (step.getRows() != null && step.getRows().get(0) != null && !step.getRows().get(0).getComments().isEmpty()) { String filePathFromComment = getExtractFilePathFromComment(step.getRows().get(0).getComments().get(0).getValue()); Resource sourceResource = getSourceResource(filePathFromComment); if (sourceResource != null) { step = loadAndReplaceSteps(step, filePathFromComment, sourceResource); } } super.step(step); prettyFormatter.step(step); }
@Override public Range getLineRange() { Range range = super.getLineRange(); if (getRows() != null) { range = new Range(range.getFirst(), getRows().get(getRows().size() - 1).getLine()); } else if (getDocString() != null) { range = new Range(range.getFirst(), getDocString().getLineRange().getLast()); } return range; }
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")))); } }
@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 DataTableRow toDataTableRow() { return new DataTableRow(CommentDTO.toGherkinComments(comments), cells, line, diffType); } }
@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("**********")); } }
private List<DataTableRow> dataTableRows(List o) { List<DataTableRow> rows = new ArrayList<DataTableRow>(o.size()); for (Object e : o) { Map row = (Map) e; rows.add(new DataTableRow(comments(row), getList(row, "cells"), getInt(row, "line"))); } return rows; }
/** * 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; } }
public String getKeywordTable() { StringWriter writer = new StringWriter(); PrettyFormatter pf = new PrettyFormatter(writer, true, false); List<Row> table = new ArrayList<Row>(); for (String key : KEYWORD_KEYS) { List<String> cells = Arrays.asList(key, join(map(keywords(key), QUOTE_MAPPER), ", ")); table.add(new DataTableRow(Collections.<Comment>emptyList(), cells, -1)); } for (String key : STEP_KEYWORD_KEYS) { List<String> codeKeywordList = new ArrayList<String>(keywords.get(key)); codeKeywordList.remove("* "); String codeKeywords = join(map(map(codeKeywordList, CODE_KEYWORD_MAPPER), QUOTE_MAPPER), ", "); List<String> cells = Arrays.asList(key + " (code)", codeKeywords); table.add(new DataTableRow(Collections.<Comment>emptyList(), cells, -1)); } pf.table(table); return writer.getBuffer().toString(); }
@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); }
private Step loadAndReplaceSteps(Step step, String filePathFromComment, Resource sourceResource) { DataReader dataReader; try { InputStream inputStream = sourceResource.getInputStream(); dataReader = DataReaderFactory.create(sourceResource.getFilename()); DataDTO data = dataReader.readTable(inputStream); List<DataTableRow> rows = Lists.newArrayList(); for (Integer lineNum : data.getValues().keySet()) { List<String> cells = Lists.newArrayList(data.getValues().get(lineNum)); String valueComment = String.format("# %s:%d", filePathFromComment, lineNum + 1); Comment comment = new Comment(valueComment, lineNum); List<Comment> comments = Lists.newArrayList(comment); int newLineNum = step.getLine() + 2; if (isPreview) { newLineNum += lineOffset; } DataTableRow row = new DataTableRow(comments, cells, newLineNum + 1); rows.add(row); lineOffset += 2; } // re-calculate lineOffset lineOffset = lineOffset - step.getRows().size() - 1; step = new Step(step.getComments(), step.getKeyword(), step.getName(), step.getLine(), rows, step.getDocString()); } catch (InstantiationException | IllegalAccessException | IOException e) { throw Throwables.propagate(e); } return step; }
@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); } } }