openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r897057 - in /websites/staging/openwebbeans/trunk/content: ./ testing_arquillian.html testing_general.html testing_test-control.html
Date Sun, 09 Feb 2014 20:35:25 GMT
Author: buildbot
Date: Sun Feb  9 20:35:25 2014
New Revision: 897057

Log:
Staging update by buildbot for openwebbeans

Modified:
    websites/staging/openwebbeans/trunk/content/   (props changed)
    websites/staging/openwebbeans/trunk/content/testing_arquillian.html
    websites/staging/openwebbeans/trunk/content/testing_general.html
    websites/staging/openwebbeans/trunk/content/testing_test-control.html

Propchange: websites/staging/openwebbeans/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Sun Feb  9 20:35:25 2014
@@ -1 +1 @@
-1566360
+1566395

Modified: websites/staging/openwebbeans/trunk/content/testing_arquillian.html
==============================================================================
--- websites/staging/openwebbeans/trunk/content/testing_arquillian.html (original)
+++ websites/staging/openwebbeans/trunk/content/testing_arquillian.html Sun Feb  9 20:35:25 2014
@@ -74,212 +74,38 @@
 
 
         <div id="OwbContent_" class="wiki-content">
-<h1 id="testing-your-application-with-apache-deltaspike-cdictrl">Testing your application with Apache DeltaSpike CdiCtrl</h1>
-<h2 id="about-cdictrl">About CdiCtrl</h2>
-<p><code>CdiCtrl</code> is <em>not</em> part of Apache OpenWebBeans but a module of 
-<a href="http://deltaspike.apache.org">Apache DeltaSpike</a>. </p>
-<p>The <code>CdiCtrl</code> interface abstracts away all the logic to boot a CDI Container
-and controls the lifecycle of it's Contexts (Request Context, Session Context, etc).</p>
-<p>The actual CDI Container is determined by using the <code>java.util.ServiceLoader</code>.
-There are a few different implementations available. Besides Apache OpenWebBeans
-there are also plugins for JBoss Weld and <a href="http://tomee.apache.org">Apache TomEE</a>. </p>
-<h2 id="adding-openwebbeans-cdictrl-to-your-project">Adding OpenWebBeans CdiCtrl to your project</h2>
-<p>The following are the dependencies you need in your Apache Maven pom.xml file in addition to
-OWB itself:</p>
+<h1 id="testing-your-application-with-jboss-arquillian">Testing your application with JBoss Arquillian</h1>
+<h2 id="about-arquillian">About Arquillian</h2>
+<p><a href="http://arquillian.org/">JBoss Arquillian</a> is a very popular testing framework for complex use cases. You write your test with 
+JUnit or TestNG but with the extended possibility to have fine grained control over the managed environment. 
+Basically Arquillian allows you to create artificial war / jar files with the exact content you need for your test. 
+Many powerful features are available in extensions. One such extension is <code>Arquillian Drone</code> 
+that allows you to test with a web-based user interface and <code>Arquillian Performance</code> is another one
+that offers rich functionality aimed at performance testing.</p>
+<p>One of the main principles of <code>Arquillian</code> is to be portable and thus using it to test applications that 
+leverage OpenWebBeans is fully supported.</p>
+<p>To author a new <code>Arquillian</code> test you follow this rough flow:</p>
+<ul>
+<li>Create a new JUnit / TestNG test class</li>
+<li>Annotate the class with <code>@RunWith(Arquillian.class)</code></li>
+<li>Create a new deployment and include exactly what you need for that test. 
+It's important that you add beans.xml to your test path and include it in the deployment.</li>
+<li>Use @Inject (from the usual package) to obtain instances that you included in the deployment</li>
+<li>Perform assertions on injected instances "normally". </li>
+</ul>
+<h2 id="testing-our-java-se-servlet-container-project">Testing our Java SE / Servlet container project</h2>
+<p>The best way to get started with <code>Arquillian</code> is to follow the official <a href="http://arquillian.org/guides/getting_started/">Getting Started</a> guide. However for testing 
+OpenWebBeans standalone you will need to use the following adapter:</p>
 <div class="codehilite"><pre><span class="nt">&lt;dependency&gt;</span>
-    <span class="nt">&lt;groupId&gt;</span>org.apache.deltaspike.cdictrl<span class="nt">&lt;/groupId&gt;</span>
-    <span class="nt">&lt;artifactId&gt;</span>deltaspike-cdictrl-api<span class="nt">&lt;/artifactId&gt;</span>
-    <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
-    <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
+   <span class="nt">&lt;groupId&gt;</span>org.apache.openwebbeans.arquillian<span class="nt">&lt;/groupId&gt;</span>
+   <span class="nt">&lt;artifactId&gt;</span>owb-arquillian-parent<span class="nt">&lt;/artifactId&gt;</span>
+   <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">owb</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
 <span class="nt">&lt;/dependency&gt;</span>
