@Test public void formatInteractionResult() throws IOException { String result = "{ \"columns\" : [ \"source_taxon_external_id\", \"source_taxon_name\", \"source_taxon_path\", \"interaction_type\", \"target_taxon_external_id\", \"target_taxon_name\", \"target_taxon_path\" ], " + "\"data\" : " + "[[ \"EOL:917146\", \"Todus mexicanus\", \"Animalia Chordata Aves Coraciiformes Todidae Todus\", \"ATE\", \"EOL:345\", \"Coleoptera\", \"Animalia Arthropoda Insecta\" ], " + "[ \"EOL:1024936\", \"Otus nudipes\", \"Animalia Chordata Aves Strigiformes Strigidae Megascops\", \"ATE\", \"EOL:421\", \"Diptera\", \"Animalia Arthropoda Insecta\" ], " + "[ \"EOL:13798\", \"Anolis gundlachi\", \"Animalia Chordata Reptilia Squamata Polychrotidae Anolis\", \"ATE\", \"EOL:4938647\", \"Stylomatophora\", \"Metazoa Eumetazoa Triploblastica Nephrozoa Protostomia Spiralia Trochozoa Eutrochozoa Mollusca Gastropoda Streptoneura\" ]]}"; ObjectMapper mapper = new ObjectMapper(); String format = new ResultFormatterJSONv2().format(result); JsonNode jsonNode = mapper.readTree(format); assertThat(jsonNode.isArray(), is(true)); int count = 0; for (JsonNode interaction : jsonNode) { assertThat(interaction.get("type").getTextValue(), is("ATE")); JsonNode taxon = assertNodePropertiesExist(interaction, "source"); if (count == 0) { assertThat(taxon.get("name").getTextValue(), is("Todus mexicanus")); assertThat(taxon.get("path").getTextValue(), is("Animalia Chordata Aves Coraciiformes Todidae Todus")); assertThat(taxon.get("id").getTextValue(), is("EOL:917146")); } taxon = assertNodePropertiesExist(interaction, "target"); if (count == 0) { assertThat(taxon.get("name").getTextValue(), is("Coleoptera")); assertThat(taxon.get("path").getTextValue(), is("Animalia Arthropoda Insecta")); assertThat(taxon.get("id").getTextValue(), is("EOL:345")); } assertThat(interaction.has("source"), is(true)); if (count == 0) { assertThat(interaction.get("source_taxon_name").asText(), is("Todus mexicanus")); assertThat(interaction.get("source_taxon_path").asText(), is("Animalia Chordata Aves Coraciiformes Todidae Todus")); assertThat(interaction.get("source_taxon_external_id").asText(), is("EOL:917146")); } if (count == 0) { assertThat(interaction.get("target_taxon_name").asText(), is("Coleoptera")); assertThat(interaction.get("target_taxon_path").asText(), is("Animalia Arthropoda Insecta")); assertThat(interaction.get("target_taxon_external_id").asText(), is("EOL:345")); } count++; } }
@Override public String format(String result) throws ResultFormattingException { try { JsonNode jsonNode = RequestHelper.parse(result); return format(jsonNode); } catch (IOException e) { throw new ResultFormattingException("failed to format result", e); } }
ResultFormatterJSONv2 implements ResultFormatter { @Override public String format(String result) throws ResultFormattingException { try { JsonNode jsonNode = RequestHelper.parse(result); return format(jsonNode); } catch (IOException e) { throw new ResultFormattingException("failed to format result", e); } } }
ResultFormatterJSONv2 implements ResultFormatter { @Override public String format(String result) throws ResultFormattingException { try { JsonNode jsonNode = RequestHelper.parse(result); return format(jsonNode); } catch (IOException e) { throw new ResultFormattingException("failed to format result", e); } }  }
ResultFormatterJSONv2 implements ResultFormatter { @Override public String format(String result) throws ResultFormattingException { try { JsonNode jsonNode = RequestHelper.parse(result); return format(jsonNode); } catch (IOException e) { throw new ResultFormattingException("failed to format result", e); } }  @Override String format(String result); }
ResultFormatterJSONv2 implements ResultFormatter { @Override public String format(String result) throws ResultFormattingException { try { JsonNode jsonNode = RequestHelper.parse(result); return format(jsonNode); } catch (IOException e) { throw new ResultFormattingException("failed to format result", e); } }  @Override String format(String result);  }