@Test public void withSection_andHeader_andFooter() { CompositeResultData result = new CompositeResultData(); String header = "this header left blank"; String footer = "this footer left blank"; result.addSection(); result.setHeader(header); result.setFooter(footer); GfJsonObject json = result.getGfJsonObject(); assertThat(json.getJSONObject("content").getString("__sections__-0")).isEqualTo("{}"); assertThat(json.getString("footer")).isEqualTo(footer); assertThat(json.getString("header")).isEqualTo(header); }
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 justAFooter() { CompositeResultData result = new CompositeResultData(); String footer = "this space left blank"; result.setFooter(footer); GfJsonObject json = result.getGfJsonObject(); assertThat(json.getString("footer")).isEqualTo(footer); assertThat(json.getString("content")).isEqualTo("{}"); }
@Test public void emptySection() { CompositeResultData result = new CompositeResultData(); result.addSection(); GfJsonObject json = result.getGfJsonObject(); assertThat(json.getJSONObject("content").getString("__sections__-0")).isEqualTo("{}"); }
@Test public void compositeResultDataStructure() { CompositeResultData result = ResultBuilder.createCompositeResultData(); result.setHeader("Heads"); result.setFooter("Tails"); // build up an example result.addSection().addData("section 0 key", "section 0 value"); result.addSection().addTable().accumulate("table 1 column", "table 1 value"); CommandResult cmdResult = ResultBuilder.buildResult(result); assertThat(cmdResult.getHeader()).isEqualTo("Heads"); assertThat(cmdResult.getFooter()).isEqualTo("Tails"); assertThat(cmdResult.getMapFromSection("0").get("section 0 key")).isEqualTo("section 0 value"); Map<String, List<String>> table = cmdResult.getMapFromTableContent("1", "0"); assertThat(table.get("table 1 column")).contains("table 1 value"); }
public SectionResultData addSection() { return addSection(String.valueOf(subsectionCount)); }
@Test public void justAHeader() { CompositeResultData result = new CompositeResultData(); String header = "this space left blank"; result.setHeader(header); GfJsonObject json = result.getGfJsonObject(); assertThat(json.getString("header")).isEqualTo(header); assertThat(json.getString("content")).isEqualTo("{}"); }
@Test public void listGatewaysDisplaysGatewayReceiversWhenEmpty() { CompositeResultData crd = ResultBuilder.createCompositeResultData(); crd.setHeader(CliStrings.HEADER_GATEWAYS); doReturn(new String[0]).when(receiverMXBean).getConnectedGatewaySenders(); command.accumulateListGatewayResult(crd, Collections.EMPTY_MAP, receiverBeans); JSONObject tableContent = (JSONObject) crd.retrieveSectionByIndex(0).getSectionGfJsonObject() .get("__tables__-GatewayReceiver Table"); assertThat(tableContent.get("content").toString()).contains("[\"\"]"); }
public static CompositeResultData createCompositeResultData() { return new CompositeResultData(); }
crd.setHeader(CliStrings.HEADER_GATEWAYS); accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans); result = ResultBuilder.buildResult(crd);
@Test public void withSectionContainingRawData() { CompositeResultData result = new CompositeResultData(); CompositeResultData.SectionResultData section = result.addSection(); section.addData("my-data", "some random string"); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONObject("__sections__-0") .getString("my-data")).isEqualTo("some random string"); } }
legacyCrd.setHeader("Heads"); legacyCrd.setFooter("Tails"); TabularResultData table1 = legacyCrd.addSection().addTable(); table1.setHeader("section-0 table-1 header"); table1.accumulate("Parameter", "param1"); CompositeResultData.SectionResultData section1 = legacyCrd.addSection(); section1.setHeader("section 0 header"); section1.addSeparator('-'); CompositeResultData.SectionResultData section2 = legacyCrd.addSection("named-section"); section2.setHeader("named section header"); section2.addSeparator('-');
TabularResultData table1 = rebalanceResultData.addSection().addTable("Table" + index); String newLine = System.getProperty("line.separator"); StringBuilder resultStr = new StringBuilder();
@Test public void listGatewaysDisplaysGatewayReceiversWhenNull() { CompositeResultData crd = ResultBuilder.createCompositeResultData(); crd.setHeader(CliStrings.HEADER_GATEWAYS); doReturn(null).when(receiverMXBean).getConnectedGatewaySenders(); command.accumulateListGatewayResult(crd, Collections.EMPTY_MAP, receiverBeans); JSONObject tableContent = (JSONObject) crd.retrieveSectionByIndex(0).getSectionGfJsonObject() .get("__tables__-GatewayReceiver Table"); assertThat(tableContent.get("content").toString()).contains("[\"\"]"); } }
resultData = new ErrorResultData(data); } else if (ResultData.TYPE_COMPOSITE.equals(contentType)) { resultData = new CompositeResultData(data); } else { ErrorResultData errorResultData = new ErrorResultData();
@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("{}"); }
@Test public void withTableContainingData() { CompositeResultData result = new CompositeResultData(); CompositeResultData.SectionResultData section = result.addSection(); TabularResultData table = section.addTable(); table.accumulate("column1", 1); table.accumulate("column1", "abc"); table.accumulate("column1", 2); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONObject("__sections__-0") .getJSONObject("__tables__-0").getJSONObject("content").getString("column1")) .isEqualTo("[1,\"abc\",2]"); }
Map<String, GatewayReceiverMXBean> gatewayReceiverBeans) { if (!gatewaySenderBeans.isEmpty()) { TabularResultData gatewaySenderData = crd.addSection(CliStrings.SECTION_GATEWAY_SENDER) .addTable(CliStrings.TABLE_GATEWAY_SENDER).setHeader(CliStrings.HEADER_GATEWAY_SENDER); for (Map.Entry<String, Map<String, GatewaySenderMXBean>> entry : gatewaySenderBeans TabularResultData gatewayReceiverData = crd.addSection(CliStrings.SECTION_GATEWAY_RECEIVER) .addTable(CliStrings.TABLE_GATEWAY_RECEIVER) .setHeader(CliStrings.HEADER_GATEWAY_RECEIVER);
@Test public void listGatewaysDisplaysGatewaySendersAndReceivers() { CompositeResultData crd = ResultBuilder.createCompositeResultData(); crd.setHeader(CliStrings.HEADER_GATEWAYS); doReturn(new String[] {"10.118.19.31(server-ny-2:33256)<v2>:1029", "10.118.19.31(server-ny-1:33206)<v1>:1028"}).when(receiverMXBean) .getConnectedGatewaySenders(); command.accumulateListGatewayResult(crd, Collections.EMPTY_MAP, receiverBeans); JSONObject tableContent = (JSONObject) crd.retrieveSectionByIndex(0).getSectionGfJsonObject() .get("__tables__-GatewayReceiver Table"); assertThat(tableContent.get("content").toString()).contains( "[\"10.118.19.31(server-ny-2:33256)<v2>:1029, 10.118.19.31(server-ny-1:33206)<v1>:1028\"]"); }
&& StringUtils.isNotEmpty(((PartitionRebalanceInfo) iterator.next()).getRegionPath())) { final TabularResultData resultData = rebalanceResultData.addSection().addTable("Table" + index); String newLine = System.getProperty("line.separator"); StringBuilder resultStr = new StringBuilder();