[gui-test] fix closeProject for IdeFrameFixture; better error handling for JUnitServerImpl

This commit is contained in:
Sergey Karashevich
2017-06-08 10:19:51 +03:00
parent 73bc80a099
commit b155bb5361
6 changed files with 26 additions and 19 deletions
@@ -65,7 +65,6 @@ import java.io.File;
import java.util.*;
import java.util.List;
import static com.intellij.ide.impl.ProjectUtil.closeAndDispose;
import static com.intellij.openapi.util.io.FileUtil.getRelativePath;
import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName;
import static com.intellij.openapi.util.text.StringUtil.isNotEmpty;
@@ -79,7 +78,7 @@ import static org.fest.util.Strings.quote;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
public class IdeFrameFixture extends ComponentFixture<IdeFrameFixture, IdeFrameImpl>{
public class IdeFrameFixture extends ComponentFixture<IdeFrameFixture, IdeFrameImpl> {
@NotNull private final File myProjectPath;
private EditorFixture myEditor;
@@ -91,7 +90,8 @@ public class IdeFrameFixture extends ComponentFixture<IdeFrameFixture, IdeFrameI
protected boolean isMatching(@NotNull IdeFrameImpl frame) {
Project project = frame.getProject();
if (projectPath == null && project != null) return true;
if (project != null && PathManager.getAbsolutePath(projectPath.getPath()).equals(PathManager.getAbsolutePath(project.getBasePath()))) {
if (project != null &&
PathManager.getAbsolutePath(projectPath.getPath()).equals(PathManager.getAbsolutePath(project.getBasePath()))) {
return projectName == null || projectName.equals(project.getName());
}
return false;
@@ -307,8 +307,11 @@ public class IdeFrameFixture extends ComponentFixture<IdeFrameFixture, IdeFrameI
ActionManager actionManager = ActionManager.getInstance();
AnAction mainMenuAction = actionManager.getAction(mainMenuActionId);
JMenuBar jMenuBar = this.target().getRootPane().getJMenuBar();
MouseEvent fakeMainMenuMouseEvent = new MouseEvent(jMenuBar, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y, 1, false);
ApplicationManager.getApplication().invokeLater(() -> actionManager.tryToExecute(mainMenuAction, fakeMainMenuMouseEvent, null, ActionPlaces.MAIN_MENU, true));
MouseEvent fakeMainMenuMouseEvent =
new MouseEvent(jMenuBar, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, MouseInfo.getPointerInfo().getLocation().x,
MouseInfo.getPointerInfo().getLocation().y, 1, false);
ApplicationManager.getApplication()
.invokeLater(() -> actionManager.tryToExecute(mainMenuAction, fakeMainMenuMouseEvent, null, ActionPlaces.MAIN_MENU, true));
}
/**
@@ -651,10 +654,10 @@ public class IdeFrameFixture extends ComponentFixture<IdeFrameFixture, IdeFrameI
}
public void closeProject() {
invokeMainMenu("CloseProject");
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
closeAndDispose(getProject());
RecentProjectsManager.getInstance().updateLastProjectPath();
WelcomeFrame.showIfNoProjectOpened();
}
@@ -868,7 +868,6 @@ GuiTestUtil {
}
public static void invokeAction(@NotNull Robot robot, @NotNull String actionId) {
KeyboardShortcut keyboardShortcut = ActionManager.getInstance().getKeyboardShortcut(actionId);
assert keyboardShortcut != null;
@@ -101,31 +101,31 @@ open class GuiTestCase : GuiTestBase() {
//*********CONTEXT FUNCTIONS ON LAMBDA RECEIVERS
open fun welcomeFrame(func: WelcomeFrameFixture.() -> Unit) {
func.invoke(findWelcomeFrame())
func(findWelcomeFrame())
}
fun ideFrame(func: IdeFrameFixture.() -> Unit) {
func.invoke(findIdeFrame())
func(findIdeFrame())
}
fun dialog(title: String? = null, timeout: Long = defaultTimeout, func: JDialogFixture.() -> Unit) {
func.invoke(dialog(title, timeout))
func(dialog(title, timeout))
}
fun simpleProject(func: IdeFrameFixture.() -> Unit) {
func.invoke(importSimpleProject())
func(importSimpleProject())
}
fun projectWizard(func: NewProjectWizardFixture.() -> Unit) {
func.invoke(findNewProjectWizard())
func(findNewProjectWizard())
}
fun IdeFrameFixture.projectView(func: ProjectViewFixture.() -> Unit) {
func.invoke(this.projectView)
func(this.projectView)
}
fun IdeFrameFixture.toolwindow(id: String, func: CustomToolWindowFixture.() -> Unit) {
func.invoke(CustomToolWindowFixture(id, this))
func(CustomToolWindowFixture(id, this))
}
//*********FIXTURES METHODS WITHOUT ROBOT and TARGET; KOTLIN ONLY
@@ -213,7 +213,7 @@ open class GuiTestCase : GuiTestBase() {
//*********FIXTURES METHODS FOR IDEFRAME WITHOUT ROBOT and TARGET; KOTLIN ONLY
fun IdeFrameFixture.editor(/*timeout in seconds*/ timeout: Long = defaultTimeout, func: EditorFixture.() -> Unit) {
func.invoke(this.editor)
func(this.editor)
}
fun IdeFrameFixture.popup(vararg path: String) = this.invokeMenuPath(*path)
@@ -222,6 +222,7 @@ open class GuiTestCase : GuiTestBase() {
fun typeText(text: String) = GuiTestUtil.typeText(text, myRobot, 10)
fun shortcut(keyStroke: String) = GuiTestUtil.invokeActionViaShortcut(myRobot, keyStroke)
fun screenshot(component: Component, screenshotName: String): Unit {
val extension = "${getScaleSuffix()}.png"
@@ -80,7 +80,7 @@ object GuiTestUtilKt {
private fun String.withoutIndent() = this.substring(this.getIndent())
private fun String.multiply(n: Int): String {
private operator fun String.times(n: Int): String {
val sb = StringBuilder(n)
for (i in 1..n) {
sb.append(this)
@@ -99,7 +99,7 @@ object GuiTestUtilKt {
}
fun printRecursive(root: ImmutableTreeNode<Value>, indent: Int) {
println(" ".multiply(indent) + root.value)
println(" " * indent + root.value)
if (!root.isLeaf()) root.children.forEach { printRecursive(it, indent + 2) }
}
@@ -158,6 +158,10 @@ class JUnitServerImpl: JUnitServer {
catch(e: InterruptedException) {
Thread.currentThread().interrupt()
}
catch (e: Exception) {
if (e is InvalidClassException) LOG.error("Probably client is down:", e)
failHandler?.invoke(e)
}
finally {
objectOutputStream.close()
}
@@ -9,9 +9,9 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="platform-impl" exported="" />
<orderEntry type="library" exported="" name="fest" level="project" />
<orderEntry type="library" name="JUnit4" level="project" />
<orderEntry type="library" exported="" name="JUnit4" level="project" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="java-impl" />
<orderEntry type="module" module-name="bootstrap" />