WorkflowBundleIO { public void writeBundle(WorkflowBundle wfBundle, File destination, String mediaType) throws WriterException, IOException { WorkflowBundleWriter writer = getWriterForMediaType(mediaType); if (writer == null) throw new IllegalArgumentException( "Could not find writer for media type " + mediaType); scufl2Tools.setParents(wfBundle); writer.writeBundle(wfBundle, destination, mediaType); }  WorkflowBundleReader getReaderForMediaType(String mediaType); List<WorkflowBundleReader> getReaders(); Set<String> getSupportedReaderMediaTypes(); Set<String> getSupportedWriterMediaTypes(); WorkflowBundleWriter getWriterForMediaType(String mediaType); List<WorkflowBundleWriter> getWriters(); String guessMediaTypeForSignature(byte[] firstBytes); WorkflowBundle readBundle(File bundleFile, String mediaType); WorkflowBundle readBundle(InputStream inputStream, String mediaType); WorkflowBundle readBundle(URL url, String mediaType); void setReaders(List<WorkflowBundleReader> readers); void setWriters(List<WorkflowBundleWriter> writers); void writeBundle(WorkflowBundle wfBundle, File destination,
			String mediaType); void writeBundle(WorkflowBundle wfBundle, OutputStream output,
			String mediaType); WorkflowBundle createBundle();  }
@Test public void writeBundleFile() throws Exception { File bundleFile = tempFile(); bundleIO.writeBundle(wfBundle, bundleFile, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); String bundleTxt = FileUtils.readFileToString(bundleFile, UTF_8); String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle(); bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", ""); getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", ""); assertEquals(getStructureFormatWorkflowBundle, bundleTxt); }
@Ignore @Test public void writeBundleFileSetParents() throws Exception { File bundleFile = tempFile(); Profile profile = wfBundle.getProfiles().getByName("tavernaWorkbench"); profile.setParent(null); wfBundle.getProfiles().add(profile); processor.setParent(null); workflow.getProcessors().add(processor); assertNull(processor.getParent()); assertNull(profile.getParent()); bundleIO.writeBundle(wfBundle, bundleFile, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); assertNotNull(processor.getParent()); assertNotNull(profile.getParent()); String bundleTxt = FileUtils.readFileToString(bundleFile, UTF_8); assertTrue(bundleTxt.contains("Processor 'Hello'")); assertTrue(bundleTxt.contains("Profile 'tavernaWorkbench'")); }
@Test public void writeBundleStream() throws Exception { ByteArrayOutputStream output = new ByteArrayOutputStream(); bundleIO.writeBundle(wfBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); String bundleTxt = new String(output.toByteArray(), UTF_8); String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle(); bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", ""); getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", ""); assertEquals(getStructureFormatWorkflowBundle, bundleTxt); }
@Test(expected = IllegalArgumentException.class) public void writeBundleUnknownMediaType() throws Exception { File bundleFile = tempFile(); bundleIO.writeBundle(wfBundle, bundleFile, "application/vnd.example.unknownStuff"); }
@Test(expected = IOException.class) public void writeBundleWrongLocation() throws Exception { File bundleDir = tempFile(); bundleDir.delete(); File bundleFile = new File(bundleDir, "nonExistingDir"); bundleIO.writeBundle(wfBundle, bundleFile, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); }