From d082b32eeb844af88faea4323866618272d9404f Mon Sep 17 00:00:00 2001 From: David Festal Date: Tue, 2 May 2017 14:29:19 +0200 Subject: [PATCH] Rework top test menu items https://issues.jboss.org/browse/CHE-227 Signed-off-by: David Festal --- .../che-plugin-testing-junit-ide/pom.xml | 4 - .../testing/junit/ide/JUnitTestAction.java | 29 +--- .../ide/JUnitTestLocalizationConstant.java | 6 - .../ide/action/RunAllContextTestAction.java | 142 ---------------- .../junit/ide/action/RunAllTestAction.java | 75 +++++++-- .../ide/action/RunClassContextTestAction.java | 135 --------------- .../junit/ide/action/RunClassTestAction.java | 75 ++++++--- .../JUnitTestLocalizationConstant.properties | 5 +- .../che-plugin-testing-testng-ide/pom.xml | 4 - .../ide/TestNGLocalizationConstant.java | 6 - .../testing/testng/ide/TestNGTestAction.java | 46 ++---- .../ide/action/RunAllContextTestAction.java | 142 ---------------- .../testng/ide/action/RunAllTestAction.java | 63 +++++-- .../ide/action/RunClassContextTestAction.java | 137 ---------------- .../testng/ide/action/RunClassTestAction.java | 84 ++++++---- .../testng/ide/action/RunTestXMLAction.java | 79 ++++++--- .../ide/action/RunTestXMLContextAction.java | 154 ------------------ .../ide/TestNGLocalizationConstant.properties | 7 +- 18 files changed, 298 insertions(+), 895 deletions(-) delete mode 100644 plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllContextTestAction.java delete mode 100644 plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassContextTestAction.java delete mode 100644 plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllContextTestAction.java delete mode 100644 plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassContextTestAction.java delete mode 100644 plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLContextAction.java diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/pom.xml b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/pom.xml index e3bb4f3efef..08bffaa7fca 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/pom.xml +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/pom.xml @@ -37,10 +37,6 @@ org.eclipse.che.core che-core-ide-api - - org.eclipse.che.core - che-core-ide-app - org.eclipse.che.plugin che-plugin-java-ext-lang-client diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java index 1fc0c441bdf..5e126469e9d 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java @@ -17,9 +17,7 @@ import org.eclipse.che.ide.api.keybinding.KeyBuilder; import org.eclipse.che.ide.util.browser.UserAgent; import org.eclipse.che.plugin.testing.ide.TestAction; -import org.eclipse.che.plugin.testing.junit.ide.action.RunAllContextTestAction; import org.eclipse.che.plugin.testing.junit.ide.action.RunAllTestAction; -import org.eclipse.che.plugin.testing.junit.ide.action.RunClassContextTestAction; import org.eclipse.che.plugin.testing.junit.ide.action.RunClassTestAction; import com.google.inject.Inject; @@ -30,27 +28,18 @@ * @author Mirage Abeysekara */ public class JUnitTestAction implements TestAction { - - public static final String TEST_ACTION_RUN_ALL = "TestActionRunAll"; - public static final String TEST_ACTION_RUN_CLASS = "TestActionRunClass"; - public static final String TEST_ACTION_RUN_CLASS_CONTEXT = "TestActionRunClassContext"; - public static final String TEST_ACTION_RUN_ALL_CONTEXT = "TestActionRunAllContext"; - private final Action runClassTestAction; - private final Action runAllTestAction; + public static final String TEST_ACTION_RUN_CLASS = "TestJUnitActionRunClassContext"; + public static final String TEST_ACTION_RUN_ALL = "TestJUnitActionRunAllContext"; private final Action runClassContextTestAction; private final Action runAllContextTestAction; @Inject public JUnitTestAction(ActionManager actionManager, - RunClassTestAction runClassTestAction, - RunAllTestAction runAllTestAction, - RunClassContextTestAction runClassContextTestAction, - RunAllContextTestAction runAllContextTestAction, + RunClassTestAction runClassContextTestAction, + RunAllTestAction runAllContextTestAction, KeyBindingAgent keyBinding) { - actionManager.registerAction(TEST_ACTION_RUN_CLASS, runClassTestAction); - actionManager.registerAction(TEST_ACTION_RUN_ALL, runAllTestAction); - actionManager.registerAction(TEST_ACTION_RUN_CLASS_CONTEXT, runClassContextTestAction); - actionManager.registerAction(TEST_ACTION_RUN_ALL_CONTEXT, runAllContextTestAction); + actionManager.registerAction(TEST_ACTION_RUN_CLASS, runClassContextTestAction); + actionManager.registerAction(TEST_ACTION_RUN_ALL, runAllContextTestAction); if (UserAgent.isMac()) { keyBinding.getGlobal().addKey(new KeyBuilder().control().alt().charCode('z').build(), TEST_ACTION_RUN_ALL); @@ -60,17 +49,15 @@ public JUnitTestAction(ActionManager actionManager, keyBinding.getGlobal().addKey(new KeyBuilder().action().shift().charCode('z').build(), TEST_ACTION_RUN_CLASS); } - this.runAllTestAction = runAllTestAction; this.runClassContextTestAction = runClassContextTestAction; - this.runClassTestAction = runClassTestAction; this.runAllContextTestAction = runAllContextTestAction; } @Override public void addMainMenuItems(DefaultActionGroup testMainMenu) { - testMainMenu.add(runClassTestAction); - testMainMenu.add(runAllTestAction); + testMainMenu.add(runClassContextTestAction); + testMainMenu.add(runAllContextTestAction); } @Override diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.java index a4fd6edcbfb..f1be10505bf 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.java @@ -26,12 +26,6 @@ public interface JUnitTestLocalizationConstant extends Messages { @Key("action.runClass.description") String actionRunClassDescription(); - @Key("action.runClassContext.title") - String actionRunClassContextTitle(); - - @Key("action.runClassContext.description") - String actionRunClassContextDescription(); - @Key("action.runAll.title") String actionRunAllTitle(); diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllContextTestAction.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllContextTestAction.java deleted file mode 100644 index 9973a123401..00000000000 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllContextTestAction.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.testing.junit.ide.action; - -import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import javax.validation.constraints.NotNull; - -import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; -import org.eclipse.che.ide.api.action.ActionEvent; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.Container; -import org.eclipse.che.ide.api.resources.Project; -import org.eclipse.che.ide.api.selection.Selection; -import org.eclipse.che.ide.api.selection.SelectionAgent; -import org.eclipse.che.ide.resources.tree.ContainerNode; -import org.eclipse.che.ide.resources.tree.FileNode; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; -import org.eclipse.che.plugin.testing.junit.ide.JUnitTestLocalizationConstant; -import org.eclipse.che.plugin.testing.junit.ide.JUnitTestResources; - -import com.google.inject.Inject; - -/** - * @author Mirage Abeysekara - * @author David Festal - */ -public class RunAllContextTestAction extends AbstractPerspectiveAction - implements RunTestActionDelegate.Source { - - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; - private final AppContext appContext; - private final SelectionAgent selectionAgent; - private final RunTestActionDelegate delegate; - - @Inject - public RunAllContextTestAction(JUnitTestResources resources, - NotificationManager notificationManager, - AppContext appContext, - TestResultPresenter presenter, - TestServiceClient service, - SelectionAgent selectionAgent, - JUnitTestLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunAllTitle(), - localization.actionRunAllDescription(), null, resources.testAllIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; - this.appContext = appContext; - this.selectionAgent = selectionAgent; - this.delegate = new RunTestActionDelegate(this); - } - - @Override - public void actionPerformed(ActionEvent e) { - final Selection< ? > selection = selectionAgent.getSelection(); - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof ContainerNode) { - Container container = ((ContainerNode)possibleNode).getData(); - Project project = container.getProject(); - if (project != null) { - Map parameters = new HashMap<>(); - delegate.doRunTests(e, parameters); - } - } - } - - @Override - public void updateInPerspective(@NotNull ActionEvent e) { - e.getPresentation().setVisible(true); - if ((appContext.getRootProject() == null)) { - e.getPresentation().setEnabled(false); - return; - } - final Selection< ? > selection = selectionAgent.getSelection(); - if (selection == null || selection.isEmpty()) { - e.getPresentation().setEnabled(false); - return; - } - if (selection.isMultiSelection()) { - e.getPresentation().setEnabled(false); - return; - } - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof FileNode) { - e.getPresentation().setVisible(false); - } - if (possibleNode instanceof ContainerNode) { - Container container = ((ContainerNode)possibleNode).getData(); - Project project = container.getProject(); - if (project != null) { - String projectType = project.getType(); - boolean enable = "maven".equals(projectType); - e.getPresentation().setEnabled(enable); - return; - } - } - e.getPresentation().setEnabled(false); - } - - @Override - public NotificationManager getNotificationManager() { - return notificationManager; - } - - @Override - public AppContext getAppContext() { - return appContext; - } - - @Override - public TestServiceClient getService() { - return service; - } - - @Override - public TestResultPresenter getPresenter() { - return presenter; - } - - @Override - public String getTestingFramework() { - return "junit"; - } -} diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllTestAction.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllTestAction.java index 4d72be58d06..3b9c692a07a 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunAllTestAction.java @@ -10,15 +10,28 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.junit.ide.action; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import javax.validation.constraints.NotNull; + +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.editor.EditorAgent; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.ext.java.client.action.JavaEditorAction; +import org.eclipse.che.ide.api.resources.Container; +import org.eclipse.che.ide.api.resources.File; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Resource; +import org.eclipse.che.ide.api.resources.VirtualFile; +import org.eclipse.che.ide.api.selection.Selection; +import org.eclipse.che.ide.api.selection.SelectionAgent; +import org.eclipse.che.ide.ext.java.client.util.JavaUtil; +import org.eclipse.che.ide.resources.tree.ContainerNode; +import org.eclipse.che.ide.resources.tree.FileNode; import org.eclipse.che.plugin.testing.ide.TestServiceClient; import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; @@ -31,35 +44,63 @@ * @author Mirage Abeysekara * @author David Festal */ -public class RunAllTestAction extends JavaEditorAction - implements RunTestActionDelegate.Source { +public class RunAllTestAction extends AbstractPerspectiveAction + implements RunTestActionDelegate.Source { private final NotificationManager notificationManager; private final TestResultPresenter presenter; private final TestServiceClient service; + private final AppContext appContext; + private final SelectionAgent selectionAgent; private final RunTestActionDelegate delegate; @Inject public RunAllTestAction(JUnitTestResources resources, - NotificationManager notificationManager, - EditorAgent editorAgent, - TestResultPresenter presenter, - FileTypeRegistry fileTypeRegistry, - TestServiceClient service, - JUnitTestLocalizationConstant localization) { - super(localization.actionRunAllTitle(), localization.actionRunAllDescription(), resources.testAllIcon(), - editorAgent, fileTypeRegistry); + NotificationManager notificationManager, + AppContext appContext, + TestResultPresenter presenter, + TestServiceClient service, + SelectionAgent selectionAgent, + JUnitTestLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunAllTitle(), + localization.actionRunAllDescription(), null, resources.testAllIcon()); this.notificationManager = notificationManager; - this.editorAgent = editorAgent; this.presenter = presenter; this.service = service; + this.appContext = appContext; + this.selectionAgent = selectionAgent; this.delegate = new RunTestActionDelegate(this); } @Override public void actionPerformed(ActionEvent e) { - Map parameters = new HashMap<>(); - delegate.doRunTests(e, parameters); + Resource resource = appContext.getResource(); + if (resource != null) { + Project project = resource.getProject(); + if (project != null) { + Map parameters = new HashMap<>(); + delegate.doRunTests(e, parameters); + } + } + } + + @Override + public void updateInPerspective(@NotNull ActionEvent e) { + Resource resource = appContext.getResource(); + if (resource == null) { + e.getPresentation().setEnabledAndVisible(false); + } + + Project project = resource.getProject(); + if (project == null) { + e.getPresentation().setEnabledAndVisible(false); + } + + e.getPresentation().setVisible(true); + + String projectType = project.getType(); + boolean enable = "maven".equals(projectType); + e.getPresentation().setEnabled(enable); } @Override @@ -81,7 +122,7 @@ public TestServiceClient getService() { public TestResultPresenter getPresenter() { return presenter; } - + @Override public String getTestingFramework() { return "junit"; diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassContextTestAction.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassContextTestAction.java deleted file mode 100644 index 40326330a66..00000000000 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassContextTestAction.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.testing.junit.ide.action; - -import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import javax.validation.constraints.NotNull; - -import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; -import org.eclipse.che.ide.api.action.ActionEvent; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.api.selection.Selection; -import org.eclipse.che.ide.api.selection.SelectionAgent; -import org.eclipse.che.ide.ext.java.client.util.JavaUtil; -import org.eclipse.che.ide.resources.tree.FileNode; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; -import org.eclipse.che.plugin.testing.junit.ide.JUnitTestLocalizationConstant; -import org.eclipse.che.plugin.testing.junit.ide.JUnitTestResources; - -import com.google.inject.Inject; - -/** - * @author Mirage Abeysekara - * @author David Festal - */ -public class RunClassContextTestAction extends AbstractPerspectiveAction - implements RunTestActionDelegate.Source { - - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; - private final AppContext appContext; - private final SelectionAgent selectionAgent; - private final RunTestActionDelegate delegate; - - @Inject - public RunClassContextTestAction(JUnitTestResources resources, - NotificationManager notificationManager, - AppContext appContext, - TestResultPresenter presenter, - TestServiceClient service, - SelectionAgent selectionAgent, - JUnitTestLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunClassContextTitle(), - localization.actionRunClassContextDescription(), null, resources.testIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; - this.appContext = appContext; - this.selectionAgent = selectionAgent; - this.delegate = new RunTestActionDelegate(this); - } - - @Override - public void actionPerformed(ActionEvent e) { - final Selection< ? > selection = selectionAgent.getSelection(); - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof FileNode) { - VirtualFile file = ((FileNode)possibleNode).getData(); - String fqn = JavaUtil.resolveFQN(file); - Map parameters = new HashMap<>(); - parameters.put("fqn", fqn); - parameters.put("runClass", "true"); - delegate.doRunTests(e, parameters); - } - } - - @Override - public void updateInPerspective(@NotNull ActionEvent e) { - if ((appContext.getRootProject() == null)) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - final Selection< ? > selection = selectionAgent.getSelection(); - if (selection == null || selection.isEmpty()) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - if (selection.isMultiSelection()) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - final Object possibleNode = selection.getHeadElement(); - if (!(possibleNode instanceof FileNode)) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - - e.getPresentation().setVisible(true); - boolean enable = "java".equals(((FileNode)possibleNode).getData().getExtension()); - e.getPresentation().setEnabled(enable); - } - - @Override - public NotificationManager getNotificationManager() { - return notificationManager; - } - - @Override - public AppContext getAppContext() { - return appContext; - } - - @Override - public TestServiceClient getService() { - return service; - } - - @Override - public TestResultPresenter getPresenter() { - return presenter; - } - - - @Override - public String getTestingFramework() { - return "junit"; - } -} diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassTestAction.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassTestAction.java index 8695f22159f..8e68812499d 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/action/RunClassTestAction.java @@ -10,17 +10,22 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.junit.ide.action; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import javax.validation.constraints.NotNull; + +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.editor.EditorAgent; -import org.eclipse.che.ide.api.editor.EditorPartPresenter; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.resources.File; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.ext.java.client.action.JavaEditorAction; import org.eclipse.che.ide.ext.java.client.util.JavaUtil; import org.eclipse.che.plugin.testing.ide.TestServiceClient; import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; @@ -34,47 +39,66 @@ * @author Mirage Abeysekara * @author David Festal */ -public class RunClassTestAction extends JavaEditorAction - implements RunTestActionDelegate.Source { +public class RunClassTestAction extends AbstractPerspectiveAction + implements RunTestActionDelegate.Source { private final NotificationManager notificationManager; - private final EditorAgent editorAgent; private final TestResultPresenter presenter; private final TestServiceClient service; + private final AppContext appContext; private final RunTestActionDelegate delegate; @Inject public RunClassTestAction(JUnitTestResources resources, - NotificationManager notificationManager, - EditorAgent editorAgent, - FileTypeRegistry fileTypeRegistry, - TestResultPresenter presenter, - TestServiceClient service, - JUnitTestLocalizationConstant localization) { - super(localization.actionRunClassTitle(), localization.actionRunClassDescription(), resources.testIcon(), - editorAgent, fileTypeRegistry); + NotificationManager notificationManager, + AppContext appContext, + TestResultPresenter presenter, + TestServiceClient service, + JUnitTestLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunClassTitle(), + localization.actionRunClassDescription(), null, resources.testIcon()); this.notificationManager = notificationManager; - this.editorAgent = editorAgent; this.presenter = presenter; this.service = service; + this.appContext = appContext; this.delegate = new RunTestActionDelegate(this); } @Override public void actionPerformed(ActionEvent e) { - EditorPartPresenter editorPart = editorAgent.getActiveEditor(); - final VirtualFile file = editorPart.getEditorInput().getFile(); - String fqn = JavaUtil.resolveFQN(file); - Map parameters = new HashMap<>(); - parameters.put("fqn", fqn); - parameters.put("runClass", "true"); - delegate.doRunTests(e, parameters); + Resource resource = appContext.getResource(); + if (resource instanceof File) { + File file = ((File)resource); + String fqn = JavaUtil.resolveFQN((VirtualFile)file); + Map parameters = new HashMap<>(); + parameters.put("fqn", fqn); + parameters.put("runClass", "true"); + delegate.doRunTests(e, parameters); + } } @Override - protected void updateProjectAction(ActionEvent e) { - super.updateProjectAction(e); + public void updateInPerspective(@NotNull ActionEvent e) { + Resource resource = appContext.getResource(); + if (! (resource instanceof File)) { + e.getPresentation().setEnabledAndVisible(false); + return; + } + + Project project = resource.getProject(); + if (project == null) { + e.getPresentation().setEnabledAndVisible(false); + } + e.getPresentation().setVisible(true); + + String projectType = project.getType(); + if (! "maven".equals(projectType)) { + e.getPresentation().setEnabled(false); + } + + boolean enable = "java".equals(((File)resource).getExtension()); + e.getPresentation().setEnabled(enable); } @Override @@ -97,6 +121,7 @@ public TestResultPresenter getPresenter() { return presenter; } + @Override public String getTestingFramework() { return "junit"; diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/resources/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.properties b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/resources/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.properties index 0b353822fbb..ffb99f16476 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/resources/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.properties +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/resources/org/eclipse/che/plugin/testing/junit/ide/JUnitTestLocalizationConstant.properties @@ -13,10 +13,7 @@ ##### Actions ##### action.runClass.title = JUnit Class -action.runClass.description = Run the currently open junit test class - -action.runClassContext.title = JUnit Class -action.runClassContext.description = Run the JUnit test cases +action.runClass.description = Run the JUnit test cases action.runAll.title = JUnit Project action.runAll.description = Run all JUnit test cases diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/pom.xml b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/pom.xml index 6667800cc8f..681283f238a 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/pom.xml +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/pom.xml @@ -37,10 +37,6 @@ org.eclipse.che.core che-core-ide-api - - org.eclipse.che.core - che-core-ide-app - org.eclipse.che.plugin che-plugin-java-ext-lang-client diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.java index 90762bb2ab5..c62700f993f 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.java @@ -26,12 +26,6 @@ public interface TestNGLocalizationConstant extends Messages { @Key("action.runClass.description") String actionRunClassDescription(); - @Key("action.runClassContext.title") - String actionRunClassContextTitle(); - - @Key("action.runClassContext.description") - String actionRunClassContextDescription(); - @Key("action.runAll.title") String actionRunAllTitle(); diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java index 463b172135e..deb7c9a1871 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java @@ -17,12 +17,9 @@ import org.eclipse.che.ide.api.keybinding.KeyBuilder; import org.eclipse.che.ide.util.browser.UserAgent; import org.eclipse.che.plugin.testing.ide.TestAction; -import org.eclipse.che.plugin.testing.testng.ide.action.RunAllContextTestAction; import org.eclipse.che.plugin.testing.testng.ide.action.RunAllTestAction; -import org.eclipse.che.plugin.testing.testng.ide.action.RunClassContextTestAction; import org.eclipse.che.plugin.testing.testng.ide.action.RunClassTestAction; import org.eclipse.che.plugin.testing.testng.ide.action.RunTestXMLAction; -import org.eclipse.che.plugin.testing.testng.ide.action.RunTestXMLContextAction; import com.google.inject.Inject; @@ -32,49 +29,42 @@ * @author Mirage Abeysekara */ public class TestNGTestAction implements TestAction { + + public static final String TEST_ACTION_RUN_CLASS = "TestNGActionRunClassContext"; + public static final String TEST_ACTION_RUN_ALL = "TestNGActionRunAllContext"; + public static final String TEST_ACTION_RUN_XML = "TestNGActionRunXMLContext"; - private final Action runClassTestAction; - private final Action runAllTestAction; private final Action runClassContextTestAction; private final Action runAllContextTestAction; - private final Action runTestXMLAction; private final Action runTestXMLContextAction; @Inject public TestNGTestAction(ActionManager actionManager, - RunClassTestAction runClassTestAction, - RunAllTestAction runAllTestAction, - RunClassContextTestAction runClassContextTestAction, - RunAllContextTestAction runAllContextTestAction, - RunTestXMLAction runTestXMLAction, - RunTestXMLContextAction runTestXMLContextAction, + RunClassTestAction runClassContextTestAction, + RunAllTestAction runAllContextTestAction, + RunTestXMLAction runTestXMLContextAction, KeyBindingAgent keyBinding) { - actionManager.registerAction("TestNGActionRunClass", runClassTestAction); - actionManager.registerAction("TestNGActionRunAll", runAllTestAction); - actionManager.registerAction("TestNGActionRunXML", runTestXMLAction); - actionManager.registerAction("TestNGActionRunClassContext", runClassContextTestAction); - actionManager.registerAction("TestNGActionRunAllContext", runAllContextTestAction); - actionManager.registerAction("TestNGActionRunXMLContext", runTestXMLContextAction); + + actionManager.registerAction(TEST_ACTION_RUN_CLASS, runClassContextTestAction); + actionManager.registerAction(TEST_ACTION_RUN_ALL, runAllContextTestAction); + actionManager.registerAction(TEST_ACTION_RUN_XML, runTestXMLContextAction); if (UserAgent.isMac()) { - keyBinding.getGlobal().addKey(new KeyBuilder().control().alt().charCode('g').build(), "TestNGActionRunAll"); - keyBinding.getGlobal().addKey(new KeyBuilder().control().shift().charCode('g').build(), "TestNGActionRunClass"); + keyBinding.getGlobal().addKey(new KeyBuilder().control().alt().charCode('g').build(), TEST_ACTION_RUN_ALL); + keyBinding.getGlobal().addKey(new KeyBuilder().control().shift().charCode('g').build(), TEST_ACTION_RUN_CLASS); } else { - keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('g').build(), "TestNGActionRunAll"); - keyBinding.getGlobal().addKey(new KeyBuilder().action().shift().charCode('g').build(), "TestNGActionRunClass"); + keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('g').build(), TEST_ACTION_RUN_ALL); + keyBinding.getGlobal().addKey(new KeyBuilder().action().shift().charCode('g').build(), TEST_ACTION_RUN_CLASS); } - this.runClassTestAction = runClassTestAction; this.runClassContextTestAction = runClassContextTestAction; - this.runAllTestAction = runAllTestAction; this.runAllContextTestAction = runAllContextTestAction; - this.runTestXMLAction = runTestXMLAction; this.runTestXMLContextAction = runTestXMLContextAction; } @Override public void addMainMenuItems(DefaultActionGroup testMainMenu) { - testMainMenu.add(runClassTestAction); - testMainMenu.add(runAllTestAction); - testMainMenu.add(runTestXMLAction); + testMainMenu.add(runClassContextTestAction); + testMainMenu.add(runAllContextTestAction); + testMainMenu.add(runTestXMLContextAction); } @Override diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllContextTestAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllContextTestAction.java deleted file mode 100644 index d3ccae98c64..00000000000 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllContextTestAction.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.testing.testng.ide.action; - -import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import javax.validation.constraints.NotNull; - -import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; -import org.eclipse.che.ide.api.action.ActionEvent; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.Container; -import org.eclipse.che.ide.api.resources.Project; -import org.eclipse.che.ide.api.selection.Selection; -import org.eclipse.che.ide.api.selection.SelectionAgent; -import org.eclipse.che.ide.resources.tree.ContainerNode; -import org.eclipse.che.ide.resources.tree.FileNode; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; -import org.eclipse.che.plugin.testing.testng.ide.TestNGLocalizationConstant; -import org.eclipse.che.plugin.testing.testng.ide.TestNGResources; - -import com.google.inject.Inject; - -/** - * @author Mirage Abeysekara - * @author David Festal - */ -public class RunAllContextTestAction extends AbstractPerspectiveAction - implements RunTestActionDelegate.Source { - - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; - private final AppContext appContext; - private final SelectionAgent selectionAgent; - private final RunTestActionDelegate delegate; - - @Inject - public RunAllContextTestAction(TestNGResources resources, - NotificationManager notificationManager, - AppContext appContext, - TestResultPresenter presenter, - TestServiceClient service, - SelectionAgent selectionAgent, - TestNGLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunAllTitle(), - localization.actionRunAllDescription(), null, resources.testAllIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; - this.appContext = appContext; - this.selectionAgent = selectionAgent; - this.delegate = new RunTestActionDelegate(this); - } - - @Override - public void actionPerformed(ActionEvent e) { - final Selection< ? > selection = selectionAgent.getSelection(); - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof ContainerNode) { - Container container = ((ContainerNode)possibleNode).getData(); - Project project = container.getProject(); - if (project != null) { - Map parameters = new HashMap<>(); - delegate.doRunTests(e, parameters); - } - } - } - - @Override - public void updateInPerspective(@NotNull ActionEvent e) { - e.getPresentation().setVisible(true); - if ((appContext.getRootProject() == null)) { - e.getPresentation().setEnabled(false); - return; - } - final Selection< ? > selection = selectionAgent.getSelection(); - if (selection == null || selection.isEmpty()) { - e.getPresentation().setEnabled(false); - return; - } - if (selection.isMultiSelection()) { - e.getPresentation().setEnabled(false); - return; - } - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof FileNode) { - e.getPresentation().setVisible(false); - } - if (possibleNode instanceof ContainerNode) { - Container container = ((ContainerNode)possibleNode).getData(); - Project project = container.getProject(); - if (project != null) { - String projectType = project.getType(); - boolean enable = "maven".equals(projectType); - e.getPresentation().setEnabled(enable); - return; - } - } - e.getPresentation().setEnabled(false); - } - - @Override - public NotificationManager getNotificationManager() { - return notificationManager; - } - - @Override - public AppContext getAppContext() { - return appContext; - } - - @Override - public TestServiceClient getService() { - return service; - } - - @Override - public TestResultPresenter getPresenter() { - return presenter; - } - - @Override - public String getTestingFramework() { - return "testng"; - } -} diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllTestAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllTestAction.java index 392f7207b56..91c02cf2a65 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunAllTestAction.java @@ -10,15 +10,20 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.testng.ide.action; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import javax.validation.constraints.NotNull; + +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.editor.EditorAgent; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.ext.java.client.action.JavaEditorAction; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.plugin.testing.ide.TestServiceClient; import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; @@ -29,38 +34,64 @@ /** * @author Mirage Abeysekara + * @author David Festal */ -public class RunAllTestAction extends JavaEditorAction +public class RunAllTestAction extends AbstractPerspectiveAction implements RunTestActionDelegate.Source { private final NotificationManager notificationManager; - private TestResultPresenter presenter; + private final TestResultPresenter presenter; private final TestServiceClient service; + private final AppContext appContext; private final RunTestActionDelegate delegate; @Inject public RunAllTestAction(TestNGResources resources, - NotificationManager notificationManager, - EditorAgent editorAgent, - TestResultPresenter presenter, - FileTypeRegistry fileTypeRegistry, - TestServiceClient service, - TestNGLocalizationConstant localization) { - super(localization.actionRunAllTitle(), localization.actionRunAllDescription(), resources.testAllIcon(), - editorAgent, fileTypeRegistry); + NotificationManager notificationManager, + AppContext appContext, + TestResultPresenter presenter, + TestServiceClient service, + TestNGLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunAllTitle(), + localization.actionRunAllDescription(), null, resources.testAllIcon()); this.notificationManager = notificationManager; this.presenter = presenter; this.service = service; + this.appContext = appContext; this.delegate = new RunTestActionDelegate(this); } - @Override public void actionPerformed(ActionEvent e) { - Map parameters = new HashMap<>(); - delegate.doRunTests(e, parameters); + Resource resource = appContext.getResource(); + if (resource != null) { + Project project = resource.getProject(); + if (project != null) { + Map parameters = new HashMap<>(); + delegate.doRunTests(e, parameters); + } + } } + @Override + public void updateInPerspective(@NotNull ActionEvent e) { + Resource resource = appContext.getResource(); + if (resource == null) { + e.getPresentation().setEnabledAndVisible(false); + } + + Project project = resource.getProject(); + if (project == null) { + e.getPresentation().setEnabledAndVisible(false); + } + + e.getPresentation().setVisible(true); + + String projectType = project.getType(); + boolean enable = "maven".equals(projectType); + e.getPresentation().setEnabled(enable); + } + @Override public NotificationManager getNotificationManager() { return notificationManager; diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassContextTestAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassContextTestAction.java deleted file mode 100644 index 471016f8bc5..00000000000 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassContextTestAction.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.testing.testng.ide.action; - -import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import javax.validation.constraints.NotNull; - -import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; -import org.eclipse.che.ide.api.action.ActionEvent; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.editor.EditorAgent; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.api.selection.Selection; -import org.eclipse.che.ide.api.selection.SelectionAgent; -import org.eclipse.che.ide.ext.java.client.util.JavaUtil; -import org.eclipse.che.ide.resources.tree.FileNode; -import org.eclipse.che.ide.rest.DtoUnmarshallerFactory; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; -import org.eclipse.che.plugin.testing.testng.ide.TestNGLocalizationConstant; -import org.eclipse.che.plugin.testing.testng.ide.TestNGResources; - -import com.google.inject.Inject; - -/** - * @author Mirage Abeysekara - */ -public class RunClassContextTestAction extends AbstractPerspectiveAction - implements RunTestActionDelegate.Source { - - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; - private final AppContext appContext; - private final SelectionAgent selectionAgent; - private final RunTestActionDelegate delegate; - - @Inject - public RunClassContextTestAction(TestNGResources resources, - NotificationManager notificationManager, - EditorAgent editorAgent, - AppContext appContext, - TestResultPresenter presenter, - TestServiceClient service, - DtoUnmarshallerFactory dtoUnmarshallerFactory, - SelectionAgent selectionAgent, - TestNGLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunClassContextTitle(), - localization.actionRunClassContextDescription(), null, resources.testIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; - this.appContext = appContext; - this.selectionAgent = selectionAgent; - this.delegate = new RunTestActionDelegate(this); - } - - @Override - public void actionPerformed(ActionEvent e) { - final Selection< ? > selection = selectionAgent.getSelection(); - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof FileNode) { - VirtualFile file = ((FileNode)possibleNode).getData(); - String fqn = JavaUtil.resolveFQN(file); - Map parameters = new HashMap<>(); - parameters.put("fqn", fqn); - parameters.put("runClass", "true"); - delegate.doRunTests(e, parameters); - } - } - - @Override - public void updateInPerspective(@NotNull ActionEvent e) { - if ((appContext.getRootProject() == null)) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - final Selection< ? > selection = selectionAgent.getSelection(); - if (selection == null || selection.isEmpty()) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - if (selection.isMultiSelection()) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - final Object possibleNode = selection.getHeadElement(); - if (!(possibleNode instanceof FileNode)) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - - e.getPresentation().setVisible(true); - boolean enable = "java".equals(((FileNode)possibleNode).getData().getExtension()); - e.getPresentation().setEnabled(enable); - } - - @Override - public NotificationManager getNotificationManager() { - return notificationManager; - } - - @Override - public AppContext getAppContext() { - return appContext; - } - - @Override - public TestServiceClient getService() { - return service; - } - - @Override - public TestResultPresenter getPresenter() { - return presenter; - } - - @Override - public String getTestingFramework() { - return "testng"; - } -} diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassTestAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassTestAction.java index 7cb2872686f..9642e1d6f24 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunClassTestAction.java @@ -10,18 +10,25 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.testng.ide.action; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import javax.validation.constraints.NotNull; + +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.editor.EditorAgent; -import org.eclipse.che.ide.api.editor.EditorPartPresenter; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.resources.File; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.ext.java.client.action.JavaEditorAction; import org.eclipse.che.ide.ext.java.client.util.JavaUtil; +import org.eclipse.che.ide.rest.DtoUnmarshallerFactory; import org.eclipse.che.plugin.testing.ide.TestServiceClient; import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; @@ -33,49 +40,70 @@ /** * @author Mirage Abeysekara */ -public class RunClassTestAction extends JavaEditorAction -implements RunTestActionDelegate.Source { +public class RunClassTestAction extends AbstractPerspectiveAction + implements RunTestActionDelegate.Source { - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; + private final NotificationManager notificationManager; + private final TestResultPresenter presenter; + private final TestServiceClient service; + private final AppContext appContext; private final RunTestActionDelegate delegate; @Inject public RunClassTestAction(TestNGResources resources, - NotificationManager notificationManager, - EditorAgent editorAgent, - FileTypeRegistry fileTypeRegistry, - TestResultPresenter presenter, - TestServiceClient service, - TestNGLocalizationConstant localization) { - super(localization.actionRunClassTitle(), localization.actionRunClassDescription(), resources.testIcon(), - editorAgent, fileTypeRegistry); + NotificationManager notificationManager, + EditorAgent editorAgent, + AppContext appContext, + TestResultPresenter presenter, + TestServiceClient service, + DtoUnmarshallerFactory dtoUnmarshallerFactory, + TestNGLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunClassTitle(), + localization.actionRunClassDescription(), null, resources.testIcon()); this.notificationManager = notificationManager; - this.editorAgent = editorAgent; this.presenter = presenter; this.service = service; + this.appContext = appContext; this.delegate = new RunTestActionDelegate(this); } @Override public void actionPerformed(ActionEvent e) { - Map parameters = new HashMap<>(); - EditorPartPresenter editorPart = editorAgent.getActiveEditor(); - final VirtualFile file = editorPart.getEditorInput().getFile(); - String fqn = JavaUtil.resolveFQN(file); - parameters.put("fqn", fqn); - parameters.put("runClass", "true"); - - delegate.doRunTests(e, parameters); + Resource resource = appContext.getResource(); + if (resource instanceof File) { + File file = ((File)resource); + String fqn = JavaUtil.resolveFQN((VirtualFile)file); + Map parameters = new HashMap<>(); + parameters.put("fqn", fqn); + parameters.put("runClass", "true"); + delegate.doRunTests(e, parameters); + } } @Override - protected void updateProjectAction(ActionEvent e) { - super.updateProjectAction(e); + public void updateInPerspective(@NotNull ActionEvent e) { + Resource resource = appContext.getResource(); + if (! (resource instanceof File)) { + e.getPresentation().setEnabledAndVisible(false); + return; + } + + Project project = resource.getProject(); + if (project == null) { + e.getPresentation().setEnabledAndVisible(false); + } + e.getPresentation().setVisible(true); + + String projectType = project.getType(); + if (! "maven".equals(projectType)) { + e.getPresentation().setEnabled(false); + } + + boolean enable = "java".equals(((File)resource).getExtension()); + e.getPresentation().setEnabled(enable); } - + @Override public NotificationManager getNotificationManager() { return notificationManager; diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLAction.java index 17ac8db0d0e..ef2baad5a56 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLAction.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLAction.java @@ -10,16 +10,21 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.testng.ide.action; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import javax.validation.constraints.NotNull; + +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.editor.EditorAgent; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.resources.File; import org.eclipse.che.ide.api.resources.Project; -import org.eclipse.che.ide.ext.java.client.action.JavaEditorAction; +import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.plugin.maven.shared.MavenAttributes; import org.eclipse.che.plugin.testing.ide.TestServiceClient; import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; @@ -31,44 +36,76 @@ /** * @author Mirage Abeysekara + * @author David Festal */ -public class RunTestXMLAction extends JavaEditorAction +public class RunTestXMLAction extends AbstractPerspectiveAction implements RunTestActionDelegate.Source { private final NotificationManager notificationManager; - private TestResultPresenter presenter; + private final TestResultPresenter presenter; private final TestServiceClient service; + private final AppContext appContext; private final RunTestActionDelegate delegate; @Inject public RunTestXMLAction(TestNGResources resources, - NotificationManager notificationManager, - EditorAgent editorAgent, - TestResultPresenter presenter, - FileTypeRegistry fileTypeRegistry, - TestServiceClient service, - TestNGLocalizationConstant localization) { - super(localization.actionRunXMLTitle(), localization.actionRunXMLDescription(), resources.testAllIcon(), - editorAgent, fileTypeRegistry); + NotificationManager notificationManager, + AppContext appContext, + TestResultPresenter presenter, + TestServiceClient service, + TestNGLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunXMLTitle(), + localization.actionRunXMLDescription(), null, resources.testAllIcon()); this.notificationManager = notificationManager; - this.editorAgent = editorAgent; this.presenter = presenter; this.service = service; + this.appContext = appContext; this.delegate = new RunTestActionDelegate(this); - } @Override public void actionPerformed(ActionEvent e) { - final Project project = appContext.getRootProject(); - Map parameters = new HashMap<>(); + Resource resource = appContext.getResource(); + if (resource != null) { + Project project = resource.getProject(); + if (project != null) { + Map parameters = new HashMap<>(); + parameters.put("testngXML", + project.getPath() + "/" + MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml"); + delegate.doRunTests(e, parameters); + } + } + } - parameters.put("testngXML", - project.getPath() + "/" + MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml"); + @Override + public void updateInPerspective(@NotNull ActionEvent e) { + Resource resource = appContext.getResource(); + if (resource == null) { + e.getPresentation().setEnabledAndVisible(false); + return; + } + + Project project = resource.getProject(); + if (project == null) { + e.getPresentation().setEnabledAndVisible(false); + } + + e.getPresentation().setVisible(true); - delegate.doRunTests(e, parameters); - } + String projectType = project.getType(); + if (! "maven".equals(projectType)) { + e.getPresentation().setEnabled(false); + } + String expectedXmlFile = MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml"; + if (resource instanceof File) { + File file = (File)resource; + e.getPresentation().setEnabled(file.getLocation().toString().endsWith(expectedXmlFile)); + } else { + e.getPresentation().setEnabled(true); + } + } + @Override public NotificationManager getNotificationManager() { return notificationManager; diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLContextAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLContextAction.java deleted file mode 100644 index 2929b3f6f35..00000000000 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/action/RunTestXMLContextAction.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.testing.testng.ide.action; - -import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import javax.validation.constraints.NotNull; - -import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; -import org.eclipse.che.ide.api.action.ActionEvent; -import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.Container; -import org.eclipse.che.ide.api.resources.File; -import org.eclipse.che.ide.api.resources.Project; -import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.api.selection.Selection; -import org.eclipse.che.ide.api.selection.SelectionAgent; -import org.eclipse.che.ide.resources.tree.ContainerNode; -import org.eclipse.che.ide.resources.tree.FileNode; -import org.eclipse.che.plugin.maven.shared.MavenAttributes; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.action.RunTestActionDelegate; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; -import org.eclipse.che.plugin.testing.testng.ide.TestNGLocalizationConstant; -import org.eclipse.che.plugin.testing.testng.ide.TestNGResources; - -import com.google.inject.Inject; - -/** - * @author Mirage Abeysekara - * @author David Festal - */ -public class RunTestXMLContextAction extends AbstractPerspectiveAction - implements RunTestActionDelegate.Source { - - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; - private final AppContext appContext; - private final SelectionAgent selectionAgent; - private final RunTestActionDelegate delegate; - - @Inject - public RunTestXMLContextAction(TestNGResources resources, - NotificationManager notificationManager, - AppContext appContext, - TestResultPresenter presenter, - TestServiceClient service, - SelectionAgent selectionAgent, - TestNGLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunXMLTitle(), - localization.actionRunXMLDescription(), null, resources.testAllIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; - this.appContext = appContext; - this.selectionAgent = selectionAgent; - this.delegate = new RunTestActionDelegate(this); - } - - @Override - public void actionPerformed(ActionEvent e) { - final Selection< ? > selection = selectionAgent.getSelection(); - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof ContainerNode) { - Container container = ((ContainerNode)possibleNode).getData(); - Project project = container.getProject(); - if (project != null) { - Map parameters = new HashMap<>(); - parameters.put("testngXML", - project.getPath() + "/" + MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml"); - delegate.doRunTests(e, parameters); - } - } - } - - @Override - public void updateInPerspective(@NotNull ActionEvent e) { - e.getPresentation().setEnabledAndVisible(false); - if ((appContext.getRootProject() == null)) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - final Selection< ? > selection = selectionAgent.getSelection(); - if (selection == null || selection.isEmpty()) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - if (selection.isMultiSelection()) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - String expectedXmlFile = MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml"; - final Object possibleNode = selection.getHeadElement(); - if (possibleNode instanceof FileNode) { - VirtualFile file = ((FileNode)possibleNode).getData(); - if (file instanceof File) { - e.getPresentation().setEnabledAndVisible(file.getLocation().toString().endsWith(expectedXmlFile)); - } else { - e.getPresentation().setEnabledAndVisible(false); - } - } - if (possibleNode instanceof ContainerNode) { - Container container = ((ContainerNode)possibleNode).getData(); - Project project = container.getProject(); - if (project != null) { - String projectType = project.getType(); - boolean enable = "maven".equals(projectType); - e.getPresentation().setEnabledAndVisible(enable); - return; - } else { - e.getPresentation().setEnabledAndVisible(false); - } - } - } - - @Override - public NotificationManager getNotificationManager() { - return notificationManager; - } - - @Override - public AppContext getAppContext() { - return appContext; - } - - @Override - public TestServiceClient getService() { - return service; - } - - @Override - public TestResultPresenter getPresenter() { - return presenter; - } - - @Override - public String getTestingFramework() { - return "testng"; - } -} diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/resources/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.properties b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/resources/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.properties index fa2c10fe469..bd9cdc5dcf0 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/resources/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.properties +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/resources/org/eclipse/che/plugin/testing/testng/ide/TestNGLocalizationConstant.properties @@ -13,14 +13,11 @@ ##### Actions ##### action.runClass.title = TestNG Class -action.runClass.description = Run the currently open TestNG test class - -action.runClassContext.title = TestNG Class -action.runClassContext.description = Run the TestNG test cases +action.runClass.description = Run the TestNG test cases action.runAll.title = TestNG Project action.runAll.description = Run all TestNG test cases action.runXML.title = TestNG XML Suite -action.runXML.description = Run TestNG XML Suite in testng.xml file +action.runXML.description = Run the TestNG XML Suite defined in testng.xml