-<span class="nt">&lt;dependency&gt;</span>
-    <span class="nt">&lt;groupId&gt;</span>org.apache.deltaspike.cdictrl<span class="nt">&lt;/groupId&gt;</span>
-    <span class="nt">&lt;artifactId&gt;</span>deltaspike-cdictrl-owb<span class="nt">&lt;/artifactId&gt;</span>
-    <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
-    <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
-<span class="nt">&lt;/dependency&gt;</span>
-</pre></div>
-
-
-<h2 id="why-use-cdictrl-for-your-unit-tests">Why use CdiCtrl for your unit tests?</h2>
-<p>Whenever you need to write unit tests for a full application, then you will need to 
-have a CDI container scann all your classes, create <code>Bean&lt;T&gt;</code> from it and provide 
-them for injection. All this can be done by either using JUnits <code>@RunWith</code> or 
-by simply creating a common base class for your unit tests which boots up the 
-container on your test classpath.</p>
-<p>There is no need to restart the container for each and every of your unit tests
-as this would cause a big performance loss. Instead it is usually sufficient to 
-use the CdiCtrls <code>ContextControl</code> mechanism to just stop and restart the 
-respective CDI Contexts.</p>
-<p>Such a base class could look roughly like the following:</p>
-<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">org.apache.deltaspike.cdise.api.CdiContainer</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.cdise.api.CdiContainerLoader</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.api.projectstage.ProjectStage</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.util.ProjectStageProducer</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.api.provider.BeanProvider</span><span class="o">;</span>
-
-<span class="kd">public</span> <span class="kd">abstract</span> <span class="kd">class</span> <span class="nc">ContainerTest</span> <span class="o">{</span>
-
-    <span class="kd">protected</span> <span class="kd">static</span> <span class="kd">volatile</span> <span class="n">CdiContainer</span> <span class="n">cdiContainer</span><span class="o">;</span>
-    <span class="c1">// nice to know, since testng executes tests in parallel.</span>
-    <span class="kd">protected</span> <span class="kd">static</span> <span class="kt">int</span> <span class="n">containerRefCount</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span>
-
-    <span class="kd">protected</span> <span class="n">ProjectStage</span> <span class="nf">runInProjectStage</span><span class="o">()</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">ProjectStage</span><span class="o">.</span><span class="na">UnitTest</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * Starts container</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="nd">@BeforeMethod</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">containerRefCount</span><span class="o">++;</span>
-
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="c1">// setting up the Apache DeltaSpike ProjectStage</span>
-            <span class="n">ProjectStage</span> <span class="n">projectStage</span> <span class="o">=</span> <span class="n">runInProjectStage</span><span class="o">();</span>
-            <span class="n">ProjectStageProducer</span><span class="o">.</span><span class="na">setProjectStage</span><span class="o">(</span><span class="n">projectStage</span><span class="o">);</span>
-
-            <span class="n">cdiContainer</span> <span class="o">=</span> <span class="n">CdiContainerLoader</span><span class="o">.</span><span class="na">getCdiContainer</span><span class="o">();</span>
-
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">boot</span><span class="o">();</span>
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContexts</span><span class="o">();</span>
-        <span class="o">}</span>
-        <span class="k">else</span> <span class="o">{</span>
-            <span class="n">cleanInstances</span><span class="o">();</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-
-    <span class="kd">public</span> <span class="kd">static</span> <span class="n">CdiContainer</span> <span class="nf">getCdiContainer</span><span class="o">()</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">cdiContainer</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * This will fill all the InjectionPoints of the current test class for you</span>
-<span class="cm">     */</span>
-    <span class="nd">@BeforeClass</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeClass</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">beforeMethod</span><span class="o">();</span>
-
-        <span class="c1">// perform injection into the very own test class</span>
-        <span class="n">BeanManager</span> <span class="n">beanManager</span> <span class="o">=</span> <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getBeanManager</span><span class="o">();</span>
-
-        <span class="n">CreationalContext</span> <span class="n">creationalContext</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createCreationalContext</span><span class="o">(</span><span class="kc">null</span><span class="o">);</span>
-
-        <span class="n">AnnotatedType</span> <span class="n">annotatedType</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createAnnotatedType</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">getClass</span><span class="o">());</span>
-        <span class="n">InjectionTarget</span> <span class="n">injectionTarget</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createInjectionTarget</span><span class="o">(</span><span class="n">annotatedType</span><span class="o">);</span>
-        <span class="n">injectionTarget</span><span class="o">.</span><span class="na">inject</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="n">creationalContext</span><span class="o">);</span>
-
-        <span class="c1">// this is a trick we use to have proper DB transactions when using the entitymanager-per-request pattern</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-        <span class="n">cleanUpDb</span><span class="o">();</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * Shuts down container.</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="nd">@AfterMethod</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">afterMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">cleanInstances</span><span class="o">();</span>
-            <span class="n">containerRefCount</span><span class="o">--;</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * clean the NormalScoped contextual instances by stopping and restarting</span>
-<span class="cm">     * some contexts. You could also restart the ApplicationScoped context</span>
-<span class="cm">     * if you have some caches in your classes. </span>
-<span class="cm">     */</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">cleanInstances</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">stopContext</span><span class="o">(</span><span class="n">RequestScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContext</span><span class="o">(</span><span class="n">RequestScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">stopContext</span><span class="o">(</span><span class="n">SessionScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContext</span><span class="o">(</span><span class="n">SessionScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-    <span class="o">}</span>
-
-    <span class="nd">@AfterSuite</span>
-    <span class="kd">public</span> <span class="kd">synchronized</span> <span class="kt">void</span> <span class="nf">shutdownContainer</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">shutdown</span><span class="o">();</span>
-            <span class="n">cdiContainer</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">finalize</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Throwable</span> <span class="o">{</span>
-        <span class="n">shutdownContainer</span><span class="o">();</span>
-        <span class="kd">super</span><span class="o">.</span><span class="na">finalize</span><span class="o">();</span>
-    <span class="o">}</span>
-
-
-    <span class="cm">/**</span>
-<span class="cm">     * Override this method for database clean up.</span>
-<span class="cm">     *</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="kd">protected</span> <span class="kt">void</span> <span class="nf">cleanUpDb</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="c1">//Override in subclasses when needed</span>
-    <span class="o">}</span>
-
-    <span class="kd">protected</span> <span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">T</span> <span class="n">getInstance</span><span class="o">(</span><span class="n">Class</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">type</span><span class="o">,</span> <span class="n">Qualifier</span><span class="o">...</span> <span class="n">qualifiers</span><span class="o">)</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">BeanProvider</span><span class="o">.</span><span class="na">getContextualReference</span><span class="o">(</span><span class="n">type</span><span class="o">,</span> <span class="n">qualifiers</span><span class="o">);</span>
-    <span class="o">}</span>
-
-<span class="o">}</span>
 </pre></div>
 
 
-<h2 id="testing-javaee-applications">Testing JavaEE applications</h2>
-<p>You can also plug in a cdictrl backend for <a href="http://tomee.apache.org">Apache TomEE</a> 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 <code>deltaspike-cdictrl-owb</code> dependency in your pom with
-<code>deltaspike-cdictrl-openejb</code>. Since Apache TomEE and Apache OpenEJB both contain OpenWebBeans as CDI container
-you will get all the OWB functionality plus other JavaEE functionality.  </p>
-<p>You can pass DataSource configuration by simply providing a <code>Properties</code> instance to 
-<code>CdiContainer.boot(dbConfiguration)</code> in the beforeMethod method of the test class above:</p>
-<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-    <span class="n">containerRefCount</span><span class="o">++;</span>
-
-    <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-        <span class="c1">// setting up the Apache DeltaSpike ProjectStage</span>
-        <span class="n">ProjectStage</span> <span class="n">projectStage</span> <span class="o">=</span> <span class="n">runInProjectStage</span><span class="o">();</span>
-        <span class="n">ProjectStageProducer</span><span class="o">.</span><span class="na">setProjectStage</span><span class="o">(</span><span class="n">projectStage</span><span class="o">);</span>
-        <span class="n">cdiContainer</span> <span class="o">=</span> <span class="n">CdiContainerLoader</span><span class="o">.</span><span class="na">getCdiContainer</span><span class="o">();</span>
-
-        <span class="n">Properties</span> <span class="n">dbProperties</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Properties</span><span class="o">();</span>
-        <span class="n">String</span> <span class="n">dbvendor</span> <span class="o">=</span> <span class="n">ConfigResolver</span><span class="o">.</span><span class="na">getPropertyValue</span><span class="o">(</span><span class="s">&quot;dbvendor&quot;</span><span class="o">,</span> <span class="s">&quot;h2&quot;</span><span class="o">);</span>
-        <span class="n">URL</span> <span class="n">dbPropertiesUrl</span> <span class="o">=</span>  <span class="n">getClass</span><span class="o">().</span><span class="na">getResource</span><span class="o">(</span><span class="s">&quot;/db/db-&quot;</span> <span class="o">+</span> <span class="n">dbvendor</span> <span class="o">+</span> <span class="s">&quot;.properties&quot;</span><span class="o">);</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">dbPropertiesUrl</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">InputStream</span> <span class="n">is</span> <span class="o">=</span> <span class="n">dbPropertiesUrl</span><span class="o">.</span><span class="na">openStream</span><span class="o">();</span>
-            <span class="k">try</span> <span class="o">{</span>
-                <span class="n">dbProperties</span><span class="o">.</span><span class="na">load</span><span class="o">(</span><span class="n">is</span><span class="o">);</span>
-            <span class="o">}</span>
-            <span class="k">finally</span> <span class="o">{</span>
-                <span class="n">is</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
-            <span class="o">}</span>
-        <span class="o">}</span>
-
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">boot</span><span class="o">(</span><span class="n">dbProperties</span><span class="o">);</span>
-    <span class="o">}</span>
-    <span class="k">else</span> <span class="o">{</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-    <span class="o">}</span>
-<span class="o">}</span>
-</pre></div>
-
-
-<p>The <code>db/db-mysql.properties</code> file for Apache OpenEJB (the former name of TomEE) would look like:</p>
-<div class="codehilite"><pre><span class="n">MYDS</span> <span class="p">=</span> <span class="n">new</span><span class="p">:</span><span class="o">//</span><span class="n">Resource</span>?<span class="n">type</span><span class="p">=</span><span class="n">DataSource</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JdbcDriver</span> <span class="p">=</span> <span class="n">org</span><span class="p">.</span><span class="n">h2</span><span class="p">.</span><span class="n">Driver</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JdbcUrl</span> <span class="p">=</span> <span class="n">jdbc</span><span class="p">:</span><span class="n">h2</span><span class="p">:</span><span class="n">file</span><span class="p">:</span><span class="o">/</span><span class="n">tmp</span><span class="o">/</span><span class="n">h2</span><span class="o">/</span><span class="n">myappdb</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JtaManaged</span> <span class="p">=</span> <span class="n">true</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">UserName</span> <span class="p">=</span> <span class="n">sa</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">Password</span> <span class="p">=</span>
-</pre></div>
+<h2 id="testing-your-java-ee-project">Testing your Java EE project</h2>
+<p>In addition to the adapter described above TomEE offers serveral adapters for working with TomEE. For more information visit <a href="http://tomee.apache.org/arquillian-available-adapters.html">TomEE: Available Arquillian Adapters</a>.</p>
         </div>
 
         <hr>

Modified: websites/staging/openwebbeans/trunk/content/testing_general.html
==============================================================================
--- websites/staging/openwebbeans/trunk/content/testing_general.html (original)
+++ websites/staging/openwebbeans/trunk/content/testing_general.html Sun Feb  9 20:35:25 2014
@@ -74,212 +74,28 @@
 
 
         <div id="OwbContent_" class="wiki-content">
-<h1 id="testing-your-application-with-apache-deltaspike-cdictrl">Testing your application with Apache DeltaSpike CdiCtrl</h1>
-<h2 id="about-cdictrl">About CdiCtrl</h2>
-<p><code>CdiCtrl</code> is <em>not</em> part of Apache OpenWebBeans but a module of 
-<a href="http://deltaspike.apache.org">Apache DeltaSpike</a>. </p>
-<p>The <code>CdiCtrl</code> interface abstracts away all the logic to boot a CDI Container
-and controls the lifecycle of it's Contexts (Request Context, Session Context, etc).</p>
-<p>The actual CDI Container is determined by using the <code>java.util.ServiceLoader</code>.
-There are a few different implementations available. Besides Apache OpenWebBeans
-there are also plugins for JBoss Weld and <a href="http://tomee.apache.org">Apache TomEE</a>. </p>
-<h2 id="adding-openwebbeans-cdictrl-to-your-project">Adding OpenWebBeans CdiCtrl to your project</h2>
-<p>The following are the dependencies you need in your Apache Maven pom.xml file in addition to
-OWB itself:</p>
-<div class="codehilite"><pre><span class="nt">&lt;dependency&gt;</span>
-    <span class="nt">&lt;groupId&gt;</span>org.apache.deltaspike.cdictrl<span class="nt">&lt;/groupId&gt;</span>
-    <span class="nt">&lt;artifactId&gt;</span>deltaspike-cdictrl-api<span class="nt">&lt;/artifactId&gt;</span>
-    <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
-    <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
-<span class="nt">&lt;/dependency&gt;</span>
-<span class="nt">&lt;dependency&gt;</span>
-    <span class="nt">&lt;groupId&gt;</span>org.apache.deltaspike.cdictrl<span class="nt">&lt;/groupId&gt;</span>
-    <span class="nt">&lt;artifactId&gt;</span>deltaspike-cdictrl-owb<span class="nt">&lt;/artifactId&gt;</span>
-    <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
-    <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
-<span class="nt">&lt;/dependency&gt;</span>
-</pre></div>
-
-
-<h2 id="why-use-cdictrl-for-your-unit-tests">Why use CdiCtrl for your unit tests?</h2>
-<p>Whenever you need to write unit tests for a full application, then you will need to 
-have a CDI container scann all your classes, create <code>Bean&lt;T&gt;</code> from it and provide 
-them for injection. All this can be done by either using JUnits <code>@RunWith</code> or 
-by simply creating a common base class for your unit tests which boots up the 
-container on your test classpath.</p>
-<p>There is no need to restart the container for each and every of your unit tests
-as this would cause a big performance loss. Instead it is usually sufficient to 
-use the CdiCtrls <code>ContextControl</code> mechanism to just stop and restart the 
-respective CDI Contexts.</p>
-<p>Such a base class could look roughly like the following:</p>
-<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">org.apache.deltaspike.cdise.api.CdiContainer</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.cdise.api.CdiContainerLoader</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.api.projectstage.ProjectStage</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.util.ProjectStageProducer</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.api.provider.BeanProvider</span><span class="o">;</span>
-
-<span class="kd">public</span> <span class="kd">abstract</span> <span class="kd">class</span> <span class="nc">ContainerTest</span> <span class="o">{</span>
-
-    <span class="kd">protected</span> <span class="kd">static</span> <span class="kd">volatile</span> <span class="n">CdiContainer</span> <span class="n">cdiContainer</span><span class="o">;</span>
-    <span class="c1">// nice to know, since testng executes tests in parallel.</span>
-    <span class="kd">protected</span> <span class="kd">static</span> <span class="kt">int</span> <span class="n">containerRefCount</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span>
-
-    <span class="kd">protected</span> <span class="n">ProjectStage</span> <span class="nf">runInProjectStage</span><span class="o">()</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">ProjectStage</span><span class="o">.</span><span class="na">UnitTest</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * Starts container</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="nd">@BeforeMethod</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">containerRefCount</span><span class="o">++;</span>
-
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="c1">// setting up the Apache DeltaSpike ProjectStage</span>
-            <span class="n">ProjectStage</span> <span class="n">projectStage</span> <span class="o">=</span> <span class="n">runInProjectStage</span><span class="o">();</span>
-            <span class="n">ProjectStageProducer</span><span class="o">.</span><span class="na">setProjectStage</span><span class="o">(</span><span class="n">projectStage</span><span class="o">);</span>
-
-            <span class="n">cdiContainer</span> <span class="o">=</span> <span class="n">CdiContainerLoader</span><span class="o">.</span><span class="na">getCdiContainer</span><span class="o">();</span>
-
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">boot</span><span class="o">();</span>
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContexts</span><span class="o">();</span>
-        <span class="o">}</span>
-        <span class="k">else</span> <span class="o">{</span>
-            <span class="n">cleanInstances</span><span class="o">();</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-
-    <span class="kd">public</span> <span class="kd">static</span> <span class="n">CdiContainer</span> <span class="nf">getCdiContainer</span><span class="o">()</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">cdiContainer</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * This will fill all the InjectionPoints of the current test class for you</span>
-<span class="cm">     */</span>
-    <span class="nd">@BeforeClass</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeClass</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">beforeMethod</span><span class="o">();</span>
-
-        <span class="c1">// perform injection into the very own test class</span>
-        <span class="n">BeanManager</span> <span class="n">beanManager</span> <span class="o">=</span> <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getBeanManager</span><span class="o">();</span>
-
-        <span class="n">CreationalContext</span> <span class="n">creationalContext</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createCreationalContext</span><span class="o">(</span><span class="kc">null</span><span class="o">);</span>
-
-        <span class="n">AnnotatedType</span> <span class="n">annotatedType</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createAnnotatedType</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">getClass</span><span class="o">());</span>
-        <span class="n">InjectionTarget</span> <span class="n">injectionTarget</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createInjectionTarget</span><span class="o">(</span><span class="n">annotatedType</span><span class="o">);</span>
-        <span class="n">injectionTarget</span><span class="o">.</span><span class="na">inject</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="n">creationalContext</span><span class="o">);</span>
-
-        <span class="c1">// this is a trick we use to have proper DB transactions when using the entitymanager-per-request pattern</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-        <span class="n">cleanUpDb</span><span class="o">();</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * Shuts down container.</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="nd">@AfterMethod</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">afterMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">cleanInstances</span><span class="o">();</span>
-            <span class="n">containerRefCount</span><span class="o">--;</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * clean the NormalScoped contextual instances by stopping and restarting</span>
-<span class="cm">     * some contexts. You could also restart the ApplicationScoped context</span>
-<span class="cm">     * if you have some caches in your classes. </span>
-<span class="cm">     */</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">cleanInstances</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">stopContext</span><span class="o">(</span><span class="n">RequestScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContext</span><span class="o">(</span><span class="n">RequestScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">stopContext</span><span class="o">(</span><span class="n">SessionScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContext</span><span class="o">(</span><span class="n">SessionScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-    <span class="o">}</span>
-
-    <span class="nd">@AfterSuite</span>
-    <span class="kd">public</span> <span class="kd">synchronized</span> <span class="kt">void</span> <span class="nf">shutdownContainer</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">shutdown</span><span class="o">();</span>
-            <span class="n">cdiContainer</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">finalize</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Throwable</span> <span class="o">{</span>
-        <span class="n">shutdownContainer</span><span class="o">();</span>
-        <span class="kd">super</span><span class="o">.</span><span class="na">finalize</span><span class="o">();</span>
-    <span class="o">}</span>
-
-
-    <span class="cm">/**</span>
-<span class="cm">     * Override this method for database clean up.</span>
-<span class="cm">     *</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="kd">protected</span> <span class="kt">void</span> <span class="nf">cleanUpDb</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="c1">//Override in subclasses when needed</span>
-    <span class="o">}</span>
-
-    <span class="kd">protected</span> <span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">T</span> <span class="n">getInstance</span><span class="o">(</span><span class="n">Class</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">type</span><span class="o">,</span> <span class="n">Qualifier</span><span class="o">...</span> <span class="n">qualifiers</span><span class="o">)</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">BeanProvider</span><span class="o">.</span><span class="na">getContextualReference</span><span class="o">(</span><span class="n">type</span><span class="o">,</span> <span class="n">qualifiers</span><span class="o">);</span>
-    <span class="o">}</span>
-
-<span class="o">}</span>
-</pre></div>
-
-
-<h2 id="testing-javaee-applications">Testing JavaEE applications</h2>
-<p>You can also plug in a cdictrl backend for <a href="http://tomee.apache.org">Apache TomEE</a> 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 <code>deltaspike-cdictrl-owb</code> dependency in your pom with
-<code>deltaspike-cdictrl-openejb</code>. Since Apache TomEE and Apache OpenEJB both contain OpenWebBeans as CDI container
-you will get all the OWB functionality plus other JavaEE functionality.  </p>
-<p>You can pass DataSource configuration by simply providing a <code>Properties</code> instance to 
-<code>CdiContainer.boot(dbConfiguration)</code> in the beforeMethod method of the test class above:</p>
-<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-    <span class="n">containerRefCount</span><span class="o">++;</span>
-
-    <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-        <span class="c1">// setting up the Apache DeltaSpike ProjectStage</span>
-        <span class="n">ProjectStage</span> <span class="n">projectStage</span> <span class="o">=</span> <span class="n">runInProjectStage</span><span class="o">();</span>
-        <span class="n">ProjectStageProducer</span><span class="o">.</span><span class="na">setProjectStage</span><span class="o">(</span><span class="n">projectStage</span><span class="o">);</span>
-        <span class="n">cdiContainer</span> <span class="o">=</span> <span class="n">CdiContainerLoader</span><span class="o">.</span><span class="na">getCdiContainer</span><span class="o">();</span>
-
-        <span class="n">Properties</span> <span class="n">dbProperties</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Properties</span><span class="o">();</span>
-        <span class="n">String</span> <span class="n">dbvendor</span> <span class="o">=</span> <span class="n">ConfigResolver</span><span class="o">.</span><span class="na">getPropertyValue</span><span class="o">(</span><span class="s">&quot;dbvendor&quot;</span><span class="o">,</span> <span class="s">&quot;h2&quot;</span><span class="o">);</span>
-        <span class="n">URL</span> <span class="n">dbPropertiesUrl</span> <span class="o">=</span>  <span class="n">getClass</span><span class="o">().</span><span class="na">getResource</span><span class="o">(</span><span class="s">&quot;/db/db-&quot;</span> <span class="o">+</span> <span class="n">dbvendor</span> <span class="o">+</span> <span class="s">&quot;.properties&quot;</span><span class="o">);</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">dbPropertiesUrl</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">InputStream</span> <span class="n">is</span> <span class="o">=</span> <span class="n">dbPropertiesUrl</span><span class="o">.</span><span class="na">openStream</span><span class="o">();</span>
-            <span class="k">try</span> <span class="o">{</span>
-                <span class="n">dbProperties</span><span class="o">.</span><span class="na">load</span><span class="o">(</span><span class="n">is</span><span class="o">);</span>
-            <span class="o">}</span>
-            <span class="k">finally</span> <span class="o">{</span>
-                <span class="n">is</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
-            <span class="o">}</span>
-        <span class="o">}</span>
-
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">boot</span><span class="o">(</span><span class="n">dbProperties</span><span class="o">);</span>
-    <span class="o">}</span>
-    <span class="k">else</span> <span class="o">{</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-    <span class="o">}</span>
-<span class="o">}</span>
-</pre></div>
-
-
-<p>The <code>db/db-mysql.properties</code> file for Apache OpenEJB (the former name of TomEE) would look like:</p>
-<div class="codehilite"><pre><span class="n">MYDS</span> <span class="p">=</span> <span class="n">new</span><span class="p">:</span><span class="o">//</span><span class="n">Resource</span>?<span class="n">type</span><span class="p">=</span><span class="n">DataSource</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JdbcDriver</span> <span class="p">=</span> <span class="n">org</span><span class="p">.</span><span class="n">h2</span><span class="p">.</span><span class="n">Driver</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JdbcUrl</span> <span class="p">=</span> <span class="n">jdbc</span><span class="p">:</span><span class="n">h2</span><span class="p">:</span><span class="n">file</span><span class="p">:</span><span class="o">/</span><span class="n">tmp</span><span class="o">/</span><span class="n">h2</span><span class="o">/</span><span class="n">myappdb</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JtaManaged</span> <span class="p">=</span> <span class="n">true</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">UserName</span> <span class="p">=</span> <span class="n">sa</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">Password</span> <span class="p">=</span>
-</pre></div>
+<h1 id="testing-strategies-for-projects-that-leverage-cdi">Testing strategies for projects that leverage CDI</h1>
+<p>One could argue that unit tests are harder to write when your instances are managed by a container. 
+However this is only true if the booting of said container is uncharted territory. 
+But lets assume the container control is taken cared of handily. Well then it can be quite the breath of fresh air to test code 
+that leverage dependency injection.</p>
+<p>Here comes the good news. Testing OpenWebBeans and CDI in general (and actually many other Java EE frameworks) 
+is in a good state as of today and testing frameworks are reaching a pretty decent level of maturity. Stay with us and 
+we will compare the pros and cons with 
+the different strategies. </p>
+<h3 id="good-practice">Good Practice</h3>
+<p>We won't go in to detail on how to properly use unit tests or integration tests in your project. However so called "Whitebox Testing" is 
+discouraged. Using whitebox testing is often critizied regardless but with frameworks that leverage 
+proxies it's simply not something you should attempt. Any reflection trick will would likely miss the mark and modify the proxy.
+Instead focus on functional tests and structure your code with high cohesion so that testing the public methods get's the job done.
+Remember to add beans.xml and other resources to your to your test path.</p>
+<h3 id="start-small-with-normal-unit-tests">Start small with normal unit tests</h3>
+<p>Testing code that leverage CDI does not differ much from using CDI in your project. You should start with just a plain pojo 
+in your project and likewise a plain unit test. Only when you need context should you upgrade the pojo to a CDI managed instance.
+Still this does not mean you automatically need something more then plain unit test. But when you need the container to act on your
+instances (for example to trigger <code>@PostConstruct</code>) then go ahead and upgrade the test to CDI aware.</p>
+<h3 id="cdi-aware-options">CDI aware options</h3>
+<p>The by far easiest and most straight forward way to write your first test is defientetly with </p>
         </div>
 
         <hr>

Modified: websites/staging/openwebbeans/trunk/content/testing_test-control.html
==============================================================================
--- websites/staging/openwebbeans/trunk/content/testing_test-control.html (original)
+++ websites/staging/openwebbeans/trunk/content/testing_test-control.html Sun Feb  9 20:35:25 2014
@@ -74,16 +74,20 @@
 
 
         <div id="OwbContent_" class="wiki-content">
-<h1 id="testing-your-application-with-apache-deltaspike-cdictrl">Testing your application with Apache DeltaSpike CdiCtrl</h1>
-<h2 id="about-cdictrl">About CdiCtrl</h2>
-<p><code>CdiCtrl</code> is <em>not</em> part of Apache OpenWebBeans but a module of 
-<a href="http://deltaspike.apache.org">Apache DeltaSpike</a>. </p>
-<p>The <code>CdiCtrl</code> interface abstracts away all the logic to boot a CDI Container
-and controls the lifecycle of it's Contexts (Request Context, Session Context, etc).</p>
-<p>The actual CDI Container is determined by using the <code>java.util.ServiceLoader</code>.
-There are a few different implementations available. Besides Apache OpenWebBeans
-there are also plugins for JBoss Weld and <a href="http://tomee.apache.org">Apache TomEE</a>. </p>
-<h2 id="adding-openwebbeans-cdictrl-to-your-project">Adding OpenWebBeans CdiCtrl to your project</h2>
+<h1 id="testing-your-application-with-apache-deltaspike-test-control">Testing your application with Apache DeltaSpike Test-Control</h1>
+<h2 id="about-test-control">About Test-Control</h2>
+<p><code>Test-Control</code> is <em>not</em> part of Apache OpenWebBeans but a module of 
+<a href="http://deltaspike.apache.org">Apache DeltaSpike</a>. It is based on another Deltaspike module called <code>CdiCtrl</code>. 
+<code>Test-Control</code> is currently only available in snapshot releases of Deltaspike.</p>
+<p><code>CdiCtrl</code> abstracts away all the logic to boot a CDI Container
+and controls the life cycle of it's Contexts (Request Context, Session Context, etc). 
+This module can be extremely powerful for CDI projects both for tests and during runtime. 
+It's a long time recommendation to use 
+<code>CdiCtrl</code> to write tests with low - medium complexity and we explain how here: 
+<a href="source.html">Testing with cdiCtrl</a>.</p>
+<p>With <code>Test-Control</code> the few steps you had to do on your own are taken cared of for you. In a way <code>Test-Control</code> 
+puts <code>CdiCtrl</code> out of business in regards to testing.</p>
+<h2 id="adding-deltaspike-test-control-to-your-project">Adding Deltaspike Test-Control to your project</h2>
 <p>The following are the dependencies you need in your Apache Maven pom.xml file in addition to
 OWB itself:</p>
 <div class="codehilite"><pre><span class="nt">&lt;dependency&gt;</span>
@@ -98,188 +102,29 @@ OWB itself:</p>
     <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
     <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
 <span class="nt">&lt;/dependency&gt;</span>
-</pre></div>
-
-
-<h2 id="why-use-cdictrl-for-your-unit-tests">Why use CdiCtrl for your unit tests?</h2>
-<p>Whenever you need to write unit tests for a full application, then you will need to 
-have a CDI container scann all your classes, create <code>Bean&lt;T&gt;</code> from it and provide 
-them for injection. All this can be done by either using JUnits <code>@RunWith</code> or 
-by simply creating a common base class for your unit tests which boots up the 
-container on your test classpath.</p>
-<p>There is no need to restart the container for each and every of your unit tests
-as this would cause a big performance loss. Instead it is usually sufficient to 
-use the CdiCtrls <code>ContextControl</code> mechanism to just stop and restart the 
-respective CDI Contexts.</p>
-<p>Such a base class could look roughly like the following:</p>
-<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">org.apache.deltaspike.cdise.api.CdiContainer</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.cdise.api.CdiContainerLoader</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.api.projectstage.ProjectStage</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.util.ProjectStageProducer</span><span class="o">;</span>
-<span class="kn">import</span> <span class="nn">org.apache.deltaspike.core.api.provider.BeanProvider</span><span class="o">;</span>
-
-<span class="kd">public</span> <span class="kd">abstract</span> <span class="kd">class</span> <span class="nc">ContainerTest</span> <span class="o">{</span>
-
-    <span class="kd">protected</span> <span class="kd">static</span> <span class="kd">volatile</span> <span class="n">CdiContainer</span> <span class="n">cdiContainer</span><span class="o">;</span>
-    <span class="c1">// nice to know, since testng executes tests in parallel.</span>
-    <span class="kd">protected</span> <span class="kd">static</span> <span class="kt">int</span> <span class="n">containerRefCount</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span>
-
-    <span class="kd">protected</span> <span class="n">ProjectStage</span> <span class="nf">runInProjectStage</span><span class="o">()</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">ProjectStage</span><span class="o">.</span><span class="na">UnitTest</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * Starts container</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="nd">@BeforeMethod</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">containerRefCount</span><span class="o">++;</span>
-
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="c1">// setting up the Apache DeltaSpike ProjectStage</span>
-            <span class="n">ProjectStage</span> <span class="n">projectStage</span> <span class="o">=</span> <span class="n">runInProjectStage</span><span class="o">();</span>
-            <span class="n">ProjectStageProducer</span><span class="o">.</span><span class="na">setProjectStage</span><span class="o">(</span><span class="n">projectStage</span><span class="o">);</span>
-
-            <span class="n">cdiContainer</span> <span class="o">=</span> <span class="n">CdiContainerLoader</span><span class="o">.</span><span class="na">getCdiContainer</span><span class="o">();</span>
-
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">boot</span><span class="o">();</span>
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContexts</span><span class="o">();</span>
-        <span class="o">}</span>
-        <span class="k">else</span> <span class="o">{</span>
-            <span class="n">cleanInstances</span><span class="o">();</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-
-    <span class="kd">public</span> <span class="kd">static</span> <span class="n">CdiContainer</span> <span class="nf">getCdiContainer</span><span class="o">()</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">cdiContainer</span><span class="o">;</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * This will fill all the InjectionPoints of the current test class for you</span>
-<span class="cm">     */</span>
-    <span class="nd">@BeforeClass</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeClass</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">beforeMethod</span><span class="o">();</span>
-
-        <span class="c1">// perform injection into the very own test class</span>
-        <span class="n">BeanManager</span> <span class="n">beanManager</span> <span class="o">=</span> <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getBeanManager</span><span class="o">();</span>
-
-        <span class="n">CreationalContext</span> <span class="n">creationalContext</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createCreationalContext</span><span class="o">(</span><span class="kc">null</span><span class="o">);</span>
-
-        <span class="n">AnnotatedType</span> <span class="n">annotatedType</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createAnnotatedType</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">getClass</span><span class="o">());</span>
-        <span class="n">InjectionTarget</span> <span class="n">injectionTarget</span> <span class="o">=</span> <span class="n">beanManager</span><span class="o">.</span><span class="na">createInjectionTarget</span><span class="o">(</span><span class="n">annotatedType</span><span class="o">);</span>
-        <span class="n">injectionTarget</span><span class="o">.</span><span class="na">inject</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="n">creationalContext</span><span class="o">);</span>
-
-        <span class="c1">// this is a trick we use to have proper DB transactions when using the entitymanager-per-request pattern</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-        <span class="n">cleanUpDb</span><span class="o">();</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * Shuts down container.</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="nd">@AfterMethod</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">afterMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">cleanInstances</span><span class="o">();</span>
-            <span class="n">containerRefCount</span><span class="o">--;</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-    <span class="cm">/**</span>
-<span class="cm">     * clean the NormalScoped contextual instances by stopping and restarting</span>
-<span class="cm">     * some contexts. You could also restart the ApplicationScoped context</span>
-<span class="cm">     * if you have some caches in your classes. </span>
-<span class="cm">     */</span>
-    <span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">cleanInstances</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">stopContext</span><span class="o">(</span><span class="n">RequestScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContext</span><span class="o">(</span><span class="n">RequestScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">stopContext</span><span class="o">(</span><span class="n">SessionScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">getContextControl</span><span class="o">().</span><span class="na">startContext</span><span class="o">(</span><span class="n">SessionScoped</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
-    <span class="o">}</span>
-
-    <span class="nd">@AfterSuite</span>
-    <span class="kd">public</span> <span class="kd">synchronized</span> <span class="kt">void</span> <span class="nf">shutdownContainer</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">cdiContainer</span><span class="o">.</span><span class="na">shutdown</span><span class="o">();</span>
-            <span class="n">cdiContainer</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
-        <span class="o">}</span>
-    <span class="o">}</span>
-
-    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">finalize</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Throwable</span> <span class="o">{</span>
-        <span class="n">shutdownContainer</span><span class="o">();</span>
-        <span class="kd">super</span><span class="o">.</span><span class="na">finalize</span><span class="o">();</span>
-    <span class="o">}</span>
-
-
-    <span class="cm">/**</span>
-<span class="cm">     * Override this method for database clean up.</span>
-<span class="cm">     *</span>
-<span class="cm">     * @throws Exception in case of severe problem</span>
-<span class="cm">     */</span>
-    <span class="kd">protected</span> <span class="kt">void</span> <span class="nf">cleanUpDb</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-        <span class="c1">//Override in subclasses when needed</span>
-    <span class="o">}</span>
-
-    <span class="kd">protected</span> <span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">T</span> <span class="n">getInstance</span><span class="o">(</span><span class="n">Class</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">type</span><span class="o">,</span> <span class="n">Qualifier</span><span class="o">...</span> <span class="n">qualifiers</span><span class="o">)</span> <span class="o">{</span>
-        <span class="k">return</span> <span class="n">BeanProvider</span><span class="o">.</span><span class="na">getContextualReference</span><span class="o">(</span><span class="n">type</span><span class="o">,</span> <span class="n">qualifiers</span><span class="o">);</span>
-    <span class="o">}</span>
-
-<span class="o">}</span>
-</pre></div>
 
