use another fixture as base class for course creator tests
authorliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 23 Aug 2016 12:20:13 +0000 (15:20 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 23 Aug 2016 12:20:13 +0000 (15:20 +0300)
python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/CCTestCase.java
python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderActionTest.java
python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCShowPreviewTest.java

index 9f1fd16ca1731e2dfac10b6ef52d4ef4d7d803e6..4cfa08c913281660c8d0d6805e0e49f48dadc59d 100644 (file)
@@ -1,7 +1,6 @@
 package com.jetbrains.edu.coursecreator;
 
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.PathManager;
 import com.intellij.openapi.application.Result;
 import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.diagnostic.Logger;
@@ -16,21 +15,21 @@ import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.testFramework.EditorTestUtil;
-import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
+import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
 import com.jetbrains.edu.learning.StudyTaskManager;
+import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.courseFormat.*;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.junit.ComparisonFailure;
 
-import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public abstract class CCTestCase extends LightPlatformCodeInsightFixtureTestCase {
+public abstract class CCTestCase extends CodeInsightFixtureTestCase {
   private static final Logger LOG = Logger.getInstance(CCTestCase.class);
 
   @Nullable
@@ -71,9 +70,8 @@ public abstract class CCTestCase extends LightPlatformCodeInsightFixtureTestCase
   }
 
   @Override
-  protected String getTestDataPath() {
-    //TODO: rewrite to work for plugin
-    return new File(PathManager.getHomePath(), "community/python/educational-core/course-creator/testData").getPath();
+  protected String getBasePath() {
+    return "/community/python/educational-core/course-creator/testData";
   }
 
   @Override
@@ -81,6 +79,7 @@ public abstract class CCTestCase extends LightPlatformCodeInsightFixtureTestCase
     super.setUp();
     Course course = new Course();
     course.setName("test course");
+    course.setCourseDirectory(getProject().getBasePath());
     StudyTaskManager.getInstance(getProject()).setCourse(course);
 
     Lesson lesson = new Lesson();
@@ -108,19 +107,20 @@ public abstract class CCTestCase extends LightPlatformCodeInsightFixtureTestCase
   }
 
   protected VirtualFile configureByTaskFile(String name) {
-    VirtualFile file =
-      myFixture.copyFileToProject(name, FileUtil.join(getProject().getBasePath(), "lesson1", "task1", name));
-    myFixture.configureFromExistingVirtualFile(file);
-
-    Document document = FileDocumentManager.getInstance().getDocument(file);
     Task task = StudyTaskManager.getInstance(getProject()).getCourse().getLessons().get(0).getTaskList().get(0);
     TaskFile taskFile = new TaskFile();
     taskFile.setTask(task);
     task.getTaskFiles().put(name, taskFile);
+    VirtualFile file =
+      myFixture.copyFileToProject(name, FileUtil.join(getProject().getBasePath(), "lesson1", "task1", name));
+    myFixture.configureFromExistingVirtualFile(file);
+    Document document = FileDocumentManager.getInstance().getDocument(file);
     for (AnswerPlaceholder placeholder : getPlaceholders(document, false)) {
       taskFile.addAnswerPlaceholder(placeholder);
     }
     taskFile.sortAnswerPlaceholders();
+    StudyUtils.drawAllWindows(myFixture.getEditor(), taskFile);
+    CCUtils.createResourceFile(file, StudyTaskManager.getInstance(getProject()).getCourse(), file.getParent());
     return file;
   }
 
@@ -186,11 +186,6 @@ public abstract class CCTestCase extends LightPlatformCodeInsightFixtureTestCase
     List<AnswerPlaceholder> placeholders = getPlaceholders(tempDocument, useLength);
     return Pair.create(tempDocument, placeholders);
   }
-
-  @Override
-  protected boolean shouldContainTempFiles() {
-    return false;
-  }
 }
 
 
index ab91204d29d308bea30a4cd8867bcf611666c29d..9ca2aa19733fa98235348eb6514032b0441ca6ff 100644 (file)
@@ -67,7 +67,7 @@ public class CCAnswerPlaceholderActionTest extends CCTestCase {
   }
 
   @Override
-  protected String getTestDataPath() {
-    return super.getTestDataPath() + "/actions/addPlaceholder";
+  protected String getBasePath() {
+    return super.getBasePath()  + "/actions/addPlaceholder";
   }
 }
index b5f57febac055dbc255cc4d6337aacd821af5f4c..79f8b5710a015e50b8f9735456499b2e53b6e300 100644 (file)
@@ -9,6 +9,7 @@ import com.intellij.openapi.editor.EditorFactory;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiManager;
 import com.intellij.testFramework.MapDataContext;
 import com.intellij.testFramework.TestActionEvent;
 import com.jetbrains.edu.coursecreator.CCTestCase;
@@ -22,7 +23,7 @@ public class CCShowPreviewTest extends CCTestCase {
   public void testPreviewUnavailable() {
     VirtualFile file = configureByTaskFile("noplaceholders.txt");
     CCShowPreview action = new CCShowPreview();
-    TestActionEvent e = getActionEvent(action, getPsiManager().findFile(file));
+    TestActionEvent e = getActionEvent(action, PsiManager.getInstance(getProject()).findFile(file));
     action.beforeActionPerformedUpdate(e);
     assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
     try {
@@ -44,7 +45,7 @@ public class CCShowPreviewTest extends CCTestCase {
   private void doTest(String name) {
     VirtualFile file = configureByTaskFile(name + CCTestsUtil.BEFORE_POSTFIX);
     CCShowPreview action = new CCShowPreview();
-    TestActionEvent e = getActionEvent(action, getPsiManager().findFile(file));
+    TestActionEvent e = getActionEvent(action,PsiManager.getInstance(getProject()).findFile(file));
     action.beforeActionPerformedUpdate(e);
     assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
     action.actionPerformed(e);
@@ -54,12 +55,11 @@ public class CCShowPreviewTest extends CCTestCase {
     for (AnswerPlaceholder placeholder : pair.getSecond()) {
       assertNotNull("No highlighter for placeholder:" + CCTestsUtil.getPlaceholderPresentation(placeholder), getHighlighter(editor.getMarkupModel(), placeholder));
     }
-    EditorFactory.getInstance().releaseEditor(editor);
   }
 
   @Override
-  protected String getTestDataPath() {
-    return super.getTestDataPath() + "/actions/preview";
+  protected String getBasePath() {
+    return super.getBasePath() + "/actions/preview";
   }
 
   TestActionEvent getActionEvent(AnAction action, PsiFile psiFile) {