openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1533722 - /openwebbeans/cms-site/trunk/content/testing_cdictrl.mdtext
Date Sat, 19 Oct 2013 09:25:13 GMT
Author: struberg
Date: Sat Oct 19 09:25:13 2013
New Revision: 1533722

URL: http://svn.apache.org/r1533722
Log:
add info about even testing OWB as part of TomEE

Modified:
    openwebbeans/cms-site/trunk/content/testing_cdictrl.mdtext

Modified: openwebbeans/cms-site/trunk/content/testing_cdictrl.mdtext
URL: http://svn.apache.org/viewvc/openwebbeans/cms-site/trunk/content/testing_cdictrl.mdtext?rev=1533722&r1=1533721&r2=1533722&view=diff
==============================================================================
--- openwebbeans/cms-site/trunk/content/testing_cdictrl.mdtext (original)
+++ openwebbeans/cms-site/trunk/content/testing_cdictrl.mdtext Sat Oct 19 09:25:13 2013
@@ -183,8 +183,55 @@ Such a base class could look roughly lik
     
     }
 
- 
+## Testing JavaEE applications
 
+You can also plug in a cdictrl backend for [Apache TomEE][2] whenever you need to not only
test CDI applications 
+but a full JavaEE application which has EJBs, managed DataSources, JTA, etc
+The only thing you need to do is to replace your ``deltaspike-cdictrl-owb`` dependency in
your pom with
+``deltaspike-cdictrl-openejb``. Since Apache TomEE and Apache OpenEJB both contain OpenWebBeans
as CDI container
+you will get all the OWB functionality plus other JavaEE functionality.  
+
+You can pass DataSource configuration by simply providing a ``Properties`` instance to 
+``CdiContainer.boot(dbConfiguration)`` in the beforeMethod method of the test class above:
+
+    :::java
+    public final void beforeMethod() throws Exception {
+        containerRefCount++;
+    
+        if (cdiContainer == null) {
+            // setting up the Apache DeltaSpike ProjectStage
+            ProjectStage projectStage = runInProjectStage();
+            ProjectStageProducer.setProjectStage(projectStage);
+            cdiContainer = CdiContainerLoader.getCdiContainer();
+    
+            Properties dbProperties = new Properties();
+            String dbvendor = ConfigResolver.getPropertyValue("dbvendor", "h2");
+            URL dbPropertiesUrl =  getClass().getResource("/db/db-" + dbvendor + ".properties");
+            if (dbPropertiesUrl != null) {
+                InputStream is = dbPropertiesUrl.openStream();
+                try {
+                    dbProperties.load(is);
+                }
+                finally {
+                    is.close();
+                }
+            }
+
+            cdiContainer.boot(dbProperties);
+        }
+        else {
+            cleanInstances();
+        }
+    }
+        
+The ``db/db-mysql.properties`` file for Apache OpenEJB (the former name of TomEE) would look
like:
+
+    MYDS = new://Resource?type=DataSource
+    MYDS.JdbcDriver = org.h2.Driver
+    MYDS.JdbcUrl = jdbc:h2:file:/tmp/h2/myappdb
+    MYDS.JtaManaged = true
+    MYDS.UserName = sa
+    MYDS.Password =
 
 
   [1]: http://deltaspike.apache.org



Mime
View raw message