-
-<h2 id="testing-javaee-applications">Testing JavaEE applications</h2>
-<p>You can also plug in a cdictrl backend for <a href="http://tomee.apache.org">Apache TomEE</a> 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 <code>deltaspike-cdictrl-owb</code> dependency in your pom with
-<code>deltaspike-cdictrl-openejb</code>. Since Apache TomEE and Apache OpenEJB both contain OpenWebBeans as CDI container
-you will get all the OWB functionality plus other JavaEE functionality.  </p>
-<p>You can pass DataSource configuration by simply providing a <code>Properties</code> instance to 
-<code>CdiContainer.boot(dbConfiguration)</code> in the beforeMethod method of the test class above:</p>
-<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">beforeMethod</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
-    <span class="n">containerRefCount</span><span class="o">++;</span>
-
-    <span class="k">if</span> <span class="o">(</span><span class="n">cdiContainer</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-        <span class="c1">// setting up the Apache DeltaSpike ProjectStage</span>
-        <span class="n">ProjectStage</span> <span class="n">projectStage</span> <span class="o">=</span> <span class="n">runInProjectStage</span><span class="o">();</span>
-        <span class="n">ProjectStageProducer</span><span class="o">.</span><span class="na">setProjectStage</span><span class="o">(</span><span class="n">projectStage</span><span class="o">);</span>
-        <span class="n">cdiContainer</span> <span class="o">=</span> <span class="n">CdiContainerLoader</span><span class="o">.</span><span class="na">getCdiContainer</span><span class="o">();</span>
-
-        <span class="n">Properties</span> <span class="n">dbProperties</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Properties</span><span class="o">();</span>
-        <span class="n">String</span> <span class="n">dbvendor</span> <span class="o">=</span> <span class="n">ConfigResolver</span><span class="o">.</span><span class="na">getPropertyValue</span><span class="o">(</span><span class="s">&quot;dbvendor&quot;</span><span class="o">,</span> <span class="s">&quot;h2&quot;</span><span class="o">);</span>
-        <span class="n">URL</span> <span class="n">dbPropertiesUrl</span> <span class="o">=</span>  <span class="n">getClass</span><span class="o">().</span><span class="na">getResource</span><span class="o">(</span><span class="s">&quot;/db/db-&quot;</span> <span class="o">+</span> <span class="n">dbvendor</span> <span class="o">+</span> <span class="s">&quot;.properties&quot;</span><span class="o">);</span>
-        <span class="k">if</span> <span class="o">(</span><span class="n">dbPropertiesUrl</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
-            <span class="n">InputStream</span> <span class="n">is</span> <span class="o">=</span> <span class="n">dbPropertiesUrl</span><span class="o">.</span><span class="na">openStream</span><span class="o">();</span>
-            <span class="k">try</span> <span class="o">{</span>
-                <span class="n">dbProperties</span><span class="o">.</span><span class="na">load</span><span class="o">(</span><span class="n">is</span><span class="o">);</span>
-            <span class="o">}</span>
-            <span class="k">finally</span> <span class="o">{</span>
-                <span class="n">is</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
-            <span class="o">}</span>
-        <span class="o">}</span>
-
-        <span class="n">cdiContainer</span><span class="o">.</span><span class="na">boot</span><span class="o">(</span><span class="n">dbProperties</span><span class="o">);</span>
-    <span class="o">}</span>
-    <span class="k">else</span> <span class="o">{</span>
-        <span class="n">cleanInstances</span><span class="o">();</span>
-    <span class="o">}</span>
-<span class="o">}</span>
+<span class="nt">&lt;dependency&gt;</span>
+    <span class="nt">&lt;groupId&gt;</span>org.apache.deltaspike.cdictrl<span class="nt">&lt;/groupId&gt;</span>
+    <span class="nt">&lt;artifactId&gt;</span>deltaspike-test-control-module-api<span class="nt">&lt;/artifactId&gt;</span>
+    <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
+    <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
+<span class="nt">&lt;/dependency&gt;</span>
+<span class="nt">&lt;dependency&gt;</span>
+    <span class="nt">&lt;groupId&gt;</span>org.apache.deltaspike.cdictrl<span class="nt">&lt;/groupId&gt;</span>
+    <span class="nt">&lt;artifactId&gt;</span>deltaspike-test-control-module-impl<span class="nt">&lt;/artifactId&gt;</span>
+    <span class="nt">&lt;version&gt;</span><span class="cp">${</span><span class="n">deltaspike</span><span class="o">.</span><span class="n">version</span><span class="cp">}</span><span class="nt">&lt;/version&gt;</span>
+    <span class="nt">&lt;scope&gt;</span>test<span class="nt">&lt;/scope&gt;</span>
+<span class="nt">&lt;/dependency&gt;</span>
 </pre></div>
 
 
