use of org.eclipse.che.plugin.testing.classpath.server.TestClasspathProvider in project che by eclipse.
the class JUnitTestRunner method execute.
/**
* {@inheritDoc}
*/
@Override
public TestResult execute(Map<String, String> testParameters) throws Exception {
String projectAbsolutePath = testParameters.get("absoluteProjectPath");
boolean updateClasspath = Boolean.valueOf(testParameters.get("updateClasspath"));
boolean runClass = Boolean.valueOf(testParameters.get("runClass"));
String projectPath = testParameters.get("projectPath");
String projectType = "";
if (projectManager != null) {
projectType = projectManager.getProject(projectPath).getType();
}
ClassLoader currentClassLoader = this.getClass().getClassLoader();
TestClasspathProvider classpathProvider = classpathRegistry.getTestClasspathProvider(projectType);
URLClassLoader providedClassLoader = (URLClassLoader) classpathProvider.getClassLoader(projectAbsolutePath, projectPath, updateClasspath);
projectClassLoader = new URLClassLoader(providedClassLoader.getURLs(), null) {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.startsWith("javassist.")) {
return currentClassLoader.loadClass(name);
}
return super.findClass(name);
}
};
boolean isJUnit4Compatible = false;
boolean isJUnit3Compatible = false;
try {
Class.forName(JUNIT4X_RUNNER_CLASS, true, projectClassLoader);
isJUnit4Compatible = true;
} catch (Exception ignored) {
}
try {
Class.forName(JUNIT3X_RUNNER_CLASS, true, projectClassLoader);
isJUnit3Compatible = true;
} catch (Exception ignored) {
}
boolean useJUnitV3API = false;
if (!isJUnit4Compatible) {
if (!isJUnit3Compatible) {
throw new ClassNotFoundException("JUnit classes not found in the following project classpath: " + Arrays.asList(providedClassLoader.getURLs()));
} else {
useJUnitV3API = true;
}
}
String currentWorkingDir = System.getProperty("user.dir");
try {
System.setProperty("user.dir", projectAbsolutePath);
TestResult testResult;
if (runClass) {
String fqn = testParameters.get("fqn");
testResult = useJUnitV3API ? run3x(fqn) : run4x(fqn);
} else {
testResult = useJUnitV3API ? runAll3x(projectAbsolutePath) : runAll4x(projectAbsolutePath);
}
return testResult;
} finally {
System.setProperty("user.dir", currentWorkingDir);
}
}
use of org.eclipse.che.plugin.testing.classpath.server.TestClasspathProvider in project che by eclipse.
the class TestNGRunner method execute.
/**
* {@inheritDoc}
*/
@Override
public TestResult execute(Map<String, String> testParameters) throws Exception {
String projectAbsolutePath = testParameters.get("absoluteProjectPath");
String xmlPath = testParameters.get("testngXML");
boolean updateClasspath = Boolean.valueOf(testParameters.get("updateClasspath"));
boolean runClass = Boolean.valueOf(testParameters.get("runClass"));
String projectPath = testParameters.get("projectPath");
String projectType = "";
if (projectManager != null) {
projectType = projectManager.getProject(projectPath).getType();
}
TestClasspathProvider classpathProvider = classpathRegistry.getTestClasspathProvider(projectType);
projectClassLoader = classpathProvider.getClassLoader(projectAbsolutePath, projectPath, updateClasspath);
TestResult testResult;
if (runClass) {
String fqn = testParameters.get("fqn");
testResult = run(projectAbsolutePath, fqn);
} else {
if (xmlPath == null) {
testResult = runAll(projectAbsolutePath);
} else {
testResult = runTestXML(projectAbsolutePath, ResourcesPlugin.getPathToWorkspace() + xmlPath);
}
}
return testResult;
}
Aggregations