Author: gk
Date: Tue Jan  7 14:08:40 2020
New Revision: 1872442

URL: http://svn.apache.org/viewvc?rev=1872442&view=rev
Log:
- cleanup code, use intermediate parent class DockerDatabaseAbstractExtension 
for configuration docker database
- add some docker-testcontainer info in site
- add Documented to annotations

Added:
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerDatabaseAbstractExtension.java
   (with props)
Modified:
    
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/developer-guide.xml
    
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/test-project.xml
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallback.java
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackExtension.java
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackMySQLExtension.java
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackPostgreSQLExtension.java
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerMySQLCallback.java
    
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerPostGresCallback.java

Modified: 
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/developer-guide.xml
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/developer-guide.xml?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/developer-guide.xml
 (original)
+++ 
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/developer-guide.xml
 Tue Jan  7 14:08:40 2020
@@ -34,8 +34,7 @@
     <section name="Building from SVN">
       <p>
         The Torque build process uses 
-        <a href="http://maven.apache.org";>Maven 3</a> for building;
-        the recommended version is Maven 3.2.3.
+        <a href="http://maven.apache.org";>Maven 3</a> for building.
         <br/>
         You need to check out the <code>torque4/trunk</code> 
         part of the <code>db/torque</code> SVN repository.
@@ -47,7 +46,7 @@
         <p>
           Change into the directory into which you checked out the
           torque 4 trunk. Run <code>mvn install</code>.
-          The runtime, generator, templates, maven 2 generator plugin
+          The runtime, generator, templates, maven 3 generator plugin
           and ant tasks will be built in turn and installed
           in your local maven 2 repository.
         </p>
@@ -121,6 +120,10 @@
             That's it.
           </li>
         </ul>
+       To later change or update a project change into the module directory 
and run 
+       <code>mvn eclipse:eclipse</code>.
+       or in case of the "special" test module torque-test run 
+       <code>mvn -Phsqldb eclipse:configure-workspace eclipse:clean 
eclipse:eclipse</code>.
       </subsection>
     </section>
 

Modified: 
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/test-project.xml
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/test-project.xml?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/test-project.xml
 (original)
+++ 
db/torque/torque4/trunk/torque-site/src/site/xdoc/developer-info/test-project.xml
 Tue Jan  7 14:08:40 2020
@@ -54,7 +54,7 @@
     </section>
     <section name="Running the test project">
       <p>
-        In order to run the test project using maven 2, use the following 
+        In order to run the test project using maven, use the following 
         procedure:
         <ul>
           <li>
@@ -85,6 +85,21 @@
             For example, if you want to test against mysql, run
             <code>mvn -Pmysql clean test</code>.
           </li>
+          <li>
+            If you do not want or have a database installed locally, you may 
use the docker-testcontainer profile. 
+            Run the command <code>mvn 
-P${profile},docker-testcontainer,managers,beans clean test</code>
+            to run some tests*, replacing the variable 
+            <code>${profile}</code> with the name of your chosen database
+            profile. Currently only mysql and postgresql type is 
supported.<br/>
+            For example, if you want to test against mysql, run
+            <code>mvn -Pmysql,docker-testcontainer,managers,beans clean 
test</code>.
+            * JUnit 5 not yet supports test suites, only some selected tests 
are triggered 
+            (see package org.apache.torque.testcontainer).
+            Hint (e.g. if adding new database profile): To test local 
Dockerfile run it locally to shortcut / 
+            exclude other failures e.g. in docker-test/target directory with 
+            <code>docker build -t build -f Dockerfile  ./ </code> and 
inspecting the image with on the fly container:
+            <code>docker run --rm -it build bash</code>.
+          </li>
         </ul>
       </p>
       <p>

Modified: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallback.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallback.java?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallback.java
 (original)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallback.java
 Tue Jan  7 14:08:40 2020
@@ -35,9 +35,9 @@ import org.testcontainers.junit.jupiter.
  * {@code @DockerCallback} is used to signal that the annotated test class or
  * test method is using Docker {@link Testcontainers} and Torque initialized 
accordingly.
  * 
- * It is currently enabled by overridign the default
+ * It is currently enabled by overriding the default
  * 
- * @author gkallidis
+ * @author gk
  *
  */
 // may have ParameterizedTest in test class -> Possible configuration error

Modified: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackExtension.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackExtension.java?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackExtension.java
 (original)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackExtension.java
 Tue Jan  7 14:08:40 2020
@@ -44,20 +44,22 @@ import org.apache.torque.TorqueException
 import org.apache.torque.adapter.Adapter;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
 import org.junit.jupiter.api.extension.ConditionEvaluationResult;
 import org.junit.jupiter.api.extension.ExecutionCondition;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
 
 /**
- * Docker Test configuration
+ * Docker Test configuration, updates Torque configuration files in {@link 
#getTargetFileName()}, 
+ * which is set by database or default annotation {@link 
DockerCallback#targetFileName()}.
+ * 
+ * Uses by default a base configuration found in 
<code>src/test/profile/%s/Torque4Test.xml</code>.
  * 
  * @author gk
  *
  */
 
-public class DockerCallbackExtension implements BeforeAllCallback, 
BeforeTestExecutionCallback, ExecutionCondition {
+public class DockerCallbackExtension implements BeforeAllCallback, 
ExecutionCondition {
 
     protected static final String DEFAULT_TEST_PROFILE_TORQUE4_TEST_XML = 
"src/test/profile/%s/Torque4Test.xml";
 
@@ -65,7 +67,6 @@ public class DockerCallbackExtension imp
 
     private static Logger log = LogManager.getLogger();
 
-    protected static int SERVICE_PORT = 3306;
     protected static Adapter defaultAdapter;
     
     private String adapterProfileFallback;
@@ -126,11 +127,6 @@ public class DockerCallbackExtension imp
     }
     
     
-    @Override
-    public void beforeTestExecution(ExtensionContext context) throws Exception 
{
-        // log.info("starting call test context "+ context);
-    }
-    
     protected void torqueInit(ExtensionContext context)
             throws TorqueException, UnsupportedOperationException, 
IOException, InterruptedException {
 

Modified: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackMySQLExtension.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackMySQLExtension.java?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackMySQLExtension.java
 (original)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackMySQLExtension.java
 Tue Jan  7 14:08:40 2020
@@ -22,11 +22,9 @@ package org.apache.torque.testcontainer.
 import static 
org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
 
 import java.io.File;
-import java.io.IOException;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.apache.torque.TorqueException;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
@@ -35,41 +33,41 @@ import org.junit.jupiter.api.extension.E
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
 import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.output.Slf4jLogConsumer;
-import org.testcontainers.containers.wait.strategy.Wait;
 import org.testcontainers.images.builder.ImageFromDockerfile;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 
 /**
- * Testcontainer configuration
+ * Testcontainer configuration for database Mysql
+ * 
+ * Requires some configuration data found for example in {@link 
DockerMySQLCallback}.
  * 
  * @author gk
  *
  */
 @Testcontainers
-public class DockerCallbackMySQLExtension extends DockerCallbackExtension 
implements BeforeAllCallback, BeforeTestExecutionCallback, ExecutionCondition {
-
-    private static Logger log = LogManager.getLogger();
+public class DockerCallbackMySQLExtension extends 
DockerDatabaseAbstractExtension implements BeforeAllCallback, 
BeforeTestExecutionCallback, ExecutionCondition {
 
-    private static int SERVICE_PORT = 3306;
+    static Logger log = LogManager.getLogger();
     
-    protected static String DATABASE_NAME = "bookstore";
-
-    // copied from src/test/profile/mysql/docker-resources/db/
-    protected static final String DOCKERFILE = "./target/Dockerfile";
-
-    protected static final ConditionEvaluationResult ENABLED_BY_DEFAULT = 
enabled(
-            "DockerCallbackExtension is enabled by default - checking internal 
state only");
+    private static int SERVICE_PORT = 3306;
 
     @Container
     public static GenericContainer DATABASE_CONTAINER = new GenericContainer<>(
-            new ImageFromDockerfile().withDockerfile(new 
File(DOCKERFILE).toPath())).withExposedPorts(SERVICE_PORT) 
-                    .withEnv("MYSQL_DATABASE", 
DATABASE_NAME).withEnv("MYSQL_USER", "torque")
-                    .withEnv("MYSQL_PASSWORD", 
"torque").withEnv("MYSQL_ROOT_PASSWORD", "torque");
-                    //.withLogConsumer(new Slf4jLogConsumer(log));;
+                new ImageFromDockerfile().withDockerfile(new 
File(DOCKERFILE).toPath())).withExposedPorts(SERVICE_PORT) 
+                        .withEnv("MYSQL_DATABASE", 
DATABASE_NAME).withEnv("MYSQL_USER", "torque")
+                        .withEnv("MYSQL_PASSWORD", 
"torque").withEnv("MYSQL_ROOT_PASSWORD", "torque");
 
+    
+    public DockerCallbackMySQLExtension() {
+       setDbContainer(DATABASE_CONTAINER);
+       setServicePort(SERVICE_PORT);
+    }
+    
+    protected static final ConditionEvaluationResult ENABLED_BY_DEFAULT = 
enabled(
+            "DockerCallbackExtension is enabled by default - checking internal 
state only");
 
+    @Override
     public ConditionEvaluationResult 
evaluateExecutionCondition(ExtensionContext context) {
         String actual = System.getProperty("torque.callback");
         if (actual == null) {
@@ -89,65 +87,34 @@ public class DockerCallbackMySQLExtensio
      * Should be called first 
      * @see BeforeAll
      */
+    @Override
     public void beforeAll(ExtensionContext context) throws Exception {
         Class<?> clazz = context.getRequiredTestClass();
         log.warn("found and get annotation : {}", (Object[] 
)context.getRequiredTestClass().getAnnotations());
         DockerMySQLCallback dockerCallback = 
clazz.getAnnotation(DockerMySQLCallback.class);
-        setSkipConfigurationCheck(dockerCallback.skipConfigurationCheck());
-        setCustomUrlKey(dockerCallback.customUrlKey());
-        setTargetConfigName(dockerCallback.targetConfigName());
-        setTargetFileName(dockerCallback.targetFileName());
-        setAdapterProfileFallback(dockerCallback.adapterProfileFallback());
+        if (dockerCallback != null) {
+            setSkipConfigurationCheck(dockerCallback.skipConfigurationCheck());
+            setCustomUrlKey(dockerCallback.customUrlKey());
+            setTargetConfigName(dockerCallback.targetConfigName());
+            setTargetFileName(dockerCallback.targetFileName());
+            setAdapterProfileFallback(dockerCallback.adapterProfileFallback());
+        } else {
+            super.beforeAll(context);
+        }
         
-        // log.info("starting call context "+ context);
-        dbInit(context);
-        String jdbcConnectionString = generateJdbcUrl();
+        try {
+            dbInit(context);
+        } catch (Exception e) {
+            final String logs = getDbContainer().getLogs();
+            log.info("fetched container logs: {} ", logs);
+            throw e;
+        }
+        String jdbcConnectionString = generateJdbcUrl("?loggerLevel=OFF");
         context.getStore(Namespace.GLOBAL).put("jdbcConnectionString", 
jdbcConnectionString);
-        context.getStore(Namespace.GLOBAL).put("container", 
DATABASE_CONTAINER);
+        context.getStore(Namespace.GLOBAL).put("container", getDbContainer());
         context.getStore(Namespace.GLOBAL).put("annotatedClass", 
dockerCallback);
         
         torqueInit(context);
     }
 
-
-    private void dbInit(ExtensionContext context)
-            throws TorqueException, UnsupportedOperationException, 
IOException, InterruptedException {
-        log.info("Starting from dockerfile: {}", DOCKERFILE);
-        // before torque init
-        DATABASE_CONTAINER.setStartupAttempts(3);
-        startDatabaseContainer();
-        
-    }
-
-    private static void startDatabaseContainer() {
-        if (!DATABASE_CONTAINER.isRunning()) {
-            DATABASE_CONTAINER.waitingFor(Wait.forListeningPort());
-            DATABASE_CONTAINER.start();
-        }
-        if (!DATABASE_CONTAINER.isRunning()) {
-            throw new RuntimeException("Could not find RUNNING database 
container");
-        }
-    }
-
-    /**
-     * 
-     * @returns the JDBC string with mapped port binding
-     */
-    private static String generateJdbcUrl() {
-        startDatabaseContainer();
-        if (!DATABASE_CONTAINER.isRunning()) {
-            throw new RuntimeException("Could not find RUNNING database 
container");
-        }
-        // MY_SQL_CONTAINER.withCreateContainerCmdModifier(modifier) //
-        String serviceHost = DATABASE_CONTAINER.getContainerIpAddress();
-        Integer mappedPort = DATABASE_CONTAINER.getMappedPort(SERVICE_PORT);// 
e.g. 32811
-        log.info("generate jdbc url from {}, mapped Port: {}, bounded port: 
{}", serviceHost, mappedPort,
-                DATABASE_CONTAINER.getBoundPortNumbers());
-
-        String targetJDBC = // genJDBC;
-                String.format("jdbc:mysql://%s:%d/%s?loggerLevel=OFF", 
serviceHost, mappedPort, DATABASE_NAME);
-        log.info("used connect url: {}", targetJDBC);
-        return targetJDBC;
-    }
-
 }

Modified: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackPostgreSQLExtension.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackPostgreSQLExtension.java?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackPostgreSQLExtension.java
 (original)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerCallbackPostgreSQLExtension.java
 Tue Jan  7 14:08:40 2020
@@ -22,9 +22,7 @@ package org.apache.torque.testcontainer.
 import static 
org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
 
 import java.io.File;
-import java.io.IOException;
 
-import org.apache.torque.TorqueException;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
 import org.junit.jupiter.api.extension.ConditionEvaluationResult;
@@ -34,28 +32,24 @@ import org.junit.jupiter.api.extension.E
 import org.slf4j.LoggerFactory;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.output.Slf4jLogConsumer;
-import org.testcontainers.containers.wait.strategy.Wait;
 import org.testcontainers.images.builder.ImageFromDockerfile;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 
 /**
- * Testcontainer configuration
+ * Testcontainer configuration for database Postgres
+ * 
+ * Requires some configuration data found for example in {@link 
DockerPostGresCallback}.
  * 
  * @author gk
  *
  */
 @Testcontainers
-public class DockerCallbackPostgreSQLExtension extends DockerCallbackExtension 
implements BeforeAllCallback, BeforeTestExecutionCallback, ExecutionCondition {
+public class DockerCallbackPostgreSQLExtension extends 
DockerDatabaseAbstractExtension implements BeforeAllCallback, 
BeforeTestExecutionCallback, ExecutionCondition {
 
     private static org.slf4j.Logger log = 
LoggerFactory.getLogger(DockerCallbackPostgreSQLExtension.class);
 
     private static int SERVICE_PORT = 5432;
-    
-    protected static String DATABASE_NAME = "bookstore";
-
-    // copied from src/test/profile/mysql/docker-resources/db/
-    protected static final String DOCKERFILE = "./target/Dockerfile";
 
     private static final ConditionEvaluationResult ENABLED_BY_DEFAULT = 
enabled(
             "DockerCallbackExtension is enabled by default - checking internal 
state only");
@@ -66,6 +60,11 @@ public class DockerCallbackPostgreSQLExt
                     .withEnv("POSTGRES_DB", 
DATABASE_NAME).withEnv("POSTGRES_USER", "torque")
                     .withEnv("POSTGRES_PASSWORD", 
"torque").withLogConsumer(new Slf4jLogConsumer(log));
     
+    public DockerCallbackPostgreSQLExtension() {
+        setDbContainer(DATABASE_CONTAINER);
+        setServicePort(SERVICE_PORT);
+    }
+    
     @Override
     public ConditionEvaluationResult 
evaluateExecutionCondition(ExtensionContext context) {
         String actual = System.getProperty("torque.callback");
@@ -101,12 +100,12 @@ public class DockerCallbackPostgreSQLExt
             log.info("fetched container logs: {} ", logs);
             throw e;
         }
-        String jdbcConnectionString = generateJdbcUrl();
+        String jdbcConnectionString = generateJdbcUrl("");
         context.getStore(Namespace.GLOBAL).put("jdbcConnectionString", 
jdbcConnectionString);
         context.getStore(Namespace.GLOBAL).put("container", 
DATABASE_CONTAINER);
         context.getStore(Namespace.GLOBAL).put("annotatedClass", 
dockerCallback);
         
-        torqueInit(context);   
+        torqueInit(context);
     }
 
     @Override
@@ -114,44 +113,5 @@ public class DockerCallbackPostgreSQLExt
         // log.info("starting call test context "+ context);
     }
 
-    private void dbInit(ExtensionContext context)
-            throws TorqueException, UnsupportedOperationException, 
IOException, InterruptedException {
-        log.info("Starting from dockerfile: {} with image name: {}", 
DOCKERFILE , DATABASE_CONTAINER.getDockerImageName() );
-        // before torque init
-        DATABASE_CONTAINER.setStartupAttempts(3);
-        startDatabaseContainer();
-    }
-
-    private static void startDatabaseContainer() {
-        if (!DATABASE_CONTAINER.isRunning()) {
-            log.info("Waiting for running/ listening port..., binds: {}", 
DATABASE_CONTAINER.getBinds());
-            DATABASE_CONTAINER.waitingFor(Wait.forListeningPort());
-            DATABASE_CONTAINER.start();
-        }
-        if (!DATABASE_CONTAINER.isRunning()) {
-            throw new RuntimeException("Could not find RUNNING database 
container");
-        }
-    }
-
-    /**
-     * 
-     * @returns the JDBC string with mapped port binding
-     */
-    private static String generateJdbcUrl() {
-        startDatabaseContainer();
-        if (!DATABASE_CONTAINER.isRunning()) {
-            throw new RuntimeException("Could not find RUNNING database 
container");
-        }
-
-        String serviceHost = DATABASE_CONTAINER.getContainerIpAddress();
-        Integer mappedPort = DATABASE_CONTAINER.getMappedPort(SERVICE_PORT);// 
e.g. 32811
-        log.info("generate jdbc url from {}, mapped Port: {}, bounded port: 
{}", serviceHost, mappedPort,
-                DATABASE_CONTAINER.getBoundPortNumbers());
-
-        String targetJDBC = // genJDBC;
-                String.format("jdbc:postgresql://%s:%d/%s", serviceHost, 
mappedPort, DATABASE_NAME);
-        log.info("used connect url: {}", targetJDBC);
-        return targetJDBC;
-    }
 
 }

Added: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerDatabaseAbstractExtension.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerDatabaseAbstractExtension.java?rev=1872442&view=auto
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerDatabaseAbstractExtension.java
 (added)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerDatabaseAbstractExtension.java
 Tue Jan  7 14:08:40 2020
@@ -0,0 +1,112 @@
+package org.apache.torque.testcontainer.junit5.extension;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.torque.TorqueException;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+/**
+ * {@link #dbContainer} and  {@link #servicePort} has to be set by 
implementing class
+ * 
+ * @author gk
+ * @version $Id$
+ *
+ */
+public abstract class DockerDatabaseAbstractExtension extends 
DockerCallbackExtension {
+
+    static Logger log = LogManager.getLogger();
+    
+    protected static String DATABASE_NAME = "bookstore";
+    protected static final String DOCKERFILE = "./target/Dockerfile";
+    
+    GenericContainer dbContainer;
+    
+    private int servicePort;
+    
+    public DockerDatabaseAbstractExtension() {
+        super();
+    }
+    
+
+    /**
+     * If database {@link #dbContainer} is not running, start it after port is 
bound.
+     * If it is still not running throw RuntimeException
+     */
+    private void startDatabaseContainer() {
+        if (!getDbContainer().isRunning()) {
+            log.info("Waiting for running/ listening port..., binds: {}", 
getDbContainer().getBinds());
+            getDbContainer().waitingFor(Wait.forListeningPort());
+            getDbContainer().start();
+        }
+        if (!getDbContainer().isRunning()) {
+            throw new RuntimeException("Could not find RUNNING database 
container ");
+        }
+    }
+
+    /**
+     * Builds and returns database specific JDBC string 
<code>jdbc:%s://%s:%d/%s%s</code> with parameters as configured in 
+     * <ul>
+     * @see #getAdapterProfileFallback(),
+     * {@link #getDbContainer} container ip address,
+     * {@link #getDbContainer()} mapped port,
+     * {@value #DATABASE_NAME} and  param queryContext.
+     * 
+     * 
+     * @param queryContext Optional query string including question mark
+     * @return the database specific JDBC string with mapped port binding
+     */
+    protected String generateJdbcUrl(String queryContext) {
+        startDatabaseContainer();
+        if (!getDbContainer().isRunning()) {
+            throw new RuntimeException("Could not find RUNNING database 
container");
+        }
+        // MY_SQL_CONTAINER.withCreateContainerCmdModifier(modifier) //
+        String serviceHost = getDbContainer().getContainerIpAddress();
+        Integer mappedPort = 
getDbContainer().getMappedPort(getServicePort());// e.g. 32811
+        log.info("generate jdbc url from {}, mapped Port: {}, bounded port: 
{}", serviceHost, mappedPort,
+                getDbContainer().getBoundPortNumbers());
+    
+        if (queryContext == null) {
+            queryContext = "";
+        }
+        String targetJDBC = // genJDBC;
+                String.format("jdbc:%s://%s:%d/%s%s", 
getAdapterProfileFallback(), serviceHost, mappedPort, DATABASE_NAME, 
queryContext);
+        log.info("used connect url: {}", targetJDBC);
+        return targetJDBC;
+    }
+
+    protected void dbInit(ExtensionContext context)
+            throws TorqueException, UnsupportedOperationException, 
IOException, InterruptedException {
+                log.info("Starting from dockerfile: {} with image name: {}", 
DOCKERFILE , getDbContainer().getDockerImageName() );
+                // before torque init
+                getDbContainer().setStartupAttempts(3);
+                startDatabaseContainer();
+    }
+
+    public DockerDatabaseAbstractExtension(String adapterProfileFallback) {
+        super(adapterProfileFallback);
+    }
+
+    public GenericContainer getDbContainer() {
+        return dbContainer;
+    }
+
+    public void setDbContainer(GenericContainer dbContainer) {
+        this.dbContainer = dbContainer;
+    }
+
+
+    public int getServicePort() {
+        return servicePort;
+    }
+
+
+    public void setServicePort(int servicePort) {
+        this.servicePort = servicePort;
+    }
+
+}
\ No newline at end of file

Propchange: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerDatabaseAbstractExtension.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerMySQLCallback.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerMySQLCallback.java?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerMySQLCallback.java
 (original)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerMySQLCallback.java
 Tue Jan  7 14:08:40 2020
@@ -1,5 +1,7 @@
 package org.apache.torque.testcontainer.junit5.extension;
 
+import java.lang.annotation.Documented;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -32,22 +34,23 @@ import org.junit.jupiter.api.extension.E
 import org.testcontainers.junit.jupiter.Testcontainers;
 
 /**
- * {@code @DockerCallback} is used to signal that the annotated test class or
- * test method is using Docker {@link Testcontainers} and Torque initialized 
accordingly.
+ * {@link DockerMySQLCallback} is used to signal that the annotated test class 
or
+ * test method is using Docker {@link Testcontainers} with database MySQL and 
Torque initialized accordingly.
  * 
- * It is currently enabled by overridign the default
+ * It is currently enabled by overriding the default.
  * 
  * @author gkallidis
+ * @version $Id$
  *
  */
 // may have ParameterizedTest in test class -> Possible configuration error
 @Tag("DockerMySQLCallback")
 @Inherited
-//@DockerCallback2(adapterProfileFallback="mysql")
 @Target( { ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE } 
)
 @Retention(RetentionPolicy.RUNTIME)
 @ExtendWith(AdapterParameterResolver.class)
 @ExtendWith(DockerCallbackMySQLExtension.class)
+@Documented
 public @interface DockerMySQLCallback {
     
     String value() default "";

Modified: 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerPostGresCallback.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerPostGresCallback.java?rev=1872442&r1=1872441&r2=1872442&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerPostGresCallback.java
 (original)
+++ 
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/testcontainer/junit5/extension/DockerPostGresCallback.java
 Tue Jan  7 14:08:40 2020
@@ -1,5 +1,7 @@
 package org.apache.torque.testcontainer.junit5.extension;
 
+import java.lang.annotation.Documented;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -32,22 +34,23 @@ import org.junit.jupiter.api.extension.E
 import org.testcontainers.junit.jupiter.Testcontainers;
 
 /**
- * {@code @DockerCallback} is used to signal that the annotated test class or
- * test method is using Docker {@link Testcontainers} and Torque initialized 
accordingly.
+ * {@link DockerPostGresCallback} is used to signal that the annotated test 
class or
+ * test method is using Docker {@link Testcontainers} with database Postgres 
and Torque initialized accordingly.
  * 
- * It is currently enabled by overridign the default
+ * It is currently enabled by overriding the default
  * 
- * @author gkallidis
+ * @author gk
+ * @version $Id$
  *
  */
 // may have ParameterizedTest in test class -> Possible configuration error
 @Tag("DockerPostGresCallback")
 @Inherited
-//@DockerCallback2(adapterProfileFallback="mysql")
 @Target( { ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE } 
)
 @Retention(RetentionPolicy.RUNTIME)
 @ExtendWith(AdapterParameterResolver.class)
 @ExtendWith(DockerCallbackPostgreSQLExtension.class)
+@Documented
 public @interface DockerPostGresCallback {
     
     String value() default "";



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to