WorkflowTraceSerializer { public static void write(File file, WorkflowTrace trace) throws FileNotFoundException, JAXBException, IOException { FileOutputStream fos = new FileOutputStream(file); WorkflowTraceSerializer.write(fos, trace); } private  WorkflowTraceSerializer(); static void write(File file, WorkflowTrace trace); static String write(WorkflowTrace trace); static void write(OutputStream outputStream, WorkflowTrace workflowTrace); static WorkflowTrace read(InputStream inputStream); static List<WorkflowTrace> readFolder(File f);  }
@Test public void testWrite() { try { WorkflowTrace trace = new WorkflowTrace(); action = new SendAction(new ClientHelloMessage(config)); trace.addTlsAction(action); File f = folder.newFile(); WorkflowTraceSerializer.write(f, trace); Assert.assertTrue(f.exists()); } catch (JAXBException | IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); Assert.fail(); } }
@Test public void serializeWithSingleConnectionTest() { try { WorkflowTrace trace = new WorkflowTrace(); action = new SendAction(new ClientHelloMessage(config)); trace.addTlsAction(action); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<workflowTrace>"); pw.println(" <Send>"); pw.println(" <messages>"); pw.println(" <ClientHello>"); pw.println(" <extensions>"); pw.println(" <ECPointFormat/>"); pw.println(" <EllipticCurves/>"); pw.println(" <SignatureAndHashAlgorithmsExtension/>"); pw.println(" <RenegotiationInfoExtension/>"); pw.println(" </extensions>"); pw.println(" </ClientHello>"); pw.println(" </messages>"); pw.println(" </Send>"); pw.println("</workflowTrace>"); pw.close(); String expected = sw.toString(); DefaultNormalizeFilter.normalizeAndFilter(trace, config); String actual = WorkflowTraceSerializer.write(trace); LOGGER.info(actual); Assert.assertEquals(actual, expected); } catch (JAXBException | IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); Assert.fail(); } }
@Test public void serializeWithSingleCustomConnectionTest() { try { WorkflowTrace trace = new WorkflowTrace(); AliasedConnection con = new OutboundConnection("theAlias", 1111, "host1111"); trace.addConnection(con); action = new SendAction(new ClientHelloMessage(config)); action.setConnectionAlias(con.getAlias()); trace.addTlsAction(action); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<workflowTrace>"); pw.println(" <OutboundConnection>"); pw.println(" <alias>theAlias</alias>"); pw.println(" <port>1111</port>"); pw.println(" <hostname>host1111</hostname>"); pw.println(" </OutboundConnection>"); pw.println(" <Send>"); pw.println(" <messages>"); pw.println(" <ClientHello>"); pw.println(" <extensions>"); pw.println(" <ECPointFormat/>"); pw.println(" <EllipticCurves/>"); pw.println(" <SignatureAndHashAlgorithmsExtension/>"); pw.println(" <RenegotiationInfoExtension/>"); pw.println(" </extensions>"); pw.println(" </ClientHello>"); pw.println(" </messages>"); pw.println(" </Send>"); pw.println("</workflowTrace>"); pw.close(); String expected = sw.toString(); DefaultNormalizeFilter.normalizeAndFilter(trace, config); String actual = WorkflowTraceSerializer.write(trace); Assert.assertEquals(expected, actual); } catch (JAXBException | IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); Assert.fail(); } }
@Test public void serializeWithMultipleCustomConnectionTest() { try { WorkflowTrace trace = new WorkflowTrace(); AliasedConnection con1 = new OutboundConnection("alias1", 1111, "host1111"); AliasedConnection con2 = new OutboundConnection("alias2", 1122, "host2222"); AliasedConnection con3 = new InboundConnection("alias3", 1313); trace.addConnection(con1); trace.addConnection(con2); trace.addConnection(con3); action = new SendAction(con3.getAlias(), new ClientHelloMessage(config)); trace.addTlsAction(action); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<workflowTrace>"); pw.println(" <OutboundConnection>"); pw.println(" <alias>alias1</alias>"); pw.println(" <port>1111</port>"); pw.println(" <hostname>host1111</hostname>"); pw.println(" </OutboundConnection>"); pw.println(" <OutboundConnection>"); pw.println(" <alias>alias2</alias>"); pw.println(" <port>1122</port>"); pw.println(" <hostname>host2222</hostname>"); pw.println(" </OutboundConnection>"); pw.println(" <InboundConnection>"); pw.println(" <alias>alias3</alias>"); pw.println(" <port>1313</port>"); pw.println(" </InboundConnection>"); pw.println(" <Send>"); pw.println(" <connectionAlias>alias3</connectionAlias>"); pw.println(" <messages>"); pw.println(" <ClientHello>"); pw.println(" <extensions>"); pw.println(" <ECPointFormat/>"); pw.println(" <EllipticCurves/>"); pw.println(" <SignatureAndHashAlgorithmsExtension/>"); pw.println(" <RenegotiationInfoExtension/>"); pw.println(" </extensions>"); pw.println(" </ClientHello>"); pw.println(" </messages>"); pw.println(" </Send>"); pw.println("</workflowTrace>"); pw.close(); String expected = sw.toString(); DefaultNormalizeFilter.normalizeAndFilter(trace, config); String actual = WorkflowTraceSerializer.write(trace); Assert.assertEquals(expected, actual); } catch (JAXBException | IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); Assert.fail(); } }