package io.vertigo.dashboard;

import java.util.Optional;

import org.h2.Driver;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

import io.vertigo.AbstractTestCaseJU4;
import io.vertigo.app.config.AppConfig;
import io.vertigo.app.config.ModuleConfig;
import io.vertigo.app.config.NodeConfig;
import io.vertigo.commons.impl.CommonsFeatures;
import io.vertigo.commons.plugins.analytics.log.SocketLoggerAnalyticsConnectorPlugin;
import io.vertigo.commons.plugins.cache.memory.MemoryCachePlugin;
import io.vertigo.core.param.Param;
import io.vertigo.core.plugins.resource.classpath.ClassPathResourceResolverPlugin;
import io.vertigo.database.DatabaseFeatures;
import io.vertigo.database.impl.sql.vendor.h2.H2DataBase;
import io.vertigo.database.plugins.sql.connection.c3p0.C3p0ConnectionProviderPlugin;
import io.vertigo.dynamo.impl.DynamoFeatures;
import io.vertigo.dynamo.plugins.search.elasticsearch.embedded.ESEmbeddedSearchServicesPlugin;
import io.vertigo.dynamo.plugins.store.datastore.sql.SqlDataStorePlugin;
import io.vertigo.dynamox.metric.domain.DomainMetricsProvider;
import io.vertigo.vega.VegaFeatures;

@RunWith(JUnitPlatform.class)
public class DashboardLauncherTest extends AbstractTestCaseJU4 {

	@Override
	protected AppConfig buildAppConfig() {
		return AppConfig.builder()
				.beginBoot()
				.addPlugin(ClassPathResourceResolverPlugin.class)
				.withLocales("fr_FR")
				.endBoot()
				.addModule(new CommonsFeatures()
						.withRedisConnector("redis-pic.part.klee.lan.net", 6379, 0, Optional.empty())
						.addAnalyticsConnectorPlugin(SocketLoggerAnalyticsConnectorPlugin.class)
						.withCache(MemoryCachePlugin.class)
						.build())
				.addModule(new DatabaseFeatures()
						.withSqlDataBase()
						.addSqlConnectionProviderPlugin(C3p0ConnectionProviderPlugin.class,
								Param.of("dataBaseClass", H2DataBase.class.getCanonicalName()),
								Param.of("jdbcDriver", Driver.class.getCanonicalName()),
								Param.of("jdbcUrl", "jdbc:h2:mem:database"))
						.build())
				.addModule(new DynamoFeatures()
						.withStore()
						.addDataStorePlugin(SqlDataStorePlugin.class,
								Param.of("sequencePrefix", "SEQ_"))
						.withSearch(ESEmbeddedSearchServicesPlugin.class,
								Param.of("home", "io/vertigo/dashboard/search/indexconfig"),
								Param.of("config.file", "io/vertigo/dashboard/search/indexconfig/elasticsearch.yml"),
								Param.of("envIndex", "TU_TEST"),
								Param.of("rowsPerQuery", "50"))
						.build())
				.addModule(new VegaFeatures()
						.withEmbeddedServer(8080)
						.build())
				.addModule(new DashboardFeatures()
						.withInfluxDb("http://analytica.part.klee.lan.net:8086", "analytica", "kleeklee")
						.build())
				.addModule(
						ModuleConfig.builder("metrics")
								.addComponent(DomainMetricsProvider.class)
								.build())
				.withNodeConfig(NodeConfig.builder()
						.withAppName("dashboardtest")
						.build())
				.build();
	}

	@Test
	public void server() {
		//		final App app = getApp();
		//		Dashboard.start(app);
		//		while (!Thread.interrupted()) {
		//			try {
		//				Thread.sleep(10 * 1000);
		//			} catch (final InterruptedException e) {
		//				e.printStackTrace();
		//			}
		//		}
	}

}

@@ -78,43 +78,8 @@
 er;%0A
-import org.junit.jupiter.api.Test;%0A
 impo
@@ -2960,15 +2960,21 @@
 %09%7D%0A%0A
+%09//
 %09@Test%0A
+%09//
 %09pub
@@ -2989,25 +2989,24 @@
  server() %7B%0A
-%09
 %09//%09%09final A
@@ -3020,25 +3020,24 @@
 = getApp();%0A
-%09
 %09//%09%09Dashboa
@@ -3051,17 +3051,16 @@
 t(app);%0A
-%09
 %09//%09%09whi
@@ -3084,25 +3084,24 @@
 rupted()) %7B%0A
-%09
 %09//%09%09%09try %7B%0A
@@ -3100,17 +3100,16 @@
 %09%09try %7B%0A
-%09
 %09//%09%09%09%09T
@@ -3132,17 +3132,16 @@
  1000);%0A
-%09
 %09//%09%09%09%7D 
@@ -3179,17 +3179,16 @@
 on e) %7B%0A
-%09
 %09//%09%09%09%09e
@@ -3211,17 +3211,16 @@
 ();%0A
-%09
 %09//%09%09%09%7D%0A
 %09%09//
@@ -3219,16 +3219,18 @@
 %09%09%7D%0A
-%09
 %09//%09%09%7D%0A
+%09//
 %09%7D%0A%0A

remove all tests