|
|
@ -17,18 +17,19 @@
|
|
|
|
package org.springframework.boot.cli.command.test;
|
|
|
|
package org.springframework.boot.cli.command.test;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.cli.compiler.GroovyCompiler;
|
|
|
|
import org.springframework.boot.cli.compiler.GroovyCompiler;
|
|
|
|
import org.springframework.boot.groovy.DelegateTestRunner;
|
|
|
|
import org.springframework.boot.groovy.DelegateTestRunner;
|
|
|
|
|
|
|
|
import org.springframework.util.ReflectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Compile and run groovy based tests.
|
|
|
|
* Compile and run groovy based tests.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
|
|
|
* @author Graeme Rocher
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class TestRunner {
|
|
|
|
public class TestRunner {
|
|
|
|
|
|
|
|
|
|
|
@ -63,17 +64,16 @@ public class TestRunner {
|
|
|
|
runThread.start();
|
|
|
|
runThread.start();
|
|
|
|
runThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
|
|
runThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void uncaughtException(Thread t, Throwable e) {
|
|
|
|
public void uncaughtException(Thread t, Throwable ex) {
|
|
|
|
// rethrow exception
|
|
|
|
TestRunner.this.threadException = ex;
|
|
|
|
threadException = e;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
runThread.join();
|
|
|
|
runThread.join();
|
|
|
|
if(threadException != null) {
|
|
|
|
if (this.threadException != null) {
|
|
|
|
Throwable t = threadException;
|
|
|
|
TestFailedException ex = new TestFailedException(this.threadException);
|
|
|
|
threadException = null;
|
|
|
|
this.threadException = null;
|
|
|
|
throw new TestFailedException(t);
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -150,30 +150,22 @@ public class TestRunner {
|
|
|
|
ClassLoader contextClassLoader = Thread.currentThread()
|
|
|
|
ClassLoader contextClassLoader = Thread.currentThread()
|
|
|
|
.getContextClassLoader();
|
|
|
|
.getContextClassLoader();
|
|
|
|
Class<?> delegateClass = contextClassLoader
|
|
|
|
Class<?> delegateClass = contextClassLoader
|
|
|
|
.loadClass(DelegateTestRunner.class.getName());
|
|
|
|
.loadClass(DelegateTestRunner.class.getName());
|
|
|
|
Class resultClass = contextClassLoader.loadClass("org.junit.runner.Result");
|
|
|
|
Class<?> resultClass = contextClassLoader
|
|
|
|
Method runMethod = delegateClass.getMethod("run", Class[].class, resultClass);
|
|
|
|
.loadClass("org.junit.runner.Result");
|
|
|
|
|
|
|
|
Method runMethod = delegateClass.getMethod("run", Class[].class,
|
|
|
|
|
|
|
|
resultClass);
|
|
|
|
Object result = resultClass.newInstance();
|
|
|
|
Object result = resultClass.newInstance();
|
|
|
|
runMethod.invoke(null, this.testClasses, result);
|
|
|
|
runMethod.invoke(null, this.testClasses, result);
|
|
|
|
Boolean wasSuccessful = (Boolean)resultClass.getMethod("wasSuccessful").invoke(result);
|
|
|
|
boolean wasSuccessful = (Boolean) resultClass.getMethod(
|
|
|
|
if(!wasSuccessful) {
|
|
|
|
"wasSuccessful").invoke(result);
|
|
|
|
try {
|
|
|
|
if (!wasSuccessful) {
|
|
|
|
throw new RuntimeException("Tests Failed.");
|
|
|
|
throw new RuntimeException("Tests Failed.");
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
|
|
|
|
throw new RuntimeException(throwable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
}
|
|
|
|
throw new RuntimeException("Exception occurred running tests: " + e.getMessage(), e);
|
|
|
|
catch (Exception ex) {
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
ReflectionUtils.rethrowRuntimeException(ex);
|
|
|
|
throw new RuntimeException("Exception occurred running tests: " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (InstantiationException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException("Exception occurred running tests: " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException("Exception occurred running tests: " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException("Exception occurred running tests: " + e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|