Skip to content

Commit

Permalink
CHE-5737: run custom set of tests (eclipse-che#5956)
Browse files Browse the repository at this point in the history
* CHE-5737: run custom set of tests

* CHE-5737: code cleanup

* CHE-5737: update test actions presentation
  • Loading branch information
Valeriy Svydenko authored and vparfonov committed Aug 17, 2017
1 parent 6792b2b commit 0d5648d
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -163,7 +164,7 @@ private ICompilationUnit findCompilationUnitByPath(IJavaProject javaProject, Str

String packagePath = packageRootPath.toOSString();
if (!packagePath.endsWith("/")) {
packagePath += "/";
packagePath += '/';
}

String pathToClass = filePath.substring(packagePath.length());
Expand Down Expand Up @@ -204,6 +205,8 @@ protected List<String> createTestSuite(TestExecutionContext context,
context.getFilePath(),
methodAnnotation,
classAnnotation);
case SET:
return convertClassesPathsToFqns(context.getListOfTestClasses(), javaProject);
case PROJECT:
return javaTestFinder.findClassesInProject(javaProject,
methodAnnotation,
Expand Down Expand Up @@ -242,4 +245,20 @@ private static boolean isPortAvailable(int port) {
private RuntimeException getRuntimeException(String filePath) {
return new RuntimeException("Can't find IClasspathEntry for path " + filePath);
}

private List<String> convertClassesPathsToFqns(List<String> testClasses, IJavaProject javaProject) {
if (testClasses == null) {
return emptyList();
}
List<String> result = new LinkedList<>();
for (String classPath : testClasses) {
ICompilationUnit compilationUnit = findCompilationUnitByPath(javaProject, classPath);
if (compilationUnit != null) {
IType primaryType = compilationUnit.findPrimaryType();
result.add(primaryType.getFullyQualifiedName());
}
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</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 @@ -14,7 +14,6 @@
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfigurationsManager;
import org.eclipse.che.ide.api.notification.NotificationManager;
Expand All @@ -27,8 +26,6 @@
import org.eclipse.che.plugin.testing.junit.ide.JUnitTestLocalizationConstant;
import org.eclipse.che.plugin.testing.junit.ide.JUnitTestResources;

import javax.validation.constraints.NotNull;

import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;

Expand Down Expand Up @@ -67,14 +64,4 @@ public void actionPerformed(ActionEvent e) {
actionPerformed(frameworkAndTestName, true);
}

@Override
public void updateInPerspective(@NotNull ActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setVisible(!isEditorInFocus);
if (!isEditorInFocus) {
analyzeProjectTreeSelection();
}
presentation.setEnabled(isEnable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfigurationsManager;
import org.eclipse.che.ide.api.notification.NotificationManager;
Expand All @@ -27,8 +26,6 @@
import org.eclipse.che.plugin.testing.junit.ide.JUnitTestLocalizationConstant;
import org.eclipse.che.plugin.testing.junit.ide.JUnitTestResources;

import javax.validation.constraints.NotNull;

import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;

Expand Down Expand Up @@ -68,13 +65,4 @@ public void actionPerformed(ActionEvent e) {
actionPerformed(frameworkAndTestName, false);
}

@Override
public void updateInPerspective(@NotNull ActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setVisible(!isEditorInFocus);
if (!isEditorInFocus) {
analyzeProjectTreeSelection();
}
presentation.setEnabled(isEnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</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 @@ -14,7 +14,6 @@
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfigurationsManager;
import org.eclipse.che.ide.api.notification.NotificationManager;
Expand All @@ -27,8 +26,6 @@
import org.eclipse.che.plugin.testing.testng.ide.TestNgLocalizationConstant;
import org.eclipse.che.plugin.testing.testng.ide.TestNgResources;

import javax.validation.constraints.NotNull;

import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;

Expand Down Expand Up @@ -67,13 +64,4 @@ public void actionPerformed(ActionEvent e) {
actionPerformed(frameworkAndTestName, true);
}

@Override
public void updateInPerspective(@NotNull ActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setVisible(!isEditorInFocus);
if (!isEditorInFocus) {
analyzeProjectTreeSelection();
}
presentation.setEnabled(isEnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfigurationsManager;
import org.eclipse.che.ide.api.notification.NotificationManager;
Expand All @@ -27,8 +26,6 @@
import org.eclipse.che.plugin.testing.testng.ide.TestNgLocalizationConstant;
import org.eclipse.che.plugin.testing.testng.ide.TestNgResources;

import javax.validation.constraints.NotNull;

import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;

Expand Down Expand Up @@ -67,13 +64,4 @@ public void actionPerformed(ActionEvent e) {
actionPerformed(frameworkAndTestName, false);
}

@Override
public void updateInPerspective(@NotNull ActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setVisible(!isEditorInFocus);
if (!isEditorInFocus) {
analyzeProjectTreeSelection();
}
presentation.setEnabled(isEnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private Map<String, List<String>> buildTestNgSuite(List<String> tests, TestExecu
switch (context.getContextType()) {
case FILE:
case FOLDER:
case SET:
case PROJECT:
return createContainerSuite(tests);
case CURSOR_POSITION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfiguration;
import org.eclipse.che.ide.api.debug.DebugConfigurationsManager;
Expand All @@ -37,6 +38,7 @@
import org.eclipse.che.ide.ext.java.client.editor.JavaReconsilerEvent;
import org.eclipse.che.ide.ext.java.client.resource.SourceFolderMarker;
import org.eclipse.che.ide.ext.java.client.util.JavaUtil;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.util.Pair;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.plugin.testing.ide.TestServiceClient;
Expand Down Expand Up @@ -74,6 +76,7 @@ public abstract class RunDebugTestAbstractAction extends AbstractPerspectiveActi
private NotificationManager notificationManager;
private TestExecutionContext.ContextType contextType;
private String selectedNodePath;
private PartPresenter activePart;

protected boolean isEnable;
protected boolean isEditorInFocus;
Expand Down Expand Up @@ -103,7 +106,7 @@ public RunDebugTestAbstractAction(EventBus eventBus,

eventBus.addHandler(JavaReconsilerEvent.TYPE, event -> detectTests(event.getEditor()));
eventBus.addHandler(ActivePartChangedEvent.TYPE, event -> {
PartPresenter activePart = event.getActivePart();
activePart = event.getActivePart();
if (activePart instanceof TextEditor) {
isEditorInFocus = true;
contextType = CURSOR_POSITION;
Expand All @@ -120,7 +123,18 @@ public RunDebugTestAbstractAction(EventBus eventBus,
}

@Override
public abstract void updateInPerspective(@NotNull ActionEvent event);
public void updateInPerspective(@NotNull ActionEvent event) {
Presentation presentation = event.getPresentation();
boolean isProjectExplorerActive = activePart instanceof ProjectExplorerPresenter;
presentation.setVisible(isProjectExplorerActive);
if (!isProjectExplorerActive) {
return;
}
if (!isEditorInFocus) {
analyzeProjectTreeSelection();
}
presentation.setEnabled(isEnable);
}

@Override
public abstract void actionPerformed(ActionEvent e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public void onTestFailed(TestFailedEvent event) {

TestState testState = getStateByStateName(name);
if (testState == null) {
Log.error(getClass(), "Test wasn't started: " + name);
onTestStarted(new TestStartedEvent(name, null));
testState = getStateByStateName(name);
}
Expand All @@ -225,7 +224,6 @@ public void onTestFinished(TestFinishedEvent event) {
TestState testState = getStateByStateName(name);

if (testState == null) {
Log.error(getClass(), "Test wasn't started: " + name);
return;
}

Expand All @@ -245,7 +243,6 @@ public void onTestIgnored(TestIgnoredEvent event) {
TestState testState = getStateByStateName(name);

if (testState == null) {
Log.error(getClass(), "Test wasn't started: " + name);
onTestStarted(new TestStartedEvent(name, null));
testState = getStateByStateName(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.che.plugin.testing.ide.model;

import org.eclipse.che.ide.util.loging.Log;

import java.util.ArrayDeque;
import java.util.Deque;

Expand Down Expand Up @@ -69,7 +67,6 @@ public TestState getCurrent() {
*/
public TestState pop(String suiteName) {
if (stack.isEmpty()) {
Log.error(getClass(), "Test suite stack is empty, unexpected suite name: " + suiteName);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import org.eclipse.che.dto.shared.DTO;

import java.util.List;

/**
* Context which provides information about test execution.
*/
Expand Down Expand Up @@ -50,7 +52,17 @@ public interface TestExecutionContext {

TestExecutionContext withDebugModeEnable(Boolean enable);

/**
* returns a list with paths of the test files relative to the project.
* The list should be initialized when value of {@link ContextType} is {@link ContextType.SET}
*
* @param listOfTestClasses
*/
void setListOfTestClasses(List<String> listOfTestClasses);

List<String> getListOfTestClasses();

enum ContextType {
FILE, FOLDER, PROJECT, CURSOR_POSITION
FILE, FOLDER, PROJECT, CURSOR_POSITION, SET
}
}

0 comments on commit 0d5648d

Please sign in to comment.