package com.opcoach.genmodeladdon.core.test;

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

import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.junit.Before;
import org.junit.Test;

import com.opcoach.genmodeladdon.core.genmodel.GMATransform;

public class TestGMATransform extends GenModelAddonTestCase
{
	
	
	
	
	/**  Examples 
	 * 
	    public class MProjecttototo
	    import com.opcoach.project.MProject;
	    public class MyDocMProject extends MProject
	    MProjectInformation
	    <MProject>  <MProject,MyMProject>
	    
	
	
	
	
	 *
	 */
	
	
	class GMATransformStub extends GMATransform
	{

		public GMATransformStub(GenModel gm)     
		{
			super(gm);
			init();
			// Add other strings to replace... just for tests.
			devNames.put("MWorkflow", "Workflow");
		}
	
	}
	
	 GMATransformStub gmat = null;

	@Before
	public  void setup() throws Exception
	{
		// Create the GMATransform with some additionals strings inside
		GenModel gm = getGenModel(PROJECT_GENMODEL);

		gmat = new GMATransformStub(gm);
	}

	@Test
	public void testSimpleReplaceWithBlank()
	{
		String source = "public class MProject ";
		String expected = "public class Project ";
		assertEquals(expected, gmat.replaceDevName(source));
	}
	
	@Test
	public void testSimpleReplaceWithCR()
	{
		String source = "public class MProject";
		String expected = "public class Project";
		assertEquals(expected, gmat.replaceDevName(source));
	}
	
	@Test
	public void testSimpleReplaceWithNothingAround()
	{
		String source = "MProject";
		String expected = "Project";
		assertEquals(expected, gmat.replaceDevName(source));
	}
	
	@Test
	public void testInnerNoReplace()
	{
		String source = "public class MyMProject";
		String expected = source;
		assertEquals(expected, gmat.replaceDevName(source));
	}

	@Test
	public void testContinuousEnd()
	{
		String source = "public class MProject1";
		String expected = source;
		assertEquals(expected, gmat.replaceDevName(source));
	}
	
	@Test
	public void testForMethodRename()
	{
		String source = "MWorkflow getWorkflow();";
		String expected = "Workflow getWorkflow();";
		assertEquals(expected, gmat.replaceDevName(source));
	}

	
	@Test
	public void fullTestWithAllCases()
	{
		String source   = "MWorkflow MWorkflowTest setMWorkflow(MWorkflow mf) WorkflowFactory MWorkflowFactory MWorkflow .MWorkflow <MWorkflow> EList<MWorkflow> Map<MWorkflow,String> Map<MWorkflow ,String>  .MWorkflow;";
		String expected = "Workflow MWorkflowTest setMWorkflow(Workflow mf) WorkflowFactory MWorkflowFactory Workflow .Workflow <Workflow> EList<Workflow> Map<Workflow,String> Map<Workflow ,String>  .Workflow;";
		assertEquals(expected, gmat.replaceDevName(source));
	}

	


}

@@ -365,248 +365,8 @@
 %09%0A%09%0A
-%09%0A%09%0A%09/**  Examples %0A%09 * %0A%09    public class MProjecttototo%0A%09    import com.opcoach.project.MProject;%0A%09    public class MyDocMProject extends MProject%0A%09    MProjectInformation%0A%09    %3CMProject%3E  %3CMProject,MyMProject%3E%0A%09    %0A%09%0A%09%0A%09%0A%09%0A%09 *%0A%09 */%0A%09%0A%09%0A
 %09cla
@@ -406,16 +406,16 @@
 ansform%0A
+
 %09%7B%0A%0A%09%09pu
@@ -537,16 +537,16 @@
  tests.%0A
-
 %09%09%09devNa
@@ -579,16 +579,102 @@
 flow%22);%0A
+%09%09%09devNames.put(%22Satellite%22, %22DevSatellite%22);%0A%09%09%09devNames.put(%22System%22, %22DevSystem%22);%0A
 %09%09%7D%0A%09%0A%09%7D
@@ -2568,13 +2568,577 @@
 );%0A%09%7D%0A%0A%09
+@Test%0A%09public void testWithKeyShorterThanValue()%0A%09%7B%0A%09%09String source   = %22Satellite SatelliteTest setSatellite(Satellite s) DevSatelliteFactory SatelliteFactory System .Satellite %3CSatellite%3E EList%3CSatellite%3E Map%3CSatellite,String%3E Map%3CSatellite ,String%3E  .System;%22;%0A%09%09String expected = %22DevSatellite SatelliteTest setSatellite(DevSatellite s) DevSatelliteFactory SatelliteFactory DevSystem .DevSatellite %3CDevSatellite%3E EList%3CDevSatellite%3E Map%3CDevSatellite,String%3E Map%3CDevSatellite ,String%3E  .DevSystem;%22;%0A%09%09assertEquals(expected, gmat.replaceDevName(source));%0A%09%7D%0A%0A%09%0A
 %0A%0A%0A%7D%0A

Add a test for keys shorter than values