JsonResultsWriter implements ResultsWriter { @Override public String writeString(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings) { ObjectWriter objectWriter = new ObjectMapper().writerWithDefaultPrettyPrinter(); try (Writer stringWriter = new StringWriter()) { writeData(modeOfInheritance, analysisResults, settings.outputContributingVariantsOnly(), objectWriter, stringWriter); stringWriter.flush(); logger.info("{} {} results written to string", OUTPUT_FORMAT, (modeOfInheritance.getAbbreviation() == null) ? "ALL" : modeOfInheritance .getAbbreviation()); return stringWriter.toString(); } catch (IOException ex) { logger.error("Unable to write results to json.", ex); } return ""; }  @Override void writeFile(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings); @Override String writeString(ModeOfInheritance modeOfInheritance, Analysis analysis, AnalysisResults analysisResults, OutputSettings settings);  }
@Test public void writeToStringPassOnlyAutosomalDominant() throws Exception { Analysis analysis = this.analysisBuilder.analysisMode(AnalysisMode.PASS_ONLY).build(); AnalysisResults analysisResults = this.analysisResultsBuilder.build(); OutputSettings outputSettings = this.settingsBuilder.outputContributingVariantsOnly(true).build(); JsonResultsWriter instance = new JsonResultsWriter(); String result = instance.writeString(ModeOfInheritance.AUTOSOMAL_DOMINANT, analysis, analysisResults, outputSettings); String expected = readFromFile("src/test/resources/writers/contributing_only_autosomal_dominant_moi_test.json"); JSONAssert.assertEquals(expected, result, true); }
@Test public void writeToStringPassOnlyAnyModeOfInheritance() throws Exception { Analysis analysis = this.analysisBuilder.analysisMode(AnalysisMode.PASS_ONLY).build(); AnalysisResults analysisResults = this.analysisResultsBuilder.build(); OutputSettings outputSettings = this.settingsBuilder.outputContributingVariantsOnly(true).build(); JsonResultsWriter instance = new JsonResultsWriter(); String result = instance.writeString(ModeOfInheritance.ANY, analysis, analysisResults, outputSettings); String expected = readFromFile("src/test/resources/writers/contributing_only_any_moi_test.json"); JSONAssert.assertEquals(expected, result, true); }
@Test public void writeToStringFullAnalysisAnyModeOfInheritanceAllVariants() throws Exception { Analysis analysis = this.analysisBuilder.analysisMode(AnalysisMode.FULL).build(); AnalysisResults analysisResults = this.analysisResultsBuilder.build(); OutputSettings outputSettings = this.settingsBuilder.outputContributingVariantsOnly(false).build(); JsonResultsWriter instance = new JsonResultsWriter(); String result = instance.writeString(ModeOfInheritance.ANY, analysis, analysisResults, outputSettings); String expected = readFromFile("src/test/resources/writers/full_any_moi_test.json"); JSONAssert.assertEquals(expected, result, true); }
@Test public void writeToStringFullAnalysisNoModeOfInheritanceMatchAllVariants() throws Exception { Analysis analysis = this.analysisBuilder.analysisMode(AnalysisMode.FULL).build(); AnalysisResults analysisResults = this.analysisResultsBuilder.build(); OutputSettings outputSettings = this.settingsBuilder.outputContributingVariantsOnly(false).build(); JsonResultsWriter instance = new JsonResultsWriter(); String result = instance.writeString(ModeOfInheritance.MITOCHONDRIAL, analysis, analysisResults, outputSettings); String expected = "[]"; JSONAssert.assertEquals(expected, result, true); }
@Test public void writeToStringFullAnalysisAnyModeOfInheritancePassOnlyVariants() throws Exception { Analysis analysis = this.analysisBuilder.analysisMode(AnalysisMode.FULL).build(); AnalysisResults analysisResults = this.analysisResultsBuilder.build(); OutputSettings outputSettings = this.settingsBuilder.outputContributingVariantsOnly(true).build(); JsonResultsWriter instance = new JsonResultsWriter(); String result = instance.writeString(ModeOfInheritance.ANY, analysis, analysisResults, outputSettings); String expected = readFromFile("src/test/resources/writers/contributing_only_any_moi_test.json"); JSONAssert.assertEquals(expected, result, true); }