package com.opcoach.genmodeladdon.core.test;


import static org.junit.Assert.*;

import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.common.util.URI;
import org.junit.Test;

import com.opcoach.genmodeladdon.core.GenerateCommon;

public class TestGenerateCommon extends GenModelAddonTestCase
{
	private static final String PROJECT_SAMPLE_NAME = "com.opcoach.genmodeladdon.sample";

	@Test
	public void testGetProjectNameFromLinuxURI()
	{
		URI u = URI.createURI("/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon/com.opcoach.genmodeladdon.sample/model/project.genmodel");
		String s = GenerateCommon.getProjectNameFromURI(u);
		assertEquals("Project name must be " + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);
	}

	@Test
	public void testGetProjectNameFromFileURI()
	{
		URI u = URI.createURI("file:/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon/com.opcoach.genmodeladdon.sample/model/project.genmodel");
		String s = GenerateCommon.getProjectNameFromURI(u);
		assertEquals("Project name must be " + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);
	}
	
	
	@Test
	public void testGetProjectNameFromWindowsFileURI()
	{
		URI u = URI.createURI("file:/C:/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon/com.opcoach.genmodeladdon.sample/model/project.genmodel");
		String s = GenerateCommon.getProjectNameFromURI(u);
		assertEquals("Project name must be " + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);
	}

	@Test
	public void testGetProjectNameFromWindowsPathURI()
	{
		URI u = URI.createURI("C:/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon/com.opcoach.genmodeladdon.sample/model/project.genmodel");
		String s = GenerateCommon.getProjectNameFromURI(u);
		assertEquals("Project name must be " + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);
	}


	@Test
	public void testGetProjectNameFromProjectGenModel()
	{
		GenModel gm = getGenModel(PROJECT_GENMODEL);
		String s = GenerateCommon.getProjectName(gm);
		assertEquals("Project name must be " + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);
	}
	
	@Test
	public void testGetProjectNameFromFannoiseGenModel()
	{
		GenModel gm = getGenModel(FANNOISE_GENMODEL);
		String s = GenerateCommon.getProjectName(gm);
		assertEquals("Project name must be " + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);
	}
	

}

@@ -402,16 +402,90 @@
 mple%22;%0A%0A
+%09private String getWsHome()%0A%09%7B%0A%09%09return root.getLocation().toString();%0A%09%7D%0A
 %09@Test%0A%09
@@ -522,13 +522,14 @@
 From
-Linux
+Simple
 URI(
@@ -561,72 +561,23 @@
 URI(
-%22/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon
+getWsHome() + %22
 /com
@@ -866,71 +866,27 @@
 ile:
-/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon
+%22 + getWsHome() + %22
 /com
@@ -1186,430 +1186,27 @@
 le:/
-C:/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon/com.opcoach.genmodeladdon.sample/model/project.genmodel%22);%0A%09%09String s = GenerateCommon.getProjectNameFromURI(u);%0A%09%09assertEquals(%22Project name must be %22 + PROJECT_SAMPLE_NAME, PROJECT_SAMPLE_NAME, s);%0A%09%7D%0A%0A%09@Test%0A%09public void testGetProjectNameFromWindowsPathURI()%0A%09%7B%0A%09%09URI u = URI.createURI(%22C:/Users/olivier/Documents/OPCoach/workspaces/junit-genmodeladdon
+%22 + getWsHome() + %22
 /com

Update tests to manage different workspaces