<commit_before>package uk.org.taverna.scufl2.translator.t2flow;

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

import java.net.URI;
import java.net.URL;

import org.junit.Before;
import org.junit.Test;

import uk.org.taverna.scufl2.api.common.NamedSet;
import uk.org.taverna.scufl2.api.common.Scufl2Tools;
import uk.org.taverna.scufl2.api.configurations.Configuration;
import uk.org.taverna.scufl2.api.container.WorkflowBundle;
import uk.org.taverna.scufl2.api.core.Processor;
import uk.org.taverna.scufl2.api.core.Workflow;
import uk.org.taverna.scufl2.api.dispatchstack.DispatchStackLayer;
import uk.org.taverna.scufl2.api.profiles.Profile;
import uk.org.taverna.scufl2.translator.t2flow.defaultdispatchstack.RetryParser.Defaults;

public class TestDispatchLayerParsing {

	private static final String WF_DISPATCH_LAYERS = "/dispatchlayers.t2flow";
	private static Scufl2Tools scufl2Tools = new Scufl2Tools();
	private T2FlowParser parser;
	private WorkflowBundle wfBundle;
	private Profile profile;
	private Workflow workflow;
	private NamedSet<Processor> processors;
	
	private URI DISPATCH_LAYER = URI.create("http://ns.taverna.org.uk/2010/scufl2/taverna/dispatchlayer/");
	
	@Before
	public void readWorkflow() throws Exception {		
		parser = new T2FlowParser();
		parser.setValidating(true);
		URL wfResource = getClass().getResource(WF_DISPATCH_LAYERS);
		assertNotNull("Could not find workflow " + WF_DISPATCH_LAYERS,
				wfResource);		
		// parser.setStrict(true);
		wfBundle = parser
				.parseT2Flow(wfResource.openStream());
		profile = wfBundle.getMainProfile();
		workflow = wfBundle.getMainWorkflow();
		processors = workflow.getProcessors();
	}
	
	@Test
	public void retriesDefault() throws Exception {
		Processor parallelise = processors.getByName("parallelise");
		URI RETRY = DISPATCH_LAYER.resolve("Retry");
		DispatchStackLayer retry = scufl2Tools.dispatchStackByType(parallelise, RETRY);
		Configuration retryConfig = scufl2Tools.configurationFor(retry, profile);
		assertEquals(RETRY.resolve("#Config"), retryConfig.getConfigurableType());
		assertTrue(retryConfig.getPropertyResource().getProperties().isEmpty());				
	}
	
	@Test
	public void retriesDefaultFromT1() throws Exception {
		Processor alternates = processors.getByName("alternates");
		URI RETRY = DISPATCH_LAYER.resolve("Retry");
		DispatchStackLayer retry = scufl2Tools.dispatchStackByType(alternates, RETRY);
		Configuration retryConfig = scufl2Tools.configurationFor(retry, profile);
		assertEquals(RETRY.resolve("#Config"), retryConfig.getConfigurableType());
		assertTrue(retryConfig.getPropertyResource().getProperties().isEmpty());				
	}
	
	
	@Test<commit_msg>SCUFL2-108 Confirm right layers<commit_after>package uk.org.taverna.scufl2.translator.t2flow;

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

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

import org.junit.Before;
import org.junit.Test;

import uk.org.taverna.scufl2.api.common.NamedSet;
import uk.org.taverna.scufl2.api.common.Scufl2Tools;
import uk.org.taverna.scufl2.api.configurations.Configuration;
import uk.org.taverna.scufl2.api.container.WorkflowBundle;
import uk.org.taverna.scufl2.api.core.Processor;
import uk.org.taverna.scufl2.api.core.Workflow;
import uk.org.taverna.scufl2.api.dispatchstack.DispatchStackLayer;
import uk.org.taverna.scufl2.api.profiles.Profile;
import uk.org.taverna.scufl2.translator.t2flow.defaultdispatchstack.RetryParser.Defaults;

public class TestDispatchLayerParsing {

	private static final String WF_DISPATCH_LAYERS = "/dispatchlayers.t2flow";
	private static Scufl2Tools scufl2Tools = new Scufl2Tools();
	private T2FlowParser parser;
	private WorkflowBundle wfBundle;
	private Profile profile;
	private Workflow workflow;
	private NamedSet<Processor> processors;
	
	private URI DISPATCH_LAYER = URI.create("http://ns.taverna.org.uk/2010/scufl2/taverna/dispatchlayer/");
	
	@Before
	public void readWorkflow() throws Exception {		
		parser = new T2FlowParser();
		parser.setValidating(true);
		URL wfResource = getClass().getResource(WF_DISPATCH_LAYERS);
		assertNotNull("Could not find workflow " + WF_DISPATCH_LAYERS,
				wfResource);		
		// parser.setStrict(true);
		wfBundle = parser
				.parseT2Flow(wfResource.openStream());
		profile = wfBundle.getMainProfile();
		workflow = wfBundle.getMainWorkflow();
		processors = workflow.getProcessors();
	}
	

	@Test
	public void whichLayers() throws Exception {
		Processor parallelise = processors.getByName("retries");
		URI RETRY = DISPATCH_LAYER.resolve("Retry");
		// As inspected in /scufl2-t2flow/src/test/resources/dispatchlayers-xsd.t2flow
		List<String> expectedNames = Arrays.asList("Parallelize", "ErrorBounce", "Failover", "Retry", "Invoke");
		List<String> foundNames = new ArrayList<String>();
		
		for (DispatchStackLayer layer : parallelise.getDispatchStack()) {
			URI type = layer.getConfigurableType();
			foundNames.add(DISPATCH_LAYER.relativize(type).toASCIIString());
		}		
		assertEquals(expectedNames, foundNames);
	}
	
	@Test
	public void retriesDefault() throws Exception {
		Processor parallelise = processors.getByName("parallelise");
		URI RETRY = DISPATCH_LAYER.resolve("Retry");
		DispatchStackLayer retry = scufl2Tools.dispatchStackByType(parallelise, RETRY);
		Configuration retryConfig = scufl2Tools.configurationFor(retry, profile);
		assertEquals(RETRY.resolve("#Config"), retryConfig.getConfigurableType());
		assertTrue(retryConfig.getPropertyResource().getProperties().isEmpty());				
	}
	
	@Test
	public void retriesDefaultFromT1() throws Exception {
		Processor alternates = processors.getByName("alternates");
		URI RETRY = DISPATCH_LAYER.resolve("Retry");
		DispatchStackLayer retry = scufl2Tools.dispatchStackByType(alternates, RETRY);
		Configuration retryConfig = scufl2Tools.configurationFor(retry, profile);
		assertEquals(RETRY.resolve("#Config"), retryConfig.getConfigurableType());
		assertTrue(retryConfig.getPropertyResource().getProperties().isEmpty());				
	}
	
	
	@Test
{'fraction_non_alphanumeric': 0.11365494685200327, 'fraction_numerical': 0.010956663941128373, 'mean_word_length': 5.918552036199095, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4235545', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1973, 'n_words': 333}