From: markt Date: Mon, 29 Nov 2010 15:40:11 +0000 (+0000) Subject: Add a test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=50351 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=25f6520887d01de44662a08f168ec92b387d4507;p=tomcat7.0 Add a test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=50351 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1040158 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/org/apache/naming/resources/TestNamingContext.java b/test/org/apache/naming/resources/TestNamingContext.java index d374f51cd..2e7b84ebd 100644 --- a/test/org/apache/naming/resources/TestNamingContext.java +++ b/test/org/apache/naming/resources/TestNamingContext.java @@ -156,4 +156,55 @@ public class TestNamingContext extends TomcatBaseTest { } } } + + public void testBeanFactory() throws Exception { + Tomcat tomcat = getTomcatInstance(); + tomcat.enableNaming(); + + // Must have a real docBase - just use temp + StandardContext ctx = (StandardContext) + tomcat.addContext("", System.getProperty("java.io.tmpdir")); + + // Create the resource + ContextResource cr = new ContextResource(); + cr.setName("bug50351"); + cr.setType("org.apache.naming.resources.TesterObject"); + cr.setProperty("factory", "org.apache.naming.factory.BeanFactory"); + cr.setProperty("foo", "value"); + ctx.getNamingResources().addResource(cr); + + // Map the test Servlet + Bug50351Servlet bug50351Servlet = new Bug50351Servlet(); + Tomcat.addServlet(ctx, "bug50351Servlet", bug50351Servlet); + ctx.addServletMapping("/", "bug50351Servlet"); + + tomcat.start(); + + ByteChunk bc = getUrl("http://localhost:" + getPort() + "/"); + assertEquals("value", bc.toString()); + } + + public final class Bug50351Servlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/plain;UTF-8"); + PrintWriter out = resp.getWriter(); + + try { + Context ctx = new InitialContext(); + Object obj = ctx.lookup("java:comp/env/bug50351"); + TesterObject to = (TesterObject) obj; + out.print(to.getFoo()); + } catch (NamingException ne) { + ne.printStackTrace(out); + } + } + } + + } diff --git a/test/org/apache/naming/resources/TesterObject.java b/test/org/apache/naming/resources/TesterObject.java index 4f16aa06c..1f09489a3 100644 --- a/test/org/apache/naming/resources/TesterObject.java +++ b/test/org/apache/naming/resources/TesterObject.java @@ -18,8 +18,18 @@ package org.apache.naming.resources; public class TesterObject { + private String foo; + @Override public String toString() { return "This is a test object (" + super.toString() + ")."; } + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getFoo() { + return this.foo; + } }