/**
 * 
 */
package javamm.swtbot.tests;

import static org.junit.Assert.assertTrue;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * @author Lorenzo Bettini
 *
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class JavammSwtBotTest extends AbstractJavammSwtbotTest {
	
	@Test
	public void canCreateANewJavammProject() throws CoreException {
		createProjectAndAssertNoErrorMarker(PROJECT_TYPE);
	}

	@Test
	public void canCreateANewJavammFile() throws CoreException {
		String name = "TestFile";
		createProjectAndAssertNoErrorMarker(PROJECT_TYPE);
		createFile("Java-- File", name, "src", "javamm", name + ".javamm");
		assertTrue(isFileCreated(TEST_PROJECT, "src-gen", "javamm", name + ".java"));
	}

	@Test
	public void canImportJavammExamples() throws CoreException {
		importExampleProjectAndAssertNoErrorMarker(
			"Some Java-- Examples", "javamm.examples");
	}

	@Test
	public void canRunAJavammFileAsJavaApplication() throws CoreException {
		createProject(PROJECT_TYPE);
		SWTBotTreeItem tree = 
				getProjectTreeItem(TEST_PROJECT).
				expand().expandNode("src").
				expandNode("javamm").
				getNode("HelloWorld.javamm");
		checkLaunchContextMenu("Run As", tree);
		checkLaunchContextMenu("Debug As", tree);
	}

	protected void checkLaunchContextMenu(String runOrDebugAs, SWTBotTreeItem tree) {
		// depending on the installed features, on a new workbench, any file has "Run As Java Application" as the
		// first menu, so we need to look for the second entry
		try {
			tree.contextMenu(runOrDebugAs).menu("1 Java-- Application");
		} catch (WidgetNotFoundException e) {
			tree.contextMenu(runOrDebugAs).menu("2 Java-- Application");
		}
	}

}

@@ -118,32 +118,95 @@
 .CoreException;%0A
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;%0A
 import org.eclip
@@ -330,16 +330,73 @@
 Runner;%0A
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;%0A
 import o
@@ -650,16 +650,88 @@
 est %7B%0A%09%0A
+%09private static final String HELLO_WORLD_JAVAMM = %22HelloWorld.javamm%22;%0A%0A
 %09@Test%0A%09
@@ -1565,35 +1565,34 @@
 getNode(
-%22HelloWorld.javamm%22
+HELLO_WORLD_JAVAMM
 );%0A%09%09che
@@ -1615,16 +1615,33 @@
 enu(
+tree.contextMenu(
 %22Run As%22
 , tr
@@ -1632,30 +1632,25 @@
 enu(%22Run As%22
-, tree
+)
 );%0A%09%09checkLa
@@ -1665,16 +1665,33 @@
 extMenu(
+tree.contextMenu(
 %22Debug A
@@ -1696,22 +1696,17 @@
  As%22
-, tree
+)
 );%0A%09%7D%0A%0A%09
 prot
@@ -1705,90 +1705,403 @@
 %7D%0A%0A%09
-protected void checkLaunchContextMenu(String runOr
+@Test%0A%09public void canRunAJavammEditorAsJavaApplication() throws CoreException %7B%0A%09%09createProject(PROJECT_TYPE);%0A%09%09SWTBotEditor editor = bot.editorByTitle(HELLO_WORLD_JAVAMM);%0A%09%09checkLaunchContextMenu(editor.toTextEditor().contextMenu(%22Run As%22));%0A%09%09checkLaunchContextMenu(editor.toTextEditor().contextMenu(%22
 Debug
+ 
 As
-, SWTBotTreeItem tree)
+%22));%0A%09%7D%0A%0A%09private void checkLaunchContextMenu(SWTBotMenu contextMenu) %7B%0A%09%09try
  %7B%0A
+%09
 %09%09//
@@ -2206,16 +2206,17 @@
 s the%0A%09%09
+%09
 // first
@@ -2268,47 +2268,20 @@
 y%0A%09%09
-try %7B%0A%09%09%09tree.contextMenu(runOrDebugAs)
+%09contextMenu
 .men
@@ -2350,21 +2350,16 @@
 e) %7B%0A%09%09%09
-tree.
 contextM
@@ -2365,22 +2365,8 @@
 Menu
-(runOrDebugAs)
 .men

test Run/Debug on editor's context menu