Author: gk
Date: Mon Oct 28 15:54:51 2019
New Revision: 1869079

URL: http://svn.apache.org/viewvc?rev=1869079&view=rev
Log:
profile docker-container: 
- requires now Torque-runtime 4.1-SNAPSHOT, set it from command line:
  mvn test -Pdocker-testcontainer -Dtorque.version=4.1-SNAPSHOT
- activate UserManagerWithContainerTest.java
- fix url setting

Modified:
    turbine/core/trunk/conf/test/docker-manager/TorqueTest.properties
    
turbine/core/trunk/conf/test/docker-manager/fulcrumComponentConfiguration.xml
    turbine/core/trunk/conf/test/log4j2-test.xml
    turbine/core/trunk/pom.xml
    
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java
    
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java

Modified: turbine/core/trunk/conf/test/docker-manager/TorqueTest.properties
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/docker-manager/TorqueTest.properties?rev=1869079&r1=1869078&r2=1869079&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/docker-manager/TorqueTest.properties (original)
+++ turbine/core/trunk/conf/test/docker-manager/TorqueTest.properties Mon Oct 
28 15:54:51 2019
@@ -31,10 +31,12 @@ torque.database.default.adapter=auto
 torque.dsfactory.default.connection.driver =           com.mysql.cj.jdbc.Driver
 
 # mapped port for 3306
-torque.dsfactory.default.connection.url =              
jdbc:mysql://192.168.99.101:32815/default?serverTimeZone=UTC
+torque.dsfactory.default.connection.url =              
jdbc:mysql://192.168.99.101:3306/default?serverTimeZone=UTC
 torque.dsfactory.default.connection.user =             root
 torque.dsfactory.default.connection.password =         test1234
-torque.dsfactory.default.factory=org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+
+# if dbcp is removed, use 
org.apache.torque.dsfactory.SharedPoolDataSourceFactory again
+torque.dsfactory.default.factory=org.apache.torque.dsfactory.SharedPool2DataSourceFactory
 # -------------------------------------------------------------------
 
 # Comment if not using shared data source factory

Modified: 
turbine/core/trunk/conf/test/docker-manager/fulcrumComponentConfiguration.xml
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/docker-manager/fulcrumComponentConfiguration.xml?rev=1869079&r1=1869078&r2=1869079&view=diff
==============================================================================
--- 
turbine/core/trunk/conf/test/docker-manager/fulcrumComponentConfiguration.xml 
(original)
+++ 
turbine/core/trunk/conf/test/docker-manager/fulcrumComponentConfiguration.xml 
Mon Oct 28 15:54:51 2019
@@ -25,7 +25,7 @@
 <componentConfig>
     <!-- Torque Component -->
     <torque>
-       <configfile>conf/test/docker-manager/TorqueTest.properties</configfile>
+       <configfile>./conf/test/docker-manager/Torque4Test.xml</configfile>
     </torque>
     <cache cacheInitialSize="20" cacheCheckFrequency="5"/>
     <mimetype/>

Modified: turbine/core/trunk/conf/test/log4j2-test.xml
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/log4j2-test.xml?rev=1869079&r1=1869078&r2=1869079&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/log4j2-test.xml (original)
+++ turbine/core/trunk/conf/test/log4j2-test.xml Mon Oct 28 15:54:51 2019
@@ -35,6 +35,7 @@
           <AppenderRef ref="console" level="info"/>
        </Logger>
        <Logger name="avalon" level="info" additivity="false">
+        <AppenderRef ref="console"/>
         <AppenderRef ref="logfile"/>
       </Logger>
       <Logger name="org.apache.logging.log4j" level="debug" additivity="false">

Modified: turbine/core/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/pom.xml?rev=1869079&r1=1869078&r2=1869079&view=diff
==============================================================================
--- turbine/core/trunk/pom.xml (original)
+++ turbine/core/trunk/pom.xml Mon Oct 28 15:54:51 2019
@@ -1030,6 +1030,16 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency> <!-- include optional dependencies from torque-runtime -->
+        <groupId>commons-dbcp</groupId>
+        <artifactId>commons-dbcp</artifactId>
+        <version>1.4</version>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-dbcp2</artifactId>
+        <version>2.7.0</version>
+    </dependency>  
     <dependency> <!-- include more modern version just for torque-runtime v4.0 
-->
          <groupId>commons-configuration</groupId>
          <artifactId>commons-configuration</artifactId>
@@ -1262,7 +1272,11 @@
           </plugins>
       </build>
       <dependencies>
-        <!-- docker testcontainer deps start here -->
+        <!-- docker testcontainer deps start here, until torque 4.1 is 
releases start it like:
+
+        mvn test -Pdocker-testcontainer -Dtorque.version=4.1-SNAPSHOT
+
+        -->
         <dependency>
             <groupId>org.testcontainers</groupId>
             <artifactId>testcontainers</artifactId>

Modified: 
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java?rev=1869079&r1=1869078&r2=1869079&view=diff
==============================================================================
--- 
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java
 (original)
+++ 
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java
 Mon Oct 28 15:54:51 2019
