package uk.org.taverna.scufl2.translator.t2flow;

import static org.junit.Assert.assertNotNull;

import java.net.URL;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import uk.org.taverna.scufl2.api.common.Scufl2Tools;
import uk.org.taverna.scufl2.api.container.WorkflowBundle;

public class TestAnnotationParsing {

	private static final String WF_ANNOTATED = "/annotated2.2.t2flow";
	private static Scufl2Tools scufl2Tools = new Scufl2Tools();

	@Test
	public void readSimpleWorkflow() throws Exception {
		URL wfResource = getClass().getResource(WF_ANNOTATED);
		assertNotNull("Could not find workflow " + WF_ANNOTATED,
				wfResource);
		T2FlowParser parser = new T2FlowParser();
		parser.setValidating(true);
		parser.setStrict(true);
		WorkflowBundle wfBundle = parser
				.parseT2Flow(wfResource.openStream());
		// System.out.println(researchObj.getProfiles().iterator().next()
		// .getConfigurations());
		List<String> revisions = Arrays.asList("bb902d82-b0e4-46fc-bed5-950a3b38bb98", 
				"9e1f7ffd-3bf9-4ba8-9c63-03b79b1858ad");
		
		for (Revision rev : wfBundle.getMainWorkflow().getWorkflowIdentifier()) {
			
		}
		
		
		
	}

}

@@ -86,39 +86,136 @@
 sert
-NotNull;%0D%0A%0D%0Aimport java.net.URL
+Equals;%0D%0Aimport static org.junit.Assert.assertNotNull;%0D%0A%0D%0Aimport java.net.URI;%0D%0Aimport java.net.URL;%0D%0Aimport java.util.ArrayList
 ;%0D%0Ai
@@ -287,24 +287,79 @@
 it.Test;%0D%0A%0D%0A
+import uk.org.taverna.scufl2.api.annotation.Revision;%0D%0A
 import uk.or
@@ -396,24 +396,75 @@
 ufl2Tools;%0D%0A
+import uk.org.taverna.scufl2.api.common.URITools;%0D%0A
 import uk.or
@@ -510,16 +510,65 @@
 Bundle;%0D
+%0Aimport uk.org.taverna.scufl2.api.core.Workflow;%0D
 %0A%0D%0Apubli
@@ -735,16 +735,71 @@
 s();%0D%0A%0D%0A
+%09private static URITools uriTools = new URITools();%0D%0A%0D%0A
 %09@Test%0D%0A
@@ -968,22 +968,17 @@
 NOTATED,
-%0D%0A%09%09%09%09
+ 
 wfResour
@@ -1120,22 +1120,16 @@
 = parser
-%0D%0A%09%09%09%09
 .parseT2
@@ -1164,106 +1164,8 @@
 );%0D%0A
-%09%09// System.out.println(researchObj.getProfiles().iterator().next()%0D%0A%09%09// .getConfigurations());%0D%0A
 %09%09Li
@@ -1175,17 +1175,25 @@
 String%3E 
-r
+expectedR
 evisions
@@ -1213,48 +1213,8 @@
 ist(
-%22bb902d82-b0e4-46fc-bed5-950a3b38bb98%22, 
 %0D%0A%09%09
@@ -1257,23 +1257,121 @@
 8ad%22
+,%0D%0A%09%09%09%09%22bb902d82-b0e4-46fc-bed5-950a3b38bb98%22
 );%0D%0A
-%09%09
 %0D%0A%09%09
-for (
+List%3CString%3E foundRevisions = new ArrayList%3CString%3E();%0D%0A%0D%0A%09%09
 Revi
@@ -1382,10 +1382,15 @@
  rev
- :
+ision =
  wfB
@@ -1420,53 +1420,382 @@
 .get
-WorkflowIdentifier()) %7B%0D%0A%09%09%09%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09%0D%0A%09%09
+CurrentRevision();%0D%0A%09%09while (revision != null) %7B%0D%0A%09%09%09URI revisionUri = revision.getResourceURI();%0D%0A%09%09%09String revisionUUID = uriTools%0D%0A%09%09%09%09%09.relativePath(Workflow.WORKFLOW_ROOT, revisionUri)%0D%0A%09%09%09%09%09.toASCIIString().replace(%22/%22, %22%22);%0D%0A%09%09%09foundRevisions.add(revisionUUID);%0D%0A%09%09%09revision = revision.getPreviousRevision();%0D%0A%09%09%7D%0D%0A%09%09assertEquals(expectedRevisions, foundRevisions);%0D%0A
 %0D%0A%09%7D

Test for workflow revisions