Skip to content

Commit

Permalink
Merge pull request #387 from authorjapps/post_process
Browse files Browse the repository at this point in the history
ISS-00 # Runner and Listener post finished - enhance UX
  • Loading branch information
authorjapps authored May 4, 2020
2 parents 282851c + 37da41e commit 69b5c8e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public void testRunFinished(Result result) {
LOGGER.info("#ZeroCode: Test run completed for this runner. Generating test reports and charts. " +
"\n* For more examples, helps, Kafka streams, APIs and Load use-cases visit https://zerocode.io");
generateChartsAndReports();
runPostFinished();
}

/**
* Override this to handle post-finished tasks
*/
public void runPostFinished() {
/*
* Do nothing for now
*/
}

private void generateChartsAndReports() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ZeroCodePackageRunner(Class<?> testClass) throws InitializationError {
}

protected SmartUtils getInjectedSmartUtilsClass() {
return getInjector().getInstance(SmartUtils.class);
return getMainModuleInjector().getInstance(SmartUtils.class);
}

@Inject
Expand Down Expand Up @@ -183,7 +183,9 @@ protected void runChild(ScenarioSpec child, RunNotifier notifier) {

}

public Injector getInjector() {
// This is exact duplicate of ZeroCodeUnitRunner.getMainModuleInjector
// Refactor and maintain a single method in RunnerUtils
public Injector getMainModuleInjector() {
//TODO: Synchronise this with e.g. synchronized (ZeroCodePackageRunner.class) {}
final TargetEnv envAnnotation = testClass.getAnnotation(TargetEnv.class);
String serverEnv = envAnnotation != null ? envAnnotation.value() : "config_hosts.properties";
Expand Down Expand Up @@ -221,12 +223,12 @@ public void setZeroCodeMultiStepsScenarioRunner(ZeroCodeMultiStepsScenarioRunner
}

private ZeroCodeMultiStepsScenarioRunner getInjectedMultiStepsRunner() {
zeroCodeMultiStepsScenarioRunner = getInjector().getInstance(ZeroCodeMultiStepsScenarioRunner.class);
zeroCodeMultiStepsScenarioRunner = getMainModuleInjector().getInstance(ZeroCodeMultiStepsScenarioRunner.class);
return zeroCodeMultiStepsScenarioRunner;
}

private ZeroCodeReportGenerator getInjectedReportGenerator() {
return getInjector().getInstance(ZeroCodeReportGenerator.class);
return getMainModuleInjector().getInstance(ZeroCodeReportGenerator.class);
}

private void handleNoRunListenerReport(ZeroCodeTestReportListener reportListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
import org.jsmart.zerocode.core.domain.Scenario;
import org.jsmart.zerocode.core.domain.ScenarioSpec;
import org.jsmart.zerocode.core.domain.TargetEnv;
import org.jsmart.zerocode.core.domain.UseHttpClient;
import org.jsmart.zerocode.core.domain.UseKafkaClient;
import org.jsmart.zerocode.core.domain.builders.ZeroCodeExecReportBuilder;
import org.jsmart.zerocode.core.domain.builders.ZeroCodeIoWriteBuilder;
import org.jsmart.zerocode.core.engine.listener.ZeroCodeTestReportListener;
import org.jsmart.zerocode.core.httpclient.BasicHttpClient;
import org.jsmart.zerocode.core.httpclient.ssl.SslTrustHttpClient;
import org.jsmart.zerocode.core.kafka.client.BasicKafkaClient;
import org.jsmart.zerocode.core.kafka.client.ZerocodeCustomKafkaClient;
import org.jsmart.zerocode.core.logbuilder.ZerocodeCorrelationshipLogger;
import org.jsmart.zerocode.core.report.ZeroCodeReportGenerator;
import org.jsmart.zerocode.core.utils.SmartUtils;
Expand All @@ -33,6 +29,7 @@
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
Expand All @@ -42,9 +39,9 @@
import org.slf4j.LoggerFactory;

import static java.lang.System.getProperty;
import static org.jsmart.zerocode.core.domain.builders.ZeroCodeExecReportBuilder.newInstance;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.CHARTS_AND_CSV;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.ZEROCODE_JUNIT;
import static org.jsmart.zerocode.core.domain.builders.ZeroCodeExecReportBuilder.newInstance;
import static org.jsmart.zerocode.core.utils.RunnerUtils.getCustomHttpClientOrDefault;
import static org.jsmart.zerocode.core.utils.RunnerUtils.getCustomKafkaClientOrDefault;
import static org.jsmart.zerocode.core.utils.RunnerUtils.getEnvSpecificConfigFile;
Expand Down Expand Up @@ -98,7 +95,7 @@ public ZeroCodeUnitRunner(Class<?> klass) throws InitializationError {

@Override
public void run(RunNotifier notifier) {
ZeroCodeTestReportListener reportListener = new ZeroCodeTestReportListener(smartUtils.getMapper(), getInjectedReportGenerator());
RunListener reportListener = createReportListener();

LOGGER.info("System property " + ZEROCODE_JUNIT + "=" + getProperty(ZEROCODE_JUNIT));
if (!CHARTS_AND_CSV.equals(getProperty(ZEROCODE_JUNIT))) {
Expand Down Expand Up @@ -171,6 +168,15 @@ public Injector getMainModuleInjector() {
}
}

/**
* Override this for Junit custom lister handling.
* End User experience can be enhanced via this
* @return An instance of the Junit RunListener
*/
protected RunListener createReportListener() {
return getMainModuleInjector().getInstance(ZeroCodeTestReportListener.class);
}

protected SmartUtils getInjectedSmartUtilsClass() {
return getMainModuleInjector().getInstance(SmartUtils.class);
}
Expand Down Expand Up @@ -319,7 +325,7 @@ private String prepareRequestReport(Description description) {
return logPrefixRelationshipId;
}

private void handleNoRunListenerReport(ZeroCodeTestReportListener reportListener) {
protected void handleNoRunListenerReport(RunListener reportListener) {
if (CHARTS_AND_CSV.equals(getProperty(ZEROCODE_JUNIT))) {
/**
* Gradle does not support JUnit RunListener. Hence Zerocode gracefully handled this
Expand All @@ -333,7 +339,12 @@ private void handleNoRunListenerReport(ZeroCodeTestReportListener reportListener
* - many more related tickets.
*/
LOGGER.debug("Bypassed JUnit RunListener [as configured by the build tool] to generate useful reports...");
reportListener.testRunFinished(new Result());
try {
reportListener.testRunFinished(new Result());
} catch (Exception e) {
LOGGER.error("### Exception occurred while handling non-maven(e.g. Gradle) report generation => " + e);
throw new RuntimeException(e);
}
}
}

Expand Down

0 comments on commit 69b5c8e

Please sign in to comment.