Skip to content

Commit

Permalink
Java Testing support Bug fixes and Enhancements - Step 2 (eclipse-che…
Browse files Browse the repository at this point in the history
…#4481)

* Show all tests in the result view, but allow filtering successful tests
* Fix various navigation bugs from test view to source code
* Remove the invalid command preview added by default
* Fix https://issues.jboss.org/browse/CHE-149
Some Java Editor action were added in the explorer context menu, which
led to strange behaviors.
* Correctly propagate sevrer errors to the client status notifications
* Change contextual test menu to `Run Test`
Fixes [CHE-157](https://issues.jboss.org/browse/CHE-157)
* Compilation error after the *Intelligent Commands* changes

Signed-off-by: David Festal <[email protected]>

Conflicts:
	plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-server/pom.xml
	plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java
  • Loading branch information
davidfestal authored and sunix committed May 3, 2017
1 parent e745192 commit 34e3028
Show file tree
Hide file tree
Showing 42 changed files with 1,527 additions and 551 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-testing-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +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;
Expand All @@ -33,20 +34,23 @@ 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;
private final Action runClassContextTestAction;
private final Action runAllContextTestAction;

@Inject
public JUnitTestAction(ActionManager actionManager,
RunClassTestAction runClassTestAction,
RunAllTestAction runAllTestAction,
RunClassContextTestAction runClassContextTestAction,
RunAllContextTestAction 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);

if (UserAgent.isMac()) {
keyBinding.getGlobal().addKey(new KeyBuilder().control().alt().charCode('z').build(), TEST_ACTION_RUN_ALL);
Expand All @@ -59,6 +63,7 @@ public JUnitTestAction(ActionManager actionManager,
this.runAllTestAction = runAllTestAction;
this.runClassContextTestAction = runClassContextTestAction;
this.runClassTestAction = runClassTestAction;
this.runAllContextTestAction = runAllContextTestAction;
}


Expand All @@ -71,6 +76,6 @@ public void addMainMenuItems(DefaultActionGroup testMainMenu) {
@Override
public void addContextMenuItems(DefaultActionGroup testContextMenu) {
testContextMenu.add(runClassContextTestAction);
testContextMenu.add(runAllTestAction);
testContextMenu.add(runAllContextTestAction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*******************************************************************************
* 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<String, String> 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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.ext.java.client.action.JavaEditorAction;
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;
Expand Down Expand Up @@ -80,4 +81,9 @@ public TestServiceClient getService() {
public TestResultPresenter getPresenter() {
return presenter;
}

@Override
public String getTestingFramework() {
return "junit";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -83,22 +84,26 @@ public void actionPerformed(ActionEvent e) {
@Override
public void updateInPerspective(@NotNull ActionEvent e) {
if ((appContext.getRootProject() == null)) {
e.getPresentation().setVisible(true);
e.getPresentation().setEnabled(false);
e.getPresentation().setEnabledAndVisible(false);
return;
}
final Selection< ? > selection = selectionAgent.getSelection();
if (selection == null || selection.isEmpty()) {
e.getPresentation().setEnabled(false);
e.getPresentation().setEnabledAndVisible(false);
return;
}
if (selection.isMultiSelection()) {
e.getPresentation().setEnabled(false);
e.getPresentation().setEnabledAndVisible(false);
return;
}
final Object possibleNode = selection.getHeadElement();
boolean enable = possibleNode instanceof FileNode
&& "java".equals(((FileNode)possibleNode).getData().getExtension());
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);
}

Expand All @@ -121,4 +126,10 @@ public TestServiceClient getService() {
public TestResultPresenter getPresenter() {
return presenter;
}


@Override
public String getTestingFramework() {
return "junit";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
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;
Expand Down Expand Up @@ -67,7 +68,6 @@ public void actionPerformed(ActionEvent e) {
Map<String, String> parameters = new HashMap<>();
parameters.put("fqn", fqn);
parameters.put("runClass", "true");
parameters.put("updateClasspath", "true");
delegate.doRunTests(e, parameters);
}

Expand Down Expand Up @@ -96,4 +96,9 @@ public TestServiceClient getService() {
public TestResultPresenter getPresenter() {
return presenter;
}

@Override
public String getTestingFramework() {
return "junit";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
Expand Down Expand Up @@ -65,23 +61,5 @@
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/**/AbstractTestListener.java</exclude>
<exclude>**/**/OutputTestListener.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 34e3028

Please sign in to comment.