Author: buildbot
Date: Wed Feb  4 19:18:24 2015
New Revision: 938999

Log:
Staging update by buildbot for deltaspike

Modified:
    websites/staging/deltaspike/trunk/content/   (props changed)
    websites/staging/deltaspike/trunk/content/documentation/test-control.html

Propchange: websites/staging/deltaspike/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Feb  4 19:18:24 2015
@@ -1 +1 @@
-1657319
+1657380

Modified: 
websites/staging/deltaspike/trunk/content/documentation/test-control.html
==============================================================================
--- websites/staging/deltaspike/trunk/content/documentation/test-control.html 
(original)
+++ websites/staging/deltaspike/trunk/content/documentation/test-control.html 
Wed Feb  4 19:18:24 2015
@@ -232,6 +232,7 @@ body {
 <li><a href="#_jsf_via_myfaces_test">JSF (via MyFaces-Test)</a></li>
 </ul>
 </li>
+<li><a href="#_using_jersey_test_with_test_control">Using jersey-test with 
test-control</a></li>
 <li><a href="#_mixed_tests">Mixed Tests</a></li>
 <li><a href="#_known_restrictions">Known Restrictions</a>
 <ul class="sectlevel3">
@@ -732,6 +733,80 @@ constructor) and specify the target-type
 </div>
 </div>
 </div>
+<div class="sect2">
+<h3 id="_using_jersey_test_with_test_control">Using jersey-test with 
test-control</h3>
+<div class="paragraph">
+<p>jersey-test starts jetty which answers requests in a separated thread. 
since ds test-control just handles the thread of the test itself, it&#8217;s 
needed to integrate jetty and jersey with the cdi-container. usually 
that&#8217;s done via a ServletRequestListener - the following part describes 
an alternative approach for jersey-test:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="CodeRay highlight"><code data-lang="java"><span 
class="comment">//use: 
-Djersey.config.test.container.factory=custom.CdiAwareJettyTestContainerFactory</span>
+
+<span class="annotation">@RunWith</span>(CdiTestRunner.class)
+<span class="directive">public</span> <span class="type">class</span> <span 
class="class">SimpleCdiAndJaxRsTest</span> <span 
class="directive">extends</span> JerseyTest {
+  <span class="comment">//...</span>
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>or</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="CodeRay highlight"><code data-lang="java"><span 
class="directive">public</span> <span class="type">class</span> <span 
class="class">CdiAwareJerseyTest</span> <span class="directive">extends</span> 
JerseyTest {
+    <span class="directive">static</span> {
+        <span class="predefined-type">System</span>.setProperty(<span 
class="string"><span class="delimiter">&quot;</span><span 
class="content">jersey.config.test.container.factory</span><span 
class="delimiter">&quot;</span></span>,CdiAwareJettyTestContainerFactory.class.getName());
+    }
+}
+
+<span class="annotation">@RunWith</span>(CdiTestRunner.class)
+<span class="directive">public</span> <span class="type">class</span> <span 
class="class">SimpleCdiAndJaxRsTest</span> <span 
class="directive">extends</span> CdiAwareJerseyTest {
+    <span class="comment">//...</span>
+}</code></pre>
+</div>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="CodeRay highlight"><code data-lang="java"><span 
class="directive">public</span> <span class="type">class</span> <span 
class="class">CdiAwareJettyTestContainerFactory</span> <span 
class="directive">implements</span> TestContainerFactory {
+    <span class="annotation">@Override</span>
+    <span class="directive">public</span> TestContainer create(<span 
class="directive">final</span> <span class="predefined-type">URI</span> 
baseUri, <span class="directive">final</span> DeploymentContext context) <span 
class="directive">throws</span> <span 
class="exception">IllegalArgumentException</span> {
+        <span class="keyword">return</span> <span class="keyword">new</span> 
CdiAwareJettyTestContainer(baseUri, context);
+    }
+}</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>CdiAwareJettyTestContainer is a copy of 
JettyTestContainerFactory.JettyTestContainer but with</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="CodeRay highlight"><code data-lang="java">HandlerWrapper 
cdiHandlerWrapper = <span class="keyword">new</span> CdiAwareHandlerWrapper();
+cdiHandlerWrapper.setHandler(<span 
class="local-variable">this</span>.server.getHandler());
+<span 
class="local-variable">this</span>.server.setHandler(cdiHandlerWrapper);</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>after the line with JettyHttpContainerFactory#createServer</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="CodeRay highlight"><code data-lang="java"><span 
class="comment">//activate the request-context e.g. via:</span>
+<span class="directive">public</span> <span class="type">class</span> <span 
class="class">CdiAwareHandlerWrapper</span> <span 
class="directive">extends</span> HandlerWrapper {
+    <span class="annotation">@Override</span>
+    <span class="directive">public</span> <span class="type">void</span> 
handle(<span class="predefined-type">String</span> target, Request baseRequest, 
HttpServletRequest request, HttpServletResponse response) <span 
class="directive">throws</span> <span class="exception">IOException</span>, 
ServletException {
+        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
+
+        <span class="keyword">try</span> {
+            cdiContainer.getContextControl().startContext(RequestScoped.class);
+            <span class="local-variable">super</span>.handle(target, 
baseRequest, request, response);
+        } <span class="keyword">finally</span> {
+            cdiContainer.getContextControl().stopContext(RequestScoped.class);
+        }
+    }
+}</code></pre>
+</div>
+</div>
+</div>
 <div class="sect2">
 <h3 id="_mixed_tests">Mixed Tests</h3>
 <div class="paragraph">


Reply via email to