/** * Convenience method to create a simple Info Result that takes a message. * * @param message Message for the OK Result */ public static Result createInfoResult(String message) { InfoResultData infoResultData = new InfoResultData(); infoResultData.addLine(message); return buildResult(infoResultData); }
/** * * @return this InfoResultData */ @Override public ErrorResultData setFooter(String footerText) { return (ErrorResultData) super.setFooter(footerText); }
/** * * @return this ErrorResultData */ @Override public ErrorResultData setHeader(String headerText) { return (ErrorResultData) super.setHeader(headerText); }
@Test public void infoResultDataStructure() { InfoResultData result = ResultBuilder.createInfoResultData(); result.addLine("line 1"); result.addLine("line 2"); result.setHeader("Heads"); result.setFooter("Tails"); CommandResult cmdResult = ResultBuilder.buildResult(result); assertThat(cmdResult.getHeader()).isEqualTo("Heads"); assertThat(cmdResult.getListFromContent("message")).contains("line 1", "line 2"); assertThat(cmdResult.getFooter()).isEqualTo("Tails"); assertThat(cmdResult.getValueFromContent("message")).isNotEmpty(); assertThat(cmdResult.getStatus()).isEqualTo(Result.Status.OK); }
@Test public void infoWithMultipleContentLines() { InfoResultData result = new InfoResultData("some content"); result.addLine("another line of content"); assertThat(result.getGfJsonObject().getJSONObject("content").getString("message")) .isEqualTo("[\"some content\",\"another line of content\"]"); }
@Test public void infoWithFile() throws Exception { InfoResultData result = new InfoResultData("some content"); ResultData data = result.addAsFile("content.zip", "file contents", "a message", false); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONArray("__bytes__") .getJSONObject(0).getString("fileName")).isEqualTo("content.zip"); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONArray("__bytes__") .getJSONObject(0).getString("fileType")).isEqualTo("1"); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONArray("__bytes__") .getJSONObject(0).getString("fileMessage")).isEqualTo("a message"); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONArray("__bytes__") .getJSONObject(0).getString("fileData").length()).isGreaterThan(0); } }
public InfoResultData(String message) { this(); addLine(message); }
/** * Creates a {@link InfoResultData} object to start building result that is required to be shown * as an information without any specific format. * * @return InfoResultData instance */ public static InfoResultData createInfoResultData() { return new InfoResultData(); }
@Test public void emptyInfo() { InfoResultData result = new InfoResultData(); assertThat(result.getGfJsonObject().getString("content")).isEqualTo("{}"); }
/** * * @param line message to add * @return this ErrorResultData */ @Override public ErrorResultData addLine(String line) { return (ErrorResultData) super.addLine(line); }
public LegacyCommandResult(Path fileToDownload) { this(new InfoResultData(fileToDownload.toString())); this.fileToDownload = fileToDownload.toAbsolutePath(); }
@Test public void infoWithContent() { InfoResultData result = new InfoResultData("some content"); assertThat(result.getGfJsonObject().getJSONObject("content").getString("message")) .isEqualTo("[\"some content\"]"); }
@Test public void resultWithTwoLinesHasTwoLines() { InfoResultData resultData = new InfoResultData(); resultData.addLine("lineOne"); resultData.addLine("lineTwo"); CommandResult commandResult = new LegacyCommandResult(resultData); assertThat(commandResult.nextLine()) .isEqualTo("lineOne" + LINE_SEPARATOR + "lineTwo" + LINE_SEPARATOR); assertThat(commandResult.hasNextLine()).isFalse(); }
infoResultData.addLine(lineRead);
@Test public void emptyResultDoesNotHaveFileToDownload() { CommandResult commandResult = new LegacyCommandResult(new InfoResultData()); Assertions.assertThat(commandResult.hasFileToDownload()).isFalse(); }
@Test public void emptyResultHasOneEmptyLine() { CommandResult commandResult = new LegacyCommandResult(new InfoResultData()); Assertions.assertThat(commandResult.nextLine()).isEqualTo(""); Assertions.assertThat(commandResult.hasNextLine()).isFalse(); }
@Test public void resultWithOneLineHasOneLine() { CommandResult commandResult = new LegacyCommandResult(new InfoResultData("oneLine")); assertThat(commandResult.nextLine()).isEqualTo("oneLine" + LINE_SEPARATOR); assertThat(commandResult.hasNextLine()).isFalse(); }