[CVS spice] More tests

sjoberg-yCVjj/[email protected] 12 Aug 2005 11:37:49 -0000
Newsgroups gmane.comp.java.spice.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>spice/components/jervlet/src/test/org/codehaus/spice/jervlet/containers/jetty/pico</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">PicoJettyContainerTestCase.java</a></tt></td><td align="right" id="added">+134</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">1.1 -&gt; 1.2</td></tr>
</table>
<pre class="comment">
More tests
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">spice/components/jervlet/src/test/org/codehaus/spice/jervlet/containers/jetty/pico<br /></span>
<div class="fileheader"><big><b>PicoJettyContainerTestCase.java</b></big> <small id="info">1.1 -&gt; 1.2</small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- PicoJettyContainerTestCase.java	10 Aug 2005 22:27:40 -0000	1.1
+++ PicoJettyContainerTestCase.java	12 Aug 2005 11:37:49 -0000	1.2
@@ -10,9 +10,19 @@
</small></pre><pre class="diff" id="context"> import junit.framework.TestCase;
 
 import java.util.Properties;
</pre><pre class="diff" id="added">+import java.io.File;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+import org.codehaus.spice.jervlet.impl.*;
+import org.codehaus.spice.jervlet.impl.pico.PicoInstantiator;
+import org.codehaus.spice.jervlet.ContextHandler;
+import org.codehaus.spice.jervlet.Context;
+import org.codehaus.spice.jervlet.Instantiator;
+import org.codehaus.spice.jervlet.Listener;
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">-import org.codehaus.spice.jervlet.impl.NoopContextMonitor;
-import org.codehaus.spice.jervlet.impl.NoopListenerMonitor;
</pre><pre class="diff" id="added">+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.defaults.DefaultPicoContainer;
</pre><pre class="diff" id="context"> 
 /**
  * TestCase for PicoJettyContainer
</pre><pre class="diff"><small id="info">@@ -23,6 +33,12 @@
</small></pre><pre class="diff" id="context"> {
     private static final String m_defaultConfiguration =
       "./testdata/jetty/jetty.xml";
</pre><pre class="diff" id="added">+    private static final String m_webapp1 =
+      "../../testdata/webapps/template";
+    private static final String m_webapp2 =
+      "../../testdata/webapps/template2.war";
+
+    private int m_count = 1;
</pre><pre class="diff" id="context"> 
     /**
      * Create an empty container and start/stop it.
</pre><pre class="diff"><small id="info">@@ -91,5 +107,121 @@
</small></pre><pre class="diff" id="context">                                                                new NoopListenerMonitor() );
         container.start();
         container.stop();
</pre><pre class="diff" id="added">+    }
+
+    /**
+     * Create an empty container and start, deploy a
+     * webapp and stop. Also test that the context
+     * are added and removed correctly.
+     *
+     * @throws Exception
+     */
+    public void testEmptyWithWebapps() throws Exception
+    {
+        Context context1 = getStandardContext( m_webapp1 );
+        Context context2 = getStandardContext( m_webapp2 );
+
+        PicoJettyContainer container = new PicoJettyContainer( null, null, null );
+        container.start();
+
+        ContextHandler contextHandler = container.createContextHandler();
+
+        contextHandler.addContext( context1 );
+        contextHandler.addContext( context2 );
+
+        contextHandler.startContext( context1 );
+        assertTrue( contextHandler.isStarted( context1 ) );
+        contextHandler.startContext( context2 );
+        assertTrue( contextHandler.isStarted( context1 ) );
+        assertTrue( contextHandler.isStarted( context2 ) );
+
+        contextHandler.stopContext( context1 );
+        assertFalse( contextHandler.isStarted( context1 ) );
+        contextHandler.stopContext( context2 );
+        assertFalse( contextHandler.isStarted( context1 ) );
+        assertFalse( contextHandler.isStarted( context2 ) );
+
+        assertTrue( 2 == contextHandler.getContexts().size() );
+        contextHandler.removeContext( context1 );
+        assertTrue( 1 == contextHandler.getContexts().size() );
+        contextHandler.removeContext( context2 );
+        assertTrue( 0 == contextHandler.getContexts().size() );
+
+        container.stop();
+    }
+
+    /**
+     * Test that a pico-servlet component gets instantiated
+     *
+     * --------------- UNDER CONSTRUCTION! ---------------
+     *
+     * @throws Exception
+     */
+    public void testEmptyWithPicoInstantiator() throws Exception
+    {
+        DefaultPicoContainer pico = new DefaultPicoContainer();
+        Context context = getPicoContext( m_webapp1, pico );
+
+        PicoJettyContainer container = new PicoJettyContainer( null, null, null );
+        container.start();
+
+        Listener listener = new DefaultListener( "localhost", 8421, Listener.HTTP );
+        container.addListener( listener );
+        container.startListener( listener );
+
+        ContextHandler contextHandler = container.createContextHandler();
+        contextHandler.addContext( context );
+        contextHandler.startContext( context );
+        contextHandler.stopContext( context );
+        contextHandler.removeContext( context );
+
+        container.stopListener( listener );
+        container.stop();
+    }
+
+    /**
+     * Create a basic context, using the standard servlet
+     * instantiator.
+     */
+    private Context getStandardContext( final String filePath )
+        throws MalformedURLException
+    {
+        String path = "context" + m_count++;
+        String[] virtualHosts = null;
+        URL resource = (new File( filePath )).toURL();
+        boolean extractWAR = false;
+        Instantiator instantiator = new StandardServletInstantiator();
+
+        DefaultContext context = new DefaultContext( path,
+                                                     virtualHosts,
+                                                     resource,
+                                                     extractWAR,
+                                                     instantiator );
+        return context;
+    }
+
+    /**
+     * Create a Pico context, using &lt;code&gt;PicoInstantiator&lt;/code&gt;.
+     *
+     * @filePath path to the web resource
+     * @pico a pico container for this context
+     *       (used when instantiation servlets)
+     */
+    private Context getPicoContext( final String filePath,
+                                    final MutablePicoContainer pico )
+        throws MalformedURLException
+    {
+        String path = "context" + m_count++;
+        String[] virtualHosts = null;
+        URL resource = (new File( filePath )).toURL();
+        boolean extractWAR = false;
+        Instantiator instantiator = new PicoInstantiator( pico );
+
+        DefaultContext context = new DefaultContext( path,
+                                                     virtualHosts,
+                                                     resource,
+                                                     extractWAR,
+                                                     instantiator );
+        return context;
</pre><pre class="diff" id="context">     }
 }
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.8</small></center>
</body></html>