package uk.org.taverna.scufl2.rdfxml;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static uk.org.taverna.scufl2.api.io.structure.StructureReader.TEXT_VND_TAVERNA_SCUFL2_STRUCTURE;

import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.output.ByteArrayOutputStream;
import org.junit.Before;
import org.junit.Test;

import uk.org.taverna.scufl2.api.container.WorkflowBundle;
import uk.org.taverna.scufl2.api.io.ReaderException;
import uk.org.taverna.scufl2.api.io.WorkflowBundleIO;

public class TestRDFXMLReader {
	
	private URL exampleBundle;
	public static final String APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE = "application/vnd.taverna.scufl2.workflow-bundle";
	protected WorkflowBundle workflowBundle;
	protected WorkflowBundleIO bundleIO = new WorkflowBundleIO();
	uk.org.taverna.scufl2.api.io.TestWorkflowBundleIO testWorkflowBundleIO = new uk.org.taverna.scufl2.api.io.TestWorkflowBundleIO();
	
	@Before
	public void exampleBundle() throws ReaderException, IOException {
		String name = "example.scufl2";
		exampleBundle = getClass().getResource(name);
		assertNotNull("Can't find example workflow bundle " + name, exampleBundle);
		workflowBundle = bundleIO.readBundle(exampleBundle, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
	}
	
	@Test
	public void testParsedWorkflow() throws Exception {
		assertEquals("HelloWorld", workflowBundle.getName());
		
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		bundleIO.writeBundle(workflowBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
		String bundleTxt = new String(output.toByteArray(), "UTF-8");
		
		assertEquals(testWorkflowBundleIO.getStructureFormatWorkflowBundle(), bundleTxt);
		
	}
	
}

@@ -32,16 +32,50 @@
 dfxml;%0A%0A
+import static org.junit.Assert.*;%0A
 import s
@@ -111,16 +111,16 @@
 Equals;%0A
-
 import s
@@ -286,24 +286,45 @@
 OException;%0A
+import java.net.URI;%0A
 import java.
@@ -417,16 +417,41 @@
 Before;%0A
+import org.junit.Ignore;%0A
 import o
@@ -525,16 +525,65 @@
 Bundle;%0A
+import uk.org.taverna.scufl2.api.core.Processor;%0A
 import u
@@ -1450,16 +1450,496 @@
 DLE);%0A%09%7D
+%0A%0A%09@Test%0A%09public void dispatchStack() throws Exception %7B%0A%09%09Processor hello = workflowBundle.getMainWorkflow().getProcessors().getByName(%22Hello%22);%0A%09%09assertEquals(%22http://ns.taverna.org.uk/2010/taverna/2.2/DefaultDispatchStack%22, hello.getDispatchStack().getType().toASCIIString());%0A%09%09assertEquals(7, hello.getDispatchStack().size());%0A%09%09assertEquals(%22http://ns.taverna.org.uk/2010/scufl2/taverna#Failover%22, hello.getDispatchStack().get(3).getConfigurableType().toASCIIString());%0A%09%7D%0A%0A
 %0A%09%0A%09@Tes
@@ -2197,16 +2197,22 @@
 CTURE);%0A
+%09%09%0A%09%09%0A
 %09%09String
@@ -2270,16 +2270,16 @@
 8%22);%0A%09%09%0A
-
 %09%09assert
@@ -2360,12 +2360,376 @@
 ;%0A%09%09%0A%09%7D%0A
+%09%09%0A%09@Ignore%0A%09@Test%0A%09public void xmlOutput() throws Exception %7B%0A%09%09ByteArrayOutputStream output = new ByteArrayOutputStream();%0A%09%09new RDFXMLSerializer(workflowBundle).workflowDoc(output, workflowBundle.getMainWorkflow(), URI.create(%22workflows/HelloWorld.rdf%22));%09%09%0A%09%09String bundleTxt = new String(output.toByteArray(), %22UTF-8%22);%0A%09%09System.out.println(bundleTxt);%0A%09%09%0A%09%7D%0A
 %09%0A%7D%0A

test dispatch layer