package com.eactive.eai.transformer;

import java.io.PrintWriter;

import org.junit.platform.engine.DiscoverySelector;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;

import com.eactive.eai.common.util.Logger;

class AllTests {
	protected static Logger logger = Logger.getLogger("transformer");

	public static void setSystemPropertyIfNull(String key, String value) {
		if (System.getProperties().contains(key) == false) {
			System.setProperty(key, value);
		}
	}

	public static void setParams() {
		System.setProperty("module", "TEST_EXCEL");
		System.setProperty("eai.tableowner", "EAI");
		System.setProperty("prefix", "local.eai.mariadb");
	}

	public static void main(String[] args) {
		/**
		 * set module
		 */
		setParams();
		System.setProperty("transformer.rule.dir", "D:\\TransformRule");
		System.setProperty("transformer.string.trimend", "true");
		System.setProperty("transformer.validation", "false");
		System.setProperty("transformer.decimalpoint.add", "false");

		System.setProperty(SystemKeys.TRANSFROMER_LAYOUT_CACHE_INIT_ONSTARTUP, "true");

		DiscoverySelector[] discoverySelectors = new DiscoverySelector[] {
				DiscoverySelectors.selectClass(TransformXmlVarGridTest.class)
//				, DiscoverySelectors.selectClass(TransformXmlTest.class) 
//				, DiscoverySelectors.selectClass(TransformJsonMultiGridTest.class) 
//				, DiscoverySelectors.selectClass(TransformJsonMixedGridTest.class) 
//				, DiscoverySelectors.selectClass(TransformAggTest.class) 
//				, DiscoverySelectors.selectClass(TransformJsonDoubleGridTest.class) 
//				, DiscoverySelectors.selectClass(TransformGvAttrTest.class)
//				, DiscoverySelectors.selectClass(TransformMessageLoadTest.class)
		};
		LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(discoverySelectors)
				.build();

		Launcher launcher = LauncherFactory.create();
		SummaryGeneratingListener listener = new SummaryGeneratingListener();

		launcher.registerTestExecutionListeners(listener);
		launcher.execute(request);
		TestExecutionSummary summary = listener.getSummary();
		summary.getTestsFailedCount();

		try (PrintWriter out = new PrintWriter(System.out)) {
			summary.printTo(out);
		}
	}

}
