[CVS spice] add in another test case that illustrates my idea on how to combine jervlet into pico/nano
proyal-yCVjj/[email protected] 8 Aug 2005 02:33:44 -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</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt>java/org/codehaus/spice/jervlet/impl/pico/<a href="#file1"><span id="added">JervletNanoContainerBuilderDecorationDelegate.java</span></a></tt></td><td align="right" id="added">+17</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt>test/org/codehaus/spice/jervlet/impl/pico/<a href="#file2"><span id="added">delegate.groovy</span></a></tt></td><td align="right" id="added">+10</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file3">AnotherTestCase.java</a></tt></td><td align="right" id="added">+68</td><td align="right" id="removed">-34</td><td nowrap="nowrap" align="center">1.1 -> 1.2</td></tr>
<tr><td></td><td align="right" id="added">+95</td><td align="right" id="removed">-34</td><td></td></tr>
</table>
<small id="info">2 added + 1 modified, total 3 files</small><br />
<pre class="comment">
add in another test case that illustrates my idea on how to combine jervlet into pico/nano
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname" id="added">spice/components/jervlet/src/java/org/codehaus/spice/jervlet/impl/pico<br /></span>
<div class="fileheader" id="added"><big><b>JervletNanoContainerBuilderDecorationDelegate.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N JervletNanoContainerBuilderDecorationDelegate.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ JervletNanoContainerBuilderDecorationDelegate.java 8 Aug 2005 02:33:44 -0000 1.1
@@ -0,0 +1,17 @@
</small></pre><pre class="diff" id="added">+/*
+ * Copyright (C) The Spice Group. All rights reserved.
+ *
+ * This software is published under the terms of the Spice
+ * Software License version 1.1, a copy of which has been included
+ * with this distribution in the LICENSE.txt file.
+ */
+package org.codehaus.spice.jervlet.impl.pico;
+
+import org.nanocontainer.script.NullNanoContainerBuilderDecorationDelegate;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class JervletNanoContainerBuilderDecorationDelegate extends NullNanoContainerBuilderDecorationDelegate
+{
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname" id="added">spice/components/jervlet/src/test/org/codehaus/spice/jervlet/impl/pico<br /></span>
<div class="fileheader" id="added"><big><b>delegate.groovy</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N delegate.groovy
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ delegate.groovy 8 Aug 2005 02:33:44 -0000 1.1
@@ -0,0 +1,10 @@
</small></pre><pre class="diff" id="added">+package org.codehaus.spice.jervlet.impl.pico
+
+import org.nanocontainer.script.groovy.NanoContainerBuilder;
+
+builder = new NanoContainerBuilder( new JervletNanoContainerBuilderDecorationDelegate() );
+pico = builder.container {
+ webserver()
+ webapp( context : "foo/", warPath : "foo.war" )
+ component( A )
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname">spice/components/jervlet/src/test/org/codehaus/spice/jervlet/impl/pico<br /></span>
<div class="fileheader"><big><b>AnotherTestCase.java</b></big> <small id="info">1.1 -> 1.2</small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- AnotherTestCase.java 27 Jul 2005 13:05:27 -0000 1.1
+++ AnotherTestCase.java 8 Aug 2005 02:33:44 -0000 1.2
@@ -1,53 +1,87 @@
</small></pre><pre class="diff" id="context"> package org.codehaus.spice.jervlet.impl.pico;
</pre><pre class="diff" id="added">+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+
</pre><pre class="diff" id="context"> import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyCodeSource;
import groovy.lang.Script;
import junit.framework.TestCase;
</pre><pre class="diff" id="removed">-import org.codehaus.groovy.runtime.InvokerHelper;
</pre><pre class="diff" id="context"> import org.codehaus.groovy.control.CompilationFailedException;
</pre><pre class="diff" id="added">+import org.codehaus.groovy.runtime.InvokerHelper;
+import org.nanocontainer.script.groovy.GroovyContainerBuilder;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.defaults.DefaultPicoContainer;
+import org.picocontainer.defaults.ObjectReference;
+import org.picocontainer.defaults.SimpleReference;
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
</pre><pre class="diff" id="added">+public class AnotherTestCase extends TestCase
+{
+ public void testJervletNanoContainerBuilderDecorationDelegate() throws Exception
+ {
+ final InputStream script = getClass().getResourceAsStream( "delegate.groovy" );
+
+ createContainer( new InputStreamReader( script ) );
+ assertEquals( "", "" );
+ }
+
+ protected PicoContainer createContainer( final Reader reader ) throws CompilationFailedException
+ {
+ final ObjectReference containerRef = new SimpleReference();
+ final ObjectReference parentContainerRef = new SimpleReference();
+ final PicoContainer parent = new DefaultPicoContainer();
+ final GroovyContainerBuilder builder = new GroovyContainerBuilder( reader, getClass().getClassLoader() );
+
+ parentContainerRef.set( parent );
+ builder.buildContainer( containerRef, parentContainerRef, "SOME_SCOPE", true );
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-public class AnotherTestCase extends TestCase {
- public void testContainerCanBeBuiltWithParent() throws CompilationFailedException {
- final Reader script = new StringReader("" +
- "package org.codehaus.spice.jervlet.impl.pico\n" +
- "import org.codehaus.spice.jervlet.impl.pico.NanoGroovyWebContainerBuilder\n" +
- "import org.picocontainer.defaults.DefaultPicoContainer\n" +
- "def pc = new DefaultPicoContainer()\n" +
- "pc.registerComponentInstance(String.class, \"Foo\")\n" +
- "def builder = new NanoGroovyWebContainerBuilder()\n" +
- "def webServer = builder.picoEnabledWebServer(pico:pc, host:\"localhost\", port:8099) {\n" +
- " webApp(warPath:\"foo/bar\")\n" +
- " webApp {\n" +
- " servlet(context:\"/foo\", servletClass:\"foo.bar.AServlet\")\n" +
- " }\n" +
- "}\n" +
- "webServer.start()\n"
- );
- doGroovy(new InputStream() {
- public int read() throws IOException {
</pre><pre class="diff" id="added">+ return (PicoContainer)containerRef.get();
+ }
+
+ public void testContainerCanBeBuiltWithParent() throws CompilationFailedException
+ {
+ final Reader script = new StringReader(
+ "package org.codehaus.spice.jervlet.impl.pico\n" +
+ "import org.codehaus.spice.jervlet.impl.pico.NanoGroovyWebContainerBuilder\n"
+ +
+ "import org.picocontainer.defaults.DefaultPicoContainer\n" +
+ "def pc = new DefaultPicoContainer()\n" +
+ "pc.registerComponentInstance(String.class, \"Foo\")\n" +
+ "def builder = new NanoGroovyWebContainerBuilder()\n" +
+ "def webServer = builder.picoEnabledWebServer(pico:pc, host:\"localhost\", port:8099) {\n"
+ +
+ " webApp(warPath:\"foo/bar\")\n" +
+ " webApp {\n" +
+ " servlet(context:\"/foo\", servletClass:\"foo.bar.AServlet\")\n" +
+ " }\n" +
+ "}\n" +
+ "webServer.start()\n"
+ );
+ doGroovy( new InputStream()
+ {
+ public int read() throws IOException
+ {
</pre><pre class="diff" id="context"> return script.read();
}
</pre><pre class="diff" id="removed">- });
- assertEquals("", "");
</pre><pre class="diff" id="added">+ } );
+ assertEquals( "", "" );
</pre><pre class="diff" id="context"> }
</pre><pre class="diff" id="removed">- protected void doGroovy(InputStream is) throws CompilationFailedException {
</pre><pre class="diff" id="added">+ protected void doGroovy( InputStream is ) throws CompilationFailedException
+ {
</pre><pre class="diff" id="context"> Script groovyScript = null;
</pre><pre class="diff" id="removed">- GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
- GroovyCodeSource groovyCodeSource = new GroovyCodeSource(is, "nanocontainer.groovy", "groovyGeneratedForNanoContainer");
- Class scriptClass = loader.parseClass(groovyCodeSource);
- groovyScript = InvokerHelper.createScript(scriptClass, null);
</pre><pre class="diff" id="added">+ GroovyClassLoader loader = new GroovyClassLoader( getClass().getClassLoader() );
+ GroovyCodeSource groovyCodeSource = new GroovyCodeSource( is,
+ "nanocontainer.groovy",
+ "groovyGeneratedForNanoContainer" );
+ Class scriptClass = loader.parseClass( groovyCodeSource );
+ groovyScript = InvokerHelper.createScript( scriptClass, null );
</pre><pre class="diff" id="context"> Binding binding = new Binding();
</pre><pre class="diff" id="removed">- groovyScript.setBinding(<span id="removedchars">binding</span>);
</pre><pre class="diff" id="added">+ groovyScript.setBinding(<span id="addedchars"> binding </span>);
</pre><pre class="diff" id="context"> Object result = groovyScript.run();
}
</pre><pre class="diff" id="removed">-
-
</pre><pre class="diff" id="context"> }
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.8</small></center>
</body></html>