@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("[\"\"]"); } }
@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("[\"\"]"); }
@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\"]"); }
@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("{}"); }
public SectionResultData addSection(SectionResultData otherSection) { String keyToAccess = String.valueOf(subsectionCount); GfJsonObject sectionData = otherSection.getSectionGfJsonObject(); try { contentObject.putAsJSONObject(SectionResultData.generateSectionKey(keyToAccess), sectionData); } catch (GfJsonException e) { throw new ResultDataException(e.getMessage()); } subsectionCount++; return new SectionResultData(sectionData); }