Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#782: The testClass is optional as we want to allow the junit plugin …
…in the ui, to select tests to run.
  • Loading branch information
davsclaus committed Dec 6, 2013
1 parent 6494a5e commit a6986be
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions hawtio-maven-plugin/src/main/java/io/hawt/maven/TestMojo.java
Expand Up @@ -37,7 +37,7 @@
@Execute(phase = LifecyclePhase.PROCESS_TEST_CLASSES)
public class TestMojo extends CamelMojo {

@Parameter(property = "hawtio.className", required = true)
@Parameter(property = "hawtio.className")
private String className;

@Parameter(property = "hawtio.testName")
Expand Down Expand Up @@ -71,26 +71,31 @@ protected void addCustomClasspaths(Set<URL> classpathURLs, boolean first) throws

@Override
protected void afterBootstrapMain() throws Exception {
// must load class and methods using reflection as otherwise we have class-loader/compiled class issues
getLog().info("*************************************");
getLog().info("Testing: " + className);
getLog().info("*************************************");

Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
Object instance = ReflectionHelper.newInstance(clazz);
getLog().debug("Loaded " + className + " and instantiated " + instance);

ReflectionHelper.invokeMethod(jUnitService.findBeforeClass(clazz), instance);
ReflectionHelper.invokeMethod(jUnitService.findBefore(clazz), instance);

// loop all test methods
List<Method> testMethods = jUnitService.findTestMethods(clazz);
testMethods = jUnitService.filterTestMethods(testMethods, testName);
getLog().info("Found and filtered " + testMethods.size() + " @Test methods to invoke");

for (Method testMethod : testMethods) {
getLog().info("Invoking @Test method " + testMethod + " on " + className);
ReflectionHelper.invokeMethod(testMethod, instance);
Class clazz = null;
Object instance = null;

if (className != null) {
// must load class and methods using reflection as otherwise we have class-loader/compiled class issues
getLog().info("*************************************");
getLog().info("Testing: " + className);
getLog().info("*************************************");

clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
instance = ReflectionHelper.newInstance(clazz);
getLog().debug("Loaded " + className + " and instantiated " + instance);

ReflectionHelper.invokeMethod(jUnitService.findBeforeClass(clazz), instance);
ReflectionHelper.invokeMethod(jUnitService.findBefore(clazz), instance);

// loop all test methods
List<Method> testMethods = jUnitService.findTestMethods(clazz);
testMethods = jUnitService.filterTestMethods(testMethods, testName);
getLog().info("Found and filtered " + testMethods.size() + " @Test methods to invoke");

for (Method testMethod : testMethods) {
getLog().info("Invoking @Test method " + testMethod + " on " + className);
ReflectionHelper.invokeMethod(testMethod, instance);
}
}

getLog().info("*************************************");
Expand All @@ -99,8 +104,10 @@ protected void afterBootstrapMain() throws Exception {
Console console = System.console();
console.readLine();

ReflectionHelper.invokeMethod(jUnitService.findAfter(clazz), instance);
ReflectionHelper.invokeMethod(jUnitService.findAfterClass(clazz), instance);
if (className != null) {
ReflectionHelper.invokeMethod(jUnitService.findAfter(clazz), instance);
ReflectionHelper.invokeMethod(jUnitService.findAfterClass(clazz), instance);
}
}

}

0 comments on commit a6986be

Please sign in to comment.