package org.apache.taverna.examples;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import javax.xml.bind.JAXBException;

import org.junit.Ignore;
import org.junit.Test;
import org.apache.taverna.examples.ProcessorNames;
import org.apache.taverna.scufl2.api.container.WorkflowBundle;
import org.apache.taverna.scufl2.api.io.ReaderException;
import org.apache.taverna.scufl2.api.io.WorkflowBundleIO;

public class TestProcessorNames {

	@Test
	public void processorNames() throws JAXBException, IOException, ReaderException {
		InputStream workflow = getClass().getResourceAsStream(
				"/workflows/t2flow/biomartandembossanalysis_904962.t2flow");
		assertNotNull(workflow);

		WorkflowBundleIO io = new WorkflowBundleIO();
		WorkflowBundle ro = io.readBundle(workflow,
				"application/vnd.taverna.t2flow+xml");

		List<String> expected = Arrays.asList("CreateFasta",
				"FlattenImageList", "GetUniqueHomolog", "emma",
				"getHSapSequence", "getMMusSequence", "getRNorSequence",
				"hsapiensGeneEnsembl", "plot", "seqret");
		ProcessorNames processorNames = new ProcessorNames();
		assertEquals(expected, processorNames.showProcessorNames(ro));
		System.out.println(processorNames.showProcessorTree(ro));
	}
	

	@Test
	public void nestedWorkflow() throws JAXBException, IOException, ReaderException {
		InputStream workflow = getClass().getResourceAsStream(
				"/workflows/t2flow/as.t2flow");
		assertNotNull(workflow);

		WorkflowBundleIO io = new WorkflowBundleIO();
		WorkflowBundle ro = io.readBundle(workflow,
				"application/vnd.taverna.t2flow+xml");
		ProcessorNames processorNames = new ProcessorNames();
		System.out.println(processorNames.showProcessorTree(ro));
	}
	

	@Test
	public void nestedWorkflowBundle() throws JAXBException, IOException, ReaderException {
		InputStream workflow = getClass().getResourceAsStream(
				"/workflows/wfbundle/as.wfbundle");
		assertNotNull(workflow);

		WorkflowBundleIO io = new WorkflowBundleIO();
		WorkflowBundle ro = io.readBundle(workflow, null);
		ProcessorNames processorNames = new ProcessorNames();
		System.out.println(processorNames.showProcessorTree(ro));
	}
	
}

@@ -1082,107 +1082,8 @@
 n;%0A%0A
-import org.junit.Ignore;%0Aimport org.junit.Test;%0Aimport org.apache.taverna.examples.ProcessorNames;%0A
 impo
@@ -1141,16 +1141,16 @@
 Bundle;%0A
+
 import o
@@ -1255,16 +1255,39 @@
 undleIO;
+%0Aimport org.junit.Test;
 %0A%0Apublic
@@ -1489,38 +1489,34 @@
 low/
-biomartandembossanalysis_90496
+defaultActivitiesTaverna2.
 2.t2
@@ -1734,177 +1734,353 @@
 st(%22
-CreateFasta%22,%0A%09%09%09%09%22FlattenImageList%22, %22GetUniqueHomolog%22, %22emma%22,%0A%09%09%09%09%22getHSapSequence%22, %22getMMusSequence%22, %22getRNorSequence%22,%0A%09%09%09%09%22hsapiensGeneEnsembl%22, %22plot%22, %22seqret
+Beanshell%22, %22Nested_workflow%22,%0A%09%09%09%09%22Rshell%22, %22Send_an_Email%22, %22SpreadsheetImport%22,%0A%09%09%09%09%22String_constant%22, %22TavernaResearchObject%22, %22biomart%22,%0A%09%09%09%09%22localWorker%22, %22localWorker_bytearray%22, %22mobyObject%22,%0A%09%09%09%09%22mobyService%22, %22run%22, %22run_input%22, %22run_output%22,%0A%09%09%09%09%22setWorkflows%22, %22soaplab%22, %22wsdl_document%22, %22wsdl_rpc%22,%0A%09%09%09%09%22wsdl_secured%22, %22xmlSplitter
 %22);%0A

test processors from defaultActivities*t2flow insteawd