-<p>The <code>db/db-mysql.properties</code> file for Apache OpenEJB (the former name of TomEE) would look like:</p>
-<div class="codehilite"><pre><span class="n">MYDS</span> <span class="p">=</span> <span class="n">new</span><span class="p">:</span><span class="o">//</span><span class="n">Resource</span>?<span class="n">type</span><span class="p">=</span><span class="n">DataSource</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JdbcDriver</span> <span class="p">=</span> <span class="n">org</span><span class="p">.</span><span class="n">h2</span><span class="p">.</span><span class="n">Driver</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JdbcUrl</span> <span class="p">=</span> <span class="n">jdbc</span><span class="p">:</span><span class="n">h2</span><span class="p">:</span><span class="n">file</span><span class="p">:</span><span class="o">/</span><span class="n">tmp</span><span class="o">/</span><span class="n">h2</span><span class="o">/</span><span class="n">myappdb</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">JtaManaged</span> <span class="p">=</span> <span class="n">true</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">UserName</span> <span class="p">=</span> <span class="n">sa</span>
-<span class="n">MYDS</span><span class="p">.</span><span class="n">Password</span> <span class="p">=</span>
-</pre></div>
+<p>Note that deltaspike-cdictrl-openejb can substitute the deltaspike-cdictrl-owb dependency if you are using TomEE.</p>
+<h2 id="why-use-test-control-for-your-unit-tests">Why use Test-Control for your unit tests?</h2>
+<p>Test-Control offers the strong testing capabilities of <code>CdiCtrl</code> 
+but let's you focus on writing the actual tests alone. <code>Test-Control</code> is the new lightweight champion for testing CDI and the required setup is very minimal.
+The testing flow is intuitive and follows the principles of other test runners. </p>
+<h2 id="examples-and-getting-started">Examples and Getting started</h2>
+<p>This information can be found here <a href="http://deltaspike.apache.org/test-control.html">Deltaspike documentation for Test-Control</a></p>
         </div>
 
         <hr>



Mime
View raw message