01: package org.nanocontainer.webcontainer;
02:
03: import java.io.IOException;
04:
05: import org.picocontainer.defaults.DefaultPicoContainer;
06:
07: public class DependencyInjectionFilterTestCase extends
08: WebContainerTestCase {
09:
10: PicoJettyServer server;
11:
12: protected void tearDown() throws Exception {
13: if (server != null) {
14: server.stop();
15: }
16: }
17:
18: public void testCanInstantiateWebContainerContextAndFilter()
19: throws InterruptedException, IOException {
20:
21: final DefaultPicoContainer parentContainer = new DefaultPicoContainer();
22: parentContainer.registerComponentInstance(String.class, "Fred");
23: parentContainer.registerComponentInstance(Integer.class,
24: new Integer(5));
25:
26: server = new PicoJettyServer("localhost", 8080, parentContainer);
27: PicoContext barContext = server.createContext("/bar", false);
28: PicoFilterHolder filterHolder = barContext
29: .addFilterWithMapping(
30: DependencyInjectionTestFilter.class, "/*", 0);
31: filterHolder.setInitParameter("foo", "bau");
32: barContext.addServletWithMapping(
33: DependencyInjectionTestServlet.class, "/foo2");
34: server.start();
35:
36: assertEquals("hello Fred Filtered!(int= 5 bau)",
37: getPage("http://localhost:8080/bar/foo2"));
38:
39: }
40:
41: public void testCanInstantiateWebContainerContextAndFilterInstance()
42: throws InterruptedException, IOException {
43:
44: final DefaultPicoContainer parentContainer = new DefaultPicoContainer();
45: parentContainer.registerComponentInstance(String.class, "Fred");
46:
47: server = new PicoJettyServer("localhost", 8080, parentContainer);
48: PicoContext barContext = server.createContext("/bar", false);
49: DependencyInjectionTestFilter filter = (DependencyInjectionTestFilter) barContext
50: .addFilterWithMapping(
51: new DependencyInjectionTestFilter(
52: new Integer(5)), "/*", 0);
53: filter.setFoo("bau");
54: barContext.addServletWithMapping(
55: DependencyInjectionTestServlet.class, "/foo2");
56: server.start();
57:
58: assertEquals("hello Fred Filtered!(int= 5 bau)",
59: getPage("http://localhost:8080/bar/foo2"));
60:
61: }
62:
63: public void testCanInstantiateWebContainerContextAndServlet()
64: throws InterruptedException, IOException {
65:
66: final DefaultPicoContainer parentContainer = new DefaultPicoContainer();
67: parentContainer.registerComponentInstance(String.class, "Fred");
68: parentContainer.registerComponentInstance(Integer.class,
69: new Integer(5));
70:
71: server = new PicoJettyServer("localhost", 8080, parentContainer);
72: PicoContext barContext = server.createContext("/bar", false);
73: barContext.addFilterWithMapping(
74: DependencyInjectionTestFilter.class, "/*", 0);
75: PicoServletHolder holder = barContext.addServletWithMapping(
76: DependencyInjectionTestServlet.class, "/foo2");
77: holder.setInitParameter("foo", "bau");
78: server.start();
79:
80: assertEquals("hello Fred Filtered!(int= 5) bau",
81: getPage("http://localhost:8080/bar/foo2"));
82:
83: }
84:
85: }
|