package it.reply.orchestrator.config;

import it.reply.workflowmanager.spring.orchestrator.annotations.WorkflowPersistenceUnit;
import it.reply.workflowmanager.utils.Constants;

import org.h2.tools.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.sql.SQLException;

import javax.annotation.Resource;
import javax.naming.NamingException;
import javax.sql.DataSource;

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
public class WorklfowPersistenceConfigTest {

  @Resource
  private Environment environment;

  @Bean(destroyMethod = "shutdown")
  public DataSource workflowDataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase dataSource =
        builder.setType(EmbeddedDatabaseType.H2).addScripts("h2-jbpm-schema.sql").build();
    return dataSource;
  }

  @Bean(initMethod = "start", destroyMethod = "stop")
  public Server h2WebServer() throws SQLException {
    return Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082");
  }

  @Bean
  @WorkflowPersistenceUnit
  public LocalContainerEntityManagerFactoryBean workflowEntityManagerFactory()
      throws NamingException {
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setPersistenceUnitName(Constants.PERSISTENCE_UNIT_NAME);
    factory.setPersistenceXmlLocation("classpath:/META-INF/persistence-test.xml");
    factory.setJtaDataSource(workflowDataSource());
    return factory;
  }
}

@@ -180,37 +180,8 @@
 %0D%0A%0D%0A
-import org.h2.tools.Server;%0D%0A
 impo
@@ -225,24 +225,24 @@
 tion.Bean;%0D%0A
+
 import org.s
@@ -727,41 +727,8 @@
 %0D%0A%0D%0A
-import java.sql.SQLException;%0D%0A%0D%0A
 impo
@@ -1304,24 +1304,27 @@
 e;%0D%0A  %7D%0D%0A%0D%0A 
+ //
  @Bean(initM
@@ -1362,24 +1362,27 @@
 = %22stop%22)%0D%0A 
+ //
  public Serv
@@ -1419,25 +1419,26 @@
 eption %7B%0D%0A  
- 
+//
  return Serv
@@ -1502,24 +1502,27 @@
  %228082%22);%0D%0A 
+ //
  %7D%0D%0A%0D%0A  @Bea

Remove H2 db inspection web service