T2FlowReader implements WorkflowBundleReader { @Override public WorkflowBundle readBundle(File bundleFile, String mediaType) throws ReaderException, IOException { try { WorkflowBundle bundle = getParser().parseT2Flow(bundleFile); scufl2Tools.setParents(bundle); preserveOriginal(bundle, new FileInputStream(bundleFile)); return bundle; } catch (JAXBException e) { if (e.getCause() instanceof IOException) { IOException ioException = (IOException) e.getCause(); throw ioException; } throw new ReaderException("Can't parse t2flow " + bundleFile, e); } }  @Override Set<String> getMediaTypes(); @Override WorkflowBundle readBundle(File bundleFile, String mediaType); @Override WorkflowBundle readBundle(InputStream inputStream, String mediaType); void setParser(T2FlowParser parser); T2FlowParser getParser(); @Override String guessMediaTypeForSignature(byte[] firstBytes); static final String APPLICATION_VND_TAVERNA_T2FLOW_XML; }
@Test public void readSimpleWorkflow() throws Exception { URL wfResource = getClass().getResource(AS_T2FLOW); assertNotNull("Could not find workflow " + AS_T2FLOW, wfResource); WorkflowBundle wfBundle = io.readBundle(wfResource, APPLICATION_VND_TAVERNA_T2FLOW_XML); Profile profile = wfBundle.getMainProfile(); assertEquals(1, wfBundle.getProfiles().size()); assertEquals(profile, wfBundle.getProfiles().getByName("taverna-2.1.0")); String report = IOUtils.toString(getClass().getResourceAsStream("/as.txt")); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); io.writeBundle(wfBundle, byteStream, StructureReader.TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); String byteStreamTtoString = byteStream.toString("utf-8"); report = report.replaceAll("\r", "").replaceAll("\n", ""); byteStreamTtoString = byteStreamTtoString.replaceAll("\r", "").replaceAll("\n", ""); assertEquals(report, byteStreamTtoString); }
@Test public void preservedOriginalT2flow() throws Exception { URL wfResource = getClass().getResource(AS_T2FLOW); assertNotNull("Could not find workflow " + AS_T2FLOW, wfResource); WorkflowBundle wfBundle = io.readBundle(wfResource, APPLICATION_VND_TAVERNA_T2FLOW_XML); Map<String, ResourceEntry> history = wfBundle.getResources() .listResources("history"); assertEquals(1, history.size()); assertEquals(AS_UUID + ".t2flow", history.keySet().iterator().next()); ResourceEntry r = history.get(AS_UUID + ".t2flow"); assertEquals("application/vnd.taverna.t2flow+xml", r.getMediaType()); String original = IOUtils.toString(getClass().getResourceAsStream( AS_T2FLOW)); String shouldBeOriginal = wfBundle.getResources().getResourceAsString( "history/" + AS_UUID + ".t2flow"); assertEquals(shouldBeOriginal, original); }