package net.sf.taverna.t2.reference.impl;

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

import java.util.Set;

import net.sf.taverna.t2.reference.ExternalReferenceSPI;
import net.sf.taverna.t2.reference.ReferenceContext;
import net.sf.taverna.t2.reference.ReferenceSet;
import net.sf.taverna.t2referencetest.DummyReferenceSet;
import net.sf.taverna.t2referencetest.GreenBuilder;
import net.sf.taverna.t2referencetest.GreenReference;
import net.sf.taverna.t2referencetest.GreenToRed;
import net.sf.taverna.t2referencetest.RedReference;

import org.junit.Test;

public class TranslationPathTest {

	private final class ReferenceSetAugmentorWithPath extends
			ReferenceSetAugmentorImpl {
		protected TranslationPath path  = new TranslationPath(this.builders);
	}

	private ReferenceSetAugmentorWithPath augmentor = new ReferenceSetAugmentorWithPath();
	
	@Test
	public void doTranslationWithTranslator() throws Exception {
		ReferenceContext context = new EmptyReferenceContext();
		ReferenceSet rs = new DummyReferenceSet(new GreenReference("green"));		
		augmentor.path.translators.add(new GreenToRed());
		Set<ExternalReferenceSPI> set = augmentor.path.doTranslation(rs, context);		
		assertEquals(1, set.size());
		assertTrue(set.iterator().next() instanceof RedReference);
	}
	
	@Test
	public void doTranslationByReadingStream() throws Exception {
		ReferenceContext context = new EmptyReferenceContext();
		augmentor.path.sourceReference = new RedReference("red");
		ReferenceSet rs = new DummyReferenceSet(augmentor.path.sourceReference);
		augmentor.path.initialBuilder = new GreenBuilder();
		//augmentor.path.translators.add(new DummyTranslator());
		Set<ExternalReferenceSPI> set = augmentor.path.doTranslation(rs, context);		
		assertEquals(1, set.size());
		assertTrue(set.iterator().next() instanceof GreenReference);
	}

	
}

@@ -640,256 +640,64 @@
 %0A%09pr
-ivate final class ReferenceSetAugmentorWithPath extends%0A%09%09%09ReferenceSetAugmentorImpl %7B%0A%09%09protected TranslationPath path  = new TranslationPath(this.builders);%0A%09%7D%0A%0A%09private ReferenceSetAugmentorWithPath augmentor = new ReferenceSetAugmentorWithPath(
+otected TranslationPath path  = new TranslationPath(null
 );%0A%09
@@ -900,26 +900,16 @@
 ));%09%09%0A%09%09
-augmentor.
 path.tra
@@ -970,34 +970,24 @@
 eSPI%3E set = 
-augmentor.
 path.doTrans
@@ -1232,34 +1232,24 @@
 ontext();%0A%09%09
-augmentor.
 path.sourceR
@@ -1326,26 +1326,16 @@
 enceSet(
-augmentor.
 path.sou
@@ -1351,26 +1351,16 @@
 nce);%0A%09%09
-augmentor.
 path.ini
@@ -1448,24 +1448,24 @@
 nslator());%0A
+
 %09%09Set%3CExtern
@@ -1486,26 +1486,16 @@
 %3E set = 
-augmentor.
 path.doT

Test TranslationPath without augmentor