/*
 * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
 * Use is subject to license terms.
 */
package org.jetbrains.plugins.groovy.lang;

import com.intellij.codeInsight.template.impl.actions.ListTemplatesAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;

/**
 * @author peter
 */
public class GroovyLiveTemplatesTest extends LightCodeInsightFixtureTestCase{
  @Override
  protected String getBasePath() {
    return "/svnPlugins/groovy/testdata/liveTemplates/";
  }

  public void testJavaTemplatesWorkInGroovyContext() throws Throwable {
    myFixture.configureByFile(getTestName(false) + ".groovy");
    expandTemplate();
    myFixture.checkResultByFile(getTestName(false) + ".groovy");
  }

  private void expandTemplate() {
    new WriteCommandAction(getProject()) {
      protected void run(Result result) throws Throwable {
        new ListTemplatesAction().actionPerformedImpl(getProject(), myFixture.getEditor());
      }
    }.execute();
  }

  public void testHtmlTemplatesWorkInGsp() throws Throwable {
    myFixture.configureByFile(getTestName(false) + ".gsp");
    expandTemplate();
    myFixture.checkResultByFile(getTestName(false) + ".gsp");
  }

}

@@ -215,32 +215,189 @@
 emplatesAction;%0A
+import com.intellij.codeInsight.lookup.impl.LookupImpl;%0Aimport com.intellij.codeInsight.lookup.LookupManager;%0Aimport com.intellij.codeInsight.lookup.Lookup;%0A
 import com.intel
@@ -476,32 +476,75 @@
 eCommandAction;%0A
+import com.intellij.openapi.editor.Editor;%0A
 import com.intel
@@ -962,32 +962,53 @@
  expandTemplate(
+myFixture.getEditor()
 );%0A    myFixture
@@ -1040,32 +1040,38 @@
 tName(false) + %22
+_after
 .groovy%22);%0A  %7D%0A%0A
@@ -1077,14 +1077,20 @@
 %0A  p
-rivate
+ublic static
  voi
@@ -1106,16 +1106,35 @@
 emplate(
+final Editor editor
 ) %7B%0A    
@@ -1156,16 +1156,23 @@
 dAction(
+editor.
 getProje
@@ -1292,16 +1292,23 @@
 medImpl(
+editor.
 getProje
@@ -1313,37 +1313,22 @@
 ject(), 
-myFixture.getE
+e
 ditor
-()
 );%0A     
@@ -1332,235 +1332,125 @@
     
-%7D%0A    %7D.execute();%0A  %7D%0A%0A  public void testHtmlTemplatesWorkInGsp() throws Throwable %7B%0A    myFixture.configureByFile(getTestName(false) + %22.gsp%22);%0A    expandTemplate();%0A    myFixture.checkResultByFile(getTestName(false) + %22.gsp%22
+  ((LookupImpl)LookupManager.getActiveLookup(editor)).finishLookup(Lookup.NORMAL_SELECT_CHAR);%0A      %7D%0A    %7D.execute(
 );%0A 

move gsp live template test to groovy-mvc-tests