@@ -75,7 +75,7 @@ class BuildContainerWithDockerfileTest {
    
    private static Logger log = LogManager.getLogger();
    
-   public static int SERVICEPORT = 3306;
+   public static int SERVICE_PORT = 3306;
 
    public static String DATABASE_NAME = "default";
 
@@ -93,7 +93,7 @@ class BuildContainerWithDockerfileTest {
 //                .add( "data.sql","/docker-entrypoint-initdb.d" ) 
 //            )
             .withDockerfile(new File(DOCKERFILE).toPath())
-        ).withExposedPorts( SERVICEPORT ) //.withStartupAttempts( 2 )
+        ).withExposedPorts( SERVICE_PORT ) //.withStartupAttempts( 2 )
          .withEnv(  "MYSQL_DATABASE", DATABASE_NAME )
          .withEnv( "MYSQL_USER", "userdb"  )
          .withEnv( "MYSQL_PASSWORD", "test1234" )
@@ -177,14 +177,14 @@ class BuildContainerWithDockerfileTest {
    // String.format("jdbc:tc:mysql:5.7.22://%s/%s", "dummy_host",
    // "test"); this will use database test, but allows e.g. custom cfg: 
?TC_MY_CNF=x.cfg
    // TODO inform torque about mapped port, use overriding configuration in 
torque 4.1
-   private static String generateJdbcUrl() {
+   public static String generateJdbcUrl() {
       if (MY_SQL_CONTAINER == null) { return null; }
       if (!MY_SQL_CONTAINER.isRunning()) {
           MY_SQL_CONTAINER.start();
       }
 
       String serviceHost = MY_SQL_CONTAINER.getContainerIpAddress();
-      Integer mappedPort = MY_SQL_CONTAINER.getMappedPort(SERVICEPORT);// e.g. 
32811
+      Integer mappedPort = MY_SQL_CONTAINER.getMappedPort(SERVICE_PORT);// 
e.g. 32811
       log.info("generate jdbc url from {}, mapped Port: {}, bounded port: {}", 
serviceHost, mappedPort, MY_SQL_CONTAINER.getBoundPortNumbers());
 
 //      if (MY_SQL_CONTAINER instanceof MySQLContainer) {

Modified: 
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java?rev=1869079&r1=1869078&r2=1869079&view=diff
==============================================================================
--- 
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java
 (original)
+++ 
turbine/core/trunk/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java
 Mon Oct 28 15:54:51 2019
@@ -4,6 +4,9 @@ import static junit.framework.TestCase.a
 import static junit.framework.TestCase.assertTrue;
 import static junit.framework.TestCase.fail;
 
+import java.io.File;
+import java.io.FileOutputStream;
+
 import org.apache.fulcrum.security.entity.ExtendedUser;
 import org.apache.fulcrum.security.util.UnknownEntityException;
 import org.apache.logging.log4j.LogManager;
@@ -16,7 +19,6 @@ import org.apache.turbine.services.secur
 import org.apache.turbine.util.TurbineConfig;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
 import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.Tag;
@@ -31,7 +33,7 @@ import org.testcontainers.junit.jupiter.
  *
  * TODO
  * This test might be more useful in a running turbine environment,
- * e.g. created by archetypes. Only one problem remains the mapped port, which 
is known only at runtime.
+ * e.g. created by archetypes or in torque-test testing databases. 
  *
  * @author gkallidis
  *
@@ -39,9 +41,8 @@ import org.testcontainers.junit.jupiter.
 @TestMethodOrder(OrderAnnotation.class)
 @Testcontainers
 @Tag("docker")
-// TODO disabled. requires manual port mapping in 
docker-manager/TorqueTest.properties, 
-// until not using Torque4.1 with xml configuration and overwriting 
user.settings.
-@Disabled
+// requires manual port mapping in docker-manager/TorqueTest.properties, 
+//@Disabled
 class UserManagerWithContainerTest {
 
    @TurbineService
@@ -63,14 +64,25 @@ class UserManagerWithContainerTest {
       tc = new TurbineConfig(".",
               "/conf/test/docker-manager/CompleteTurbineResources.properties");
       try {
-         // TODO get Torque component configuration and override 
torque.dsfactory.default.connection.url with url mapped port.
-         BuildContainerWithDockerfileTest.getConnection();
+         // get Torque component configuration and override 
torque.dsfactory.default.connection.url with url containing mapped port.
+         //Connection c = BuildContainerWithDockerfileTest.getConnection();
+         //MY_SQL_CONTAINER.getMappedPort( 
BuildContainerWithDockerfileTest.SERVICE_PORT );
+          
+         String jdbcConnectionString = 
BuildContainerWithDockerfileTest.generateJdbcUrl();
+         String customUrl = "torque.dsfactory.default.connection.url="+ 
jdbcConnectionString;
+         // override and set mapped port in url, which is known only at 
runtime.
+         File file = new 
File("./conf/test/docker-manager/torque.usersettings.properties");
+         try (FileOutputStream fop = new FileOutputStream(file )) {
+             if (!file.exists()) {
+                 file.createNewFile();
+             }
+             fop.write( customUrl.getBytes() );
+             fop.flush();
+         }
          tc.initialize();
       } catch (Exception e) {
          fail();
       }
-
-      //Torque.getInstance();
    }
 
    /**
@@ -85,7 +97,6 @@ class UserManagerWithContainerTest {
    @Test
    @Order(1)
    @Tag("docker")
-   @Disabled
    public void testCreateManagedUser()
            throws Exception
    {
@@ -103,13 +114,15 @@ class UserManagerWithContainerTest {
    @Test
    @Order(2)
    @Tag("docker")
-   @Disabled
+   //@Disabled
    void selectNewUser() {
       User ringo;
       try {
          ringo = turbineSecurityService.getUser("ringo");
          assertEquals("ringo", ringo.getFirstName());
+         
          deleteUser(ringo);
+         
       } catch (Exception sqle) {
           log.error( "new user error",sqle);
           fail();


Reply via email to