private void buildData() { try { if (resultData.getType() == ResultData.TYPE_OBJECT) { buildObjectResultOutput(); } else if (resultData.getType() == ResultData.TYPE_COMPOSITE) { buildComposite(); } else { GfJsonObject content = getContent(); if (content != null) { Table resultTable = TableBuilder.newTable(); addHeaderInTable(resultTable, getGfJsonObject()); buildTable(rowGroup, content); } else { buildInfoErrorData(rowGroup, content); addFooterInTable(resultTable, getGfJsonObject());
public static CommandResponse prepareCommandResponse(String memberName, CommandResult result) { GfJsonObject content = null; try { content = result.getContent(); } catch (GfJsonException e) { try { content = new GfJsonObject(e.getMessage()); } catch (GfJsonException e1) { content = new GfJsonObject(); } } return new CommandResponse(memberName, // sender getType(result), // contentType result.getStatus().getCode(), // status code "1/1", // page --- TODO - Abhishek - define a scrollable ResultData NO_TOKEN_ACCESSOR, // tokenAccessor for next results getDebugInfo(result), // debugData result.getHeader(), // header content, // content result.getFooter(), // footer result.failedToPersist()); // failed to persist }
public static SectionResultData extractArgumentsForNextStep(Result result) { CommandResult cResult = (CommandResult) result; if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) { CompositeResultData rd = (CompositeResultData) cResult.getResultData(); SectionResultData data = rd.retrieveSection(CLIMultiStepHelper.ARG_SECTION); return data; } else { if (ResultData.TYPE_ERROR.equals(cResult.getType())) { throw new CLIStepExecption(cResult); } else { throw new StepExecutionException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType()); } } }
protected String commandResultToString(final CommandResult commandResult) { assertNotNull(commandResult); commandResult.resetToFirstLine(); StringBuilder buffer = new StringBuilder(commandResult.getHeader()); while (commandResult.hasNextLine()) { buffer.append(commandResult.nextLine()); } buffer.append(commandResult.getFooter()); return buffer.toString(); }
private static String[] getPresentationString(TestableGfsh shell) { Map<String, Object> result = shell.getCommandOutput(); StringBuffer presentationStr = new StringBuffer(); StringBuffer errStr = new StringBuffer(); for (Object key: result.keySet()) { Object value = result.get(key); // Log.getLogWriter().info("key class is " + key.getClass().getName() + ", key is " + key + " value is class " + // value.getClass().getName() + ", value is " + value + "\n"); if (value instanceof CommandResult) { CommandResult cr = (CommandResult)value; cr.resetToFirstLine(); while (cr.hasNextLine()) { String line = cr.nextLine(); presentationStr.append(line).append("\n"); //errStr.append(checkForRightPadding(line)); } } } return new String[] {presentationStr.toString(), errStr.toString()}; }
Log.getLogWriter().info( "testCreateGatewayReceiver stringResult : " + strCmdResult + ">>>>"); assertEquals(Result.Status.OK, cmdResult.getStatus()); .getResultData(); List<String> status = resultData.retrieveAllValues("Status"); assertEquals(4, status.size());// expected size 4 includes the manager
public void testGCForGroup() { Properties localProps = new Properties(); localProps.setProperty(DistributionConfig.NAME_NAME, "Manager"); localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group1"); createDefaultSetup(localProps); String command = "gc --group=Group1"; CommandResult cmdResult = executeCommand(command); cmdResult.resetToFirstLine(); if (cmdResult != null) { String cmdResultStr = commandResultToString(cmdResult); getLogWriter().info("testGCForGroup cmdResultStr=" + cmdResultStr); assertEquals(Result.Status.OK, cmdResult.getStatus()); if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) { TabularResultData table = (TabularResultData) cmdResult.getResultData(); List<String> memberNames = table .retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME); assertEquals(true, memberNames.size() == 1 ? true : false); } else { fail("testGCForGroup failed as CommandResult should be table type"); } } else { fail("testGCForGroup failed as did not get CommandResult"); } }
public CommandOutputValidatorResult validate() { CommandOutputValidatorResult validationResult = new CommandOutputValidatorResult(); validationResult.command = this.command; validationResult.result = true; List<String> stringerrors = stringValidator.validate(presentationStr); if(stringerrors.size()>0){ validationResult.result = false; validationResult.errorStrings.addAll(stringerrors); } // checkStrings(errorStringPatterns, validationResult, false); // checkStrings(stringPatterns, validationResult, true); if(!result.getStatus().equals(Result.Status.OK)){ validationResult.result = false; validationResult.errorStrings.add("Result status is not OK : " + result.getStatus()); } return validationResult; }
if (cmdResult.hasIncomingFiles()) { boolean isAlreadySaved = cmdResult.getNumTimesSaved() > 0; if (!isAlreadySaved) { cmdResult.saveIncomingFiles(null);
resultTable.setColumnSeparator(" : "); addHeaderInTable(resultTable, getGfJsonObject()); GfJsonObject content = getContent(); buildObjectSection(resultTable, null, object, 0); addFooterInTable(resultTable, getGfJsonObject());
/*private*/ void buildComposite() { try { GfJsonObject content = getContent(); if (content != null) { Table resultTable = TableBuilder.newTable(); resultTable.setColumnSeparator(" : "); addHeaderInTable(resultTable, getGfJsonObject()); if (key.startsWith(CompositeResultData.SECTION_DATA_ACCESSOR)) { GfJsonObject subSection = content.getJSONObject(key); buildSection(resultTable, null, subSection, 0); } else if (key.equals(CompositeResultData.SEPARATOR)) { String separatorString = content.getString(key); addFooterInTable(resultTable, getGfJsonObject()); resultLines.addAll(resultTable.buildTableList());
private static boolean hasResultObject(TestableGfsh shell) { for (Object value: shell.getCommandOutput().values()) { if (value instanceof CommandResult) { CommandResult cr = (CommandResult) value; try { Log.getLogWriter().info("TestableGfsh saw ResultObject as follows: " + cr.getContent().toString()); Log.getLogWriter().info(" size: " + cr.getContent().size()); Log.getLogWriter().info(" toString: " + cr.getContent().toString()); Log.getLogWriter().info(" class: " + cr.getContent().getClass().getName()); if(cr.getContent().size()==0) { return false; } else { StringBuffer checkForOutput = new StringBuffer(); while (cr.hasNextLine()) { String line = cr.nextLine(); checkForOutput.append(line); } String tmpStr = checkForOutput.toString(); if(tmpStr.trim().length() == 0) { return false; } else { return true; } } } catch(Exception ex) {} return true; } } return false; }
CommandResult commandResult = CLIMultiStepHelper.getDisplayResultFromArgs(args); Gfsh.println(); while (commandResult.hasNextLine()) { Gfsh.println(commandResult.nextLine());
private static String handleCommandResult(CommandResult object) { StringBuilder sb = new StringBuilder(); sb.append(" Status : " + object.getStatus()).append(NEW_LINE); try { sb.append(" Raw JSON : " + object.getContent().toIndentedString(5)); sb.append(NEW_LINE); } catch (GfJsonException e) { sb.append(" Error getting raw JSON : " + e.getMessage()); logError(" Error getting raw JSON : ", e); } return sb.toString(); }
public String getHeader() { return getHeader(gfJsonObject); }
public String getFooter() { return getFooter(gfJsonObject); }
public void saveIncomingFiles(String directory) throws IOException { // dump file data if any try { GfJsonObject content = getContent(); if (content != null) { GfJsonArray bytesArray = content.getJSONArray(CompositeResultData.BYTE_DATA_ACCESSOR); AbstractResultData.readFileDataAndDump(bytesArray, directory); } else { throw new RuntimeException("No associated files to save .. "); // TODO Abhishek - add i18n string } numTimesSaved = numTimesSaved + 1; } catch (DataFormatException e) { throw new RuntimeException(e); } catch (GfJsonException e) { throw new RuntimeException(e); } }
private static String getType(CommandResult result) { return result.getType(); }
.getResultData(); List<String> status = resultData.retrieveAllValues("Result"); assertEquals(4, status.size());
Log.getLogWriter().info( "testCreateGatewayReceiver stringResult : " + strCmdResult + ">>>>"); assertEquals(Result.Status.OK, cmdResult.getStatus()); .getResultData(); List<String> status = resultData.retrieveAllValues("Status"); assertEquals(4, status.size());//expected size 4 includes the manager node