@Test public void testSerializePdbInfoList() throws JAXBException { List<PdbInfo> pdbList = getPdbInfo(); StringWriter stringWriter = new StringWriter(); PrintWriter p = new PrintWriter(stringWriter); DataDownloadServlet d = new DataDownloadServlet(); d.serializePdbInfoList(pdbList, p, "xml"); String resultString = stringWriter.getBuffer().toString(); System.out.println(resultString); String expectedFirstLine = "<eppicAnalysisList><eppicAnalysis uid=\"9999\" jobId=\"1smt\" inputType=\"0\" inputName=\"1smt\">"; assertEquals("Wrong content", expectedFirstLine, resultString.split("\n")[0]); assertTrue("Result should contain pdb title", resultString.contains("SMTB REPRESSOR FROM SYNECHOCOCCUS PCC7942")); assertTrue("Result should contain the interface", resultString.contains("<operatorType>OP</operatorType>")); assertTrue("Result should contain the interface cluster", resultString.contains("<interfaceCluster>")); stringWriter = new StringWriter(); p = new PrintWriter(stringWriter); d = new DataDownloadServlet(); d.serializePdbInfoList(pdbList, p, "json"); resultString = stringWriter.getBuffer().toString(); System.out.println(resultString); expectedFirstLine = "{ \"uid\" : 9999, \"jobId\" : \"1smt\", \"inputType\" : 0, \"inputName\" : \"1smt\", "; assertEquals("Wrong content", expectedFirstLine, resultString.substring(0, resultString.lastIndexOf("\"pdbCode\" : \"1smt\"")).replaceAll("\n","").replaceAll("\\s+"," ")); assertTrue("Result should contain pdb title", resultString.contains("SMTB REPRESSOR FROM SYNECHOCOCCUS PCC7942")); assertTrue("Result should contain the interface", resultString.contains("\"operatorType\" : \"OP\"")); assertTrue("Result should contain the interface cluster", resultString.contains("\"interfaceCluster\"")); assertFalse(resultString.contains("NaN")); }
protected void serializePdbInfoList(List<PdbInfo> pdbList, PrintWriter writer, String format) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(PdbInfo.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); if (format.equals("xml")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); } else if (format.equals("json")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false); } if (format.equals("xml")) { writer.append("<eppicAnalysisList>"); } for(PdbInfo pdb:pdbList){ jaxbMarshaller.marshal(pdb, writer); } if (format.equals("xml")) { writer.append("</eppicAnalysisList>"); } }
DataDownloadServlet extends BaseServlet { protected void serializePdbInfoList(List<PdbInfo> pdbList, PrintWriter writer, String format) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(PdbInfo.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); if (format.equals("xml")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); } else if (format.equals("json")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false); } if (format.equals("xml")) { writer.append("<eppicAnalysisList>"); } for(PdbInfo pdb:pdbList){ jaxbMarshaller.marshal(pdb, writer); } if (format.equals("xml")) { writer.append("</eppicAnalysisList>"); } } }
DataDownloadServlet extends BaseServlet { protected void serializePdbInfoList(List<PdbInfo> pdbList, PrintWriter writer, String format) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(PdbInfo.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); if (format.equals("xml")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); } else if (format.equals("json")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false); } if (format.equals("xml")) { writer.append("<eppicAnalysisList>"); } for(PdbInfo pdb:pdbList){ jaxbMarshaller.marshal(pdb, writer); } if (format.equals("xml")) { writer.append("</eppicAnalysisList>"); } }  }
DataDownloadServlet extends BaseServlet { protected void serializePdbInfoList(List<PdbInfo> pdbList, PrintWriter writer, String format) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(PdbInfo.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); if (format.equals("xml")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); } else if (format.equals("json")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false); } if (format.equals("xml")) { writer.append("<eppicAnalysisList>"); } for(PdbInfo pdb:pdbList){ jaxbMarshaller.marshal(pdb, writer); } if (format.equals("xml")) { writer.append("</eppicAnalysisList>"); } }  @Override void init(ServletConfig config); static PdbInfo getResultData(String jobId,
								  Set<Integer> interfaceClusterIdList,
								  Set<Integer> interfaceIdList,
								  Set<Integer> assemblyIdList,
								  boolean getSeqInfo,
								  boolean getResInfo); }
DataDownloadServlet extends BaseServlet { protected void serializePdbInfoList(List<PdbInfo> pdbList, PrintWriter writer, String format) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(PdbInfo.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); if (format.equals("xml")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); } else if (format.equals("json")) { jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false); } if (format.equals("xml")) { writer.append("<eppicAnalysisList>"); } for(PdbInfo pdb:pdbList){ jaxbMarshaller.marshal(pdb, writer); } if (format.equals("xml")) { writer.append("</eppicAnalysisList>"); } }  @Override void init(ServletConfig config); static PdbInfo getResultData(String jobId,
								  Set<Integer> interfaceClusterIdList,
								  Set<Integer> interfaceIdList,
								  Set<Integer> assemblyIdList,
								  boolean getSeqInfo,
								  boolean getResInfo); static final String SERVLET_NAME; }