Result getResult() { CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData(); compositeResultData.setHeader( "************************* Execution Summary ***********************\nScript file: " + filePath); for (int i = 0; i < this.commandAndStatusList.size(); i++) { int commandSrNo = i + 1; CompositeResultData.SectionResultData section = compositeResultData.addSection("" + (i + 1)); CommandAndStatus commandAndStatus = commandAndStatusList.get(i); section.addData("Command-" + String.valueOf(commandSrNo), commandAndStatus.command); section.addData("Status", commandAndStatus.status); if (commandAndStatus.status.equals("FAILED")) { compositeResultData.setStatus(Result.Status.ERROR); } if (i != this.commandAndStatusList.size()) { section.setFooter(Gfsh.LINE_SEPARATOR); } } return ResultBuilder.buildResult(compositeResultData); }
@Test public void withNestedSectionContainingASingleTable() { CompositeResultData result = new CompositeResultData(); String outerHeader = "this outerHeader left blank"; String outerFooter = "this outerFooter left blank"; result.setHeader(outerHeader); result.setFooter(outerFooter); CompositeResultData.SectionResultData section = result.addSection(); String tableSurround = "this surround left blank"; section.addTable(); section.setHeader(tableSurround); section.setFooter(tableSurround); GfJsonObject json = result.getGfJsonObject(); assertThat(json.getJSONObject("content").getJSONObject("__sections__-0") .getJSONObject("__tables__-0").getString("content")).isEqualTo("{}"); assertThat(json.getString("footer")).isEqualTo(outerFooter); assertThat(json.getString("header")).isEqualTo(outerHeader); assertThat(json.getJSONObject("content").getJSONObject("__sections__-0").getString("header")) .isEqualTo(tableSurround); assertThat(json.getJSONObject("content").getJSONObject("__sections__-0").getString("footer")) .isEqualTo(tableSurround); CompositeResultData.SectionResultData resultSection = result.retrieveSectionByIndex(0); assertThat(resultSection.getSectionGfJsonObject().getString("header")).isEqualTo(tableSurround); assertThat(resultSection.getSectionGfJsonObject().getString("footer")).isEqualTo(tableSurround); assertThat(resultSection.retrieveTable("0").getGfJsonObject().getString("content")) .isEqualTo("{}"); }
section1.addData("param-3", "value-3"); section1.addData("param-2", "value-2"); section1.setFooter("section 0 footer");