From 61688b2883723307f3db10c1f57423f112b4ea0e Mon Sep 17 00:00:00 2001 From: "liana.bakradze" Date: Tue, 23 Aug 2016 15:20:13 +0300 Subject: [PATCH] use another fixture as base class for course creator tests --- .../edu/coursecreator/CCTestCase.java | 29 ++++++++----------- .../CCAnswerPlaceholderActionTest.java | 4 +-- .../actions/CCShowPreviewTest.java | 10 +++---- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/CCTestCase.java b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/CCTestCase.java index 9f1fd16ca173..4cfa08c91328 100644 --- a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/CCTestCase.java +++ b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/CCTestCase.java @@ -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 placeholders = getPlaceholders(tempDocument, useLength); return Pair.create(tempDocument, placeholders); } - - @Override - protected boolean shouldContainTempFiles() { - return false; - } } diff --git a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderActionTest.java b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderActionTest.java index ab91204d29d3..9ca2aa19733f 100644 --- a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderActionTest.java +++ b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderActionTest.java @@ -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"; } } diff --git a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCShowPreviewTest.java b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCShowPreviewTest.java index b5f57febac05..79f8b5710a01 100644 --- a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCShowPreviewTest.java +++ b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCShowPreviewTest.java @@ -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) { -- 2.23.3