CatResult extends JestResult { public String[][] getPlainText() { JsonObject jsonObject = getJsonObject(); if (jsonObject != null && getPathToResult() != null && jsonObject.has(getPathToResult()) && jsonObject.get(getPathToResult()).isJsonArray()) { JsonArray esResultRows = jsonObject.get(getPathToResult()).getAsJsonArray(); if(esResultRows.size() > 0 && esResultRows.get(0).isJsonObject()) { return parseResultArray(esResultRows); } } return new String[0][0]; } CatResult(CatResult catResult);  CatResult(Gson gson); String[][] getPlainText();  }
@Test public void shouldReturnEmptyArrayOnNoJsonObject() { CatResult catResult = new CatResult(new Gson()); assertArrayEquals(new String[0][0], catResult.getPlainText()); }
@Test public void shouldReturnArrayWithColumnNamesAndSingleResult() { Cat cat = new Cat.IndicesBuilder().build(); String reasonPhase = ""; CatResult catResult = cat.createNewElasticSearchResult(EXAMPLE_RESPONSE_SINGLE_ROWS, 200, reasonPhase, new Gson()); assertArrayEquals(new String[][]{ new String[]{"alias", "index", "filter"}, new String[]{"testAlias", "testIndex", "-"} }, catResult.getPlainText()); }
@Test public void shouldReturnArrayWithTwoResultsEventWhenColumnsWereReordered() { Cat cat = new Cat.IndicesBuilder().build(); String reasonPhase = ""; CatResult catResult = cat.createNewElasticSearchResult(EXAMPLE_RESPONSE_TWO_ROWS, 200, reasonPhase, new Gson()); assertArrayEquals(new String[][]{ new String[]{"alias", "index", "filter"}, new String[]{"testAlias", "testIndex", "-"}, new String[]{"testAlias2", "testIndex2", "-"} }, catResult.getPlainText()); }