You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2006/08/24 20:41:43 UTC
svn commit: r434464 - in /hivemind/branches/branch-2-0-annot: ./
framework/src/java/org/apache/hivemind/servlet/
framework/src/test/org/apache/hivemind/servlet/
xml/src/descriptor/META-INF/ xml/src/java/org/apache/hivemind/servlet/
xml/src/test/org/apa...
Author: ahuegen
Date: Thu Aug 24 11:41:42 2006
New Revision: 434464
URL: http://svn.apache.org/viewvc?rev=434464&view=rev
Log:
Introduced a base version for the hivemind servlet which is not xml specific
Added:
hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java (contents, props changed)
- copied, changed from r431096, hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java (contents, props changed)
- copied, changed from r431431, hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java
hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/servlet/
hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/servlet/
hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java
Removed:
hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java
Modified:
hivemind/branches/branch-2-0-annot/.project
hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/hivemodule.xml
Modified: hivemind/branches/branch-2-0-annot/.project
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/.project?rev=434464&r1=434463&r2=434464&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/.project (original)
+++ hivemind/branches/branch-2-0-annot/.project Thu Aug 24 11:41:42 2006
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jakarta-hivemind</name>
+ <name>jakarta-hivemind-2</name>
<comment>HiveMind is a dynamic services and configuration microkernel. Its primary feature is the dynamic creation of a runtime registry of services and configuration data, where any HiveMind module may contribute extensions to any other HiveMind module.</comment>
<projects>
</projects>
Copied: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java (from r431096, hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java)
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java?p2=hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java&p1=hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java&r1=431096&r2=434464&rev=434464&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java Thu Aug 24 11:41:42 2006
@@ -32,19 +32,22 @@
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.util.ContextResource;
/**
* Servlet filter that constructs the Registry at startup. It ensures that each request is properly
* terminated with a call to
* {@link org.apache.hivemind.service.ThreadEventNotifier#fireThreadCleanup()}. It also makes the
* Registry available during the request by storing it as a request attribute.
+ * Autodetects hivemind modules by calling {@link RegistryBuilder#autoDetectModules()}.
+ *
+ * Specializations can override the {@link #addWebInfDescriptor(ServletContext, ClassResolver, RegistryBuilder)} method.
+ * to add custom modules.
*
* @author Howard Lewis Ship
*/
-public class HiveMindFilter implements Filter
+public class AutoloadingHiveMindFilter implements Filter
{
- private static final Log LOG = LogFactory.getLog(HiveMindFilter.class);
+ private static final Log LOG = LogFactory.getLog(AutoloadingHiveMindFilter.class);
/**
* Request attribute key that stores the Registry.
@@ -54,9 +57,6 @@
static final String REBUILD_REQUEST_KEY = "org.apache.hivemind.RebuildRegistry";
- /** @since 1.1 */
- static final String HIVE_MODULE_XML = "/WEB-INF/hivemodule.xml";
-
private FilterConfig _filterConfig;
private Registry _registry;
@@ -111,23 +111,13 @@
}
/**
- * Invoked from {@link #constructRegistry(FilterConfig)} to add WEB-INF/hivemodule.xml to
- * the registry, if it exists.
+ * Invoked from {@link #constructRegistry(FilterConfig)} to add an web specific
+ * application descriptor if one exists.
*
- * @since 1.1
*/
-
protected void addWebInfDescriptor(ServletContext context, ClassResolver resolver,
RegistryBuilder builder)
{
- ContextResource r = new ContextResource(context, HIVE_MODULE_XML);
-
-// if (r.getResourceURL() != null)
-// {
-// XmlModuleReader reader = new XmlModuleReader(builder.getRegistryDefinition(),
-// resolver, builder.getErrorHandler());
-// reader.readModule(r);
-// }
}
/**
Propchange: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java
------------------------------------------------------------------------------
cvs2svn:cvs-rev = 1.20
Propchange: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/servlet/AutoloadingHiveMindFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Copied: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java (from r431431, hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java)
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java?p2=hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java&p1=hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java&r1=431431&r2=434464&rev=434464&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java Thu Aug 24 11:41:42 2006
@@ -38,11 +38,11 @@
import org.easymock.MockControl;
/**
- * Tests for {@link org.apache.hivemind.servlet.HiveMindFilter}.
+ * Tests for {@link org.apache.hivemind.servlet.AutoloadingHiveMindFilter}.
*
* @author Howard Lewis Ship
*/
-public class TestHiveMindFilter extends HiveMindTestCase
+public class TestAutoloadingHiveMindFilter extends HiveMindTestCase
{
private static class ThreadListenerFixture implements ThreadCleanupListener
{
@@ -76,7 +76,7 @@
}
- private static class FailingHiveMindFilterFixture extends HiveMindFilter
+ private static class FailingAutoloadingHiveMindFilterFixture extends AutoloadingHiveMindFilter
{
protected Registry constructRegistry(FilterConfig config)
@@ -86,7 +86,7 @@
}
- private static class RegistryExposingHiveMindFilterFixture extends HiveMindFilter
+ private static class RegistryExposingAutoloadingHiveMindFilterFixture extends AutoloadingHiveMindFilter
{
private Registry _registry;
@@ -109,48 +109,17 @@
public void doFilter(ServletRequest request, ServletResponse response) throws IOException,
ServletException
{
- HiveMindFilter.rebuildRegistry((HttpServletRequest) request);
+ AutoloadingHiveMindFilter.rebuildRegistry((HttpServletRequest) request);
}
}
- /** @since 1.1 */
-
- public void testLoadsFromWebInf() throws Exception
- {
- MockControl contextc = newControl(ServletContext.class);
- ServletContext context = (ServletContext) contextc.getMock();
-
- MockControl configc = newControl(FilterConfig.class);
- FilterConfig config = (FilterConfig) configc.getMock();
-
- config.getServletContext();
- configc.setReturnValue(context);
-
- URL url = getClass().getResource("webinf-hivemodule.xml");
-
- context.getResource(HiveMindFilter.HIVE_MODULE_XML);
- contextc.setReturnValue(url, 2);
-
- replayControls();
-
- RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
-
- f.init(config);
-
- Registry r = f.getRegistry();
-
- assertEquals("was here", r.expandSymbols("${kilroy}", null));
-
- verifyControls();
- }
-
public void testBasic() throws Exception
{
FilterConfig filterConfig = newFilterConfig();
replayControls();
- RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
+ RegistryExposingAutoloadingHiveMindFilterFixture f = new RegistryExposingAutoloadingHiveMindFilterFixture();
f.init(filterConfig);
@@ -173,21 +142,21 @@
HttpServletResponse response = (HttpServletResponse) newMock(HttpServletResponse.class);
FilterChain chain = (FilterChain) newMock(FilterChain.class);
- request.setAttribute(HiveMindFilter.REQUEST_KEY, r);
+ request.setAttribute(AutoloadingHiveMindFilter.REQUEST_KEY, r);
chain.doFilter(request, response);
- request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
+ request.getAttribute(AutoloadingHiveMindFilter.REBUILD_REQUEST_KEY);
requestControl.setReturnValue(null);
- request.getAttribute(HiveMindFilter.REQUEST_KEY);
+ request.getAttribute(AutoloadingHiveMindFilter.REQUEST_KEY);
requestControl.setReturnValue(r);
replayControls();
f.doFilter(request, response, chain);
- assertSame(r, HiveMindFilter.getRegistry(request));
+ assertSame(r, AutoloadingHiveMindFilter.getRegistry(request));
assertEquals(true, l.getCleanup());
@@ -217,12 +186,9 @@
filterConfig.getServletContext();
configc.setReturnValue(context);
- context.getResource(HiveMindFilter.HIVE_MODULE_XML);
- contextc.setReturnValue(null);
-
replayControls();
- RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
+ RegistryExposingAutoloadingHiveMindFilterFixture f = new RegistryExposingAutoloadingHiveMindFilterFixture();
f.init(filterConfig);
@@ -244,19 +210,16 @@
HttpServletResponse response = (HttpServletResponse) newMock(HttpServletResponse.class);
FilterChain chain = new RebuildRegistryChainFixture();
- request.setAttribute(HiveMindFilter.REQUEST_KEY, r);
+ request.setAttribute(AutoloadingHiveMindFilter.REQUEST_KEY, r);
- request.setAttribute(HiveMindFilter.REBUILD_REQUEST_KEY, Boolean.TRUE);
+ request.setAttribute(AutoloadingHiveMindFilter.REBUILD_REQUEST_KEY, Boolean.TRUE);
- request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
+ request.getAttribute(AutoloadingHiveMindFilter.REBUILD_REQUEST_KEY);
requestControl.setReturnValue(Boolean.TRUE);
filterConfig.getServletContext();
configc.setReturnValue(context);
- context.getResource(HiveMindFilter.HIVE_MODULE_XML);
- contextc.setReturnValue(null);
-
replayControls();
f.doFilter(request, response, chain);
@@ -272,9 +235,6 @@
ServletContext context = (ServletContext) control.getMock();
- context.getResource(HiveMindFilter.HIVE_MODULE_XML);
- control.setReturnValue(null);
-
return newFilterConfig(context);
}
@@ -291,9 +251,9 @@
public void testExceptionInInit() throws Exception
{
- Filter f = new FailingHiveMindFilterFixture();
+ Filter f = new FailingAutoloadingHiveMindFilterFixture();
- interceptLogging(HiveMindFilter.class.getName());
+ interceptLogging(AutoloadingHiveMindFilter.class.getName());
f.init(null);
@@ -304,11 +264,11 @@
HttpServletResponse response = (HttpServletResponse) newMock(HttpServletResponse.class);
FilterChain chain = (FilterChain) newMock(FilterChain.class);
- request.setAttribute(HiveMindFilter.REQUEST_KEY, null);
+ request.setAttribute(AutoloadingHiveMindFilter.REQUEST_KEY, null);
chain.doFilter(request, response);
- request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
+ request.getAttribute(AutoloadingHiveMindFilter.REBUILD_REQUEST_KEY);
requestControl.setReturnValue(null);
replayControls();
@@ -322,27 +282,27 @@
public void testDestroyWithoutRepository()
{
- Filter f = new HiveMindFilter();
+ Filter f = new AutoloadingHiveMindFilter();
f.destroy();
}
public void testFilterWithoutRepository() throws Exception
{
- Filter f = new HiveMindFilter();
+ Filter f = new AutoloadingHiveMindFilter();
- interceptLogging(HiveMindFilter.class.getName());
+ interceptLogging(AutoloadingHiveMindFilter.class.getName());
MockControl requestControl = newControl(HttpServletRequest.class);
HttpServletRequest request = (HttpServletRequest) requestControl.getMock();
HttpServletResponse response = (HttpServletResponse) newMock(HttpServletResponse.class);
FilterChain chain = (FilterChain) newMock(FilterChain.class);
- request.setAttribute(HiveMindFilter.REQUEST_KEY, null);
+ request.setAttribute(AutoloadingHiveMindFilter.REQUEST_KEY, null);
chain.doFilter(request, response);
- request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
+ request.getAttribute(AutoloadingHiveMindFilter.REBUILD_REQUEST_KEY);
requestControl.setReturnValue(null);
replayControls();
Propchange: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java
------------------------------------------------------------------------------
cvs2svn:cvs-rev = 1.5
Propchange: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/servlet/TestAutoloadingHiveMindFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/hivemodule.xml
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/hivemodule.xml?rev=434464&r1=434463&r2=434464&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/hivemodule.xml (original)
+++ hivemind/branches/branch-2-0-annot/xml/src/descriptor/META-INF/hivemodule.xml Thu Aug 24 11:41:42 2006
@@ -465,7 +465,7 @@
<create-instance class="service.impl.BuilderFactory" model="primitive"/>
</service-point>
- <schema configuration-id="ServiceModels">
+ <schema id="ServiceModels" configuration-id="hivemind.ServiceModels">
Describes contributions that define new types of service models by providing service model factories.
Added: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/servlet/HiveMindFilter.java?rev=434464&view=auto
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/servlet/HiveMindFilter.java (added)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/servlet/HiveMindFilter.java Thu Aug 24 11:41:42 2006
@@ -0,0 +1,49 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.hivemind.servlet;
+
+import javax.servlet.ServletContext;
+
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.impl.RegistryBuilder;
+import org.apache.hivemind.impl.XmlModuleReader;
+import org.apache.hivemind.util.ContextResource;
+
+/**
+ * Specializations of {@link AutoloadingHiveMindFilter} that additionally loads a xml
+ * module from "/WEB-INF/hivemodule.xml".
+ * Actually should be called XmlHiveMindFilter but is not for sake of
+ * backward compatibility.
+ *
+ * @author Achim Huegen
+ */
+public class HiveMindFilter extends AutoloadingHiveMindFilter
+{
+ static final String HIVE_MODULE_XML = "/WEB-INF/hivemodule.xml";
+
+ protected void addWebInfDescriptor(ServletContext context, ClassResolver resolver,
+ RegistryBuilder builder)
+ {
+ ContextResource r = new ContextResource(context, HIVE_MODULE_XML);
+
+ if (r.getResourceURL() != null)
+ {
+ XmlModuleReader reader = new XmlModuleReader(builder.getRegistryDefinition(),
+ resolver, builder.getErrorHandler());
+ reader.readModule(r);
+ }
+ }
+
+}
\ No newline at end of file
Added: hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java?rev=434464&view=auto
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java (added)
+++ hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/servlet/TestHiveMindFilter.java Thu Aug 24 11:41:42 2006
@@ -0,0 +1,282 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.hivemind.servlet;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.HiveMind;
+import org.apache.hivemind.Registry;
+import org.apache.hivemind.ShutdownCoordinator;
+import org.apache.hivemind.events.RegistryShutdownListener;
+import org.apache.hivemind.service.ThreadCleanupListener;
+import org.apache.hivemind.service.ThreadEventNotifier;
+import org.apache.hivemind.test.HiveMindTestCase;
+import org.easymock.MockControl;
+
+/**
+ * Tests for {@link org.apache.hivemind.servlet.HiveMindFilter}.
+ *
+ * @author Howard Lewis Ship
+ */
+public class TestHiveMindFilter extends HiveMindTestCase
+{
+ private static class ThreadListenerFixture implements ThreadCleanupListener
+ {
+ private boolean _cleanup;
+
+ public void threadDidCleanup()
+ {
+ _cleanup = true;
+ }
+
+ public boolean getCleanup()
+ {
+ return _cleanup;
+ }
+
+ }
+
+ private static class ShutdownListenerFixture implements RegistryShutdownListener
+ {
+ private boolean _didShutdown;
+
+ public void registryDidShutdown()
+ {
+ _didShutdown = true;
+ }
+
+ public boolean getDidShutdown()
+ {
+ return _didShutdown;
+ }
+
+ }
+
+ private static class RegistryExposingHiveMindFilterFixture extends HiveMindFilter
+ {
+
+ private Registry _registry;
+
+ public Registry getRegistry()
+ {
+ return _registry;
+ }
+
+ protected Registry constructRegistry(FilterConfig config)
+ {
+ _registry = super.constructRegistry(config);
+ return _registry;
+ }
+
+ }
+
+ private static class RebuildRegistryChainFixture implements FilterChain
+ {
+ public void doFilter(ServletRequest request, ServletResponse response) throws IOException,
+ ServletException
+ {
+ HiveMindFilter.rebuildRegistry((HttpServletRequest) request);
+ }
+ }
+
+ /** @since 1.1 */
+
+ public void testLoadsFromWebInf() throws Exception
+ {
+ MockControl contextc = newControl(ServletContext.class);
+ ServletContext context = (ServletContext) contextc.getMock();
+
+ MockControl configc = newControl(FilterConfig.class);
+ FilterConfig config = (FilterConfig) configc.getMock();
+
+ config.getServletContext();
+ configc.setReturnValue(context);
+
+ URL url = getClass().getResource("webinf-hivemodule.xml");
+
+ context.getResource(HiveMindFilter.HIVE_MODULE_XML);
+ contextc.setReturnValue(url, 2, 3);
+
+ replayControls();
+
+ RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
+
+ f.init(config);
+
+ Registry r = f.getRegistry();
+
+ assertEquals("was here", r.expandSymbols("${kilroy}", null));
+
+ verifyControls();
+ }
+
+ public void testBasic() throws Exception
+ {
+ FilterConfig filterConfig = newFilterConfig();
+
+ replayControls();
+
+ RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
+
+ f.init(filterConfig);
+
+ verifyControls();
+
+ Registry r = f.getRegistry();
+
+ assertNotNull(r);
+
+ ThreadEventNotifier t = (ThreadEventNotifier) r.getService(
+ HiveMind.THREAD_EVENT_NOTIFIER_SERVICE,
+ ThreadEventNotifier.class);
+
+ ThreadListenerFixture l = new ThreadListenerFixture();
+
+ t.addThreadCleanupListener(l);
+
+ MockControl requestControl = newControl(HttpServletRequest.class);
+ HttpServletRequest request = (HttpServletRequest) requestControl.getMock();
+ HttpServletResponse response = (HttpServletResponse) newMock(HttpServletResponse.class);
+ FilterChain chain = (FilterChain) newMock(FilterChain.class);
+
+ request.setAttribute(HiveMindFilter.REQUEST_KEY, r);
+
+ chain.doFilter(request, response);
+
+ request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
+ requestControl.setReturnValue(null);
+
+ request.getAttribute(HiveMindFilter.REQUEST_KEY);
+ requestControl.setReturnValue(r);
+
+ replayControls();
+
+ f.doFilter(request, response, chain);
+
+ assertSame(r, HiveMindFilter.getRegistry(request));
+
+ assertEquals(true, l.getCleanup());
+
+ f.destroy();
+
+ try
+ {
+ t.addThreadCleanupListener(null);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertExceptionSubstring(ex, "The HiveMind Registry has been shutdown.");
+ }
+
+ verifyControls();
+ }
+
+ public void testShutdown() throws Exception
+ {
+ MockControl contextc = newControl(ServletContext.class);
+ ServletContext context = (ServletContext) contextc.getMock();
+
+ MockControl configc = newControl(FilterConfig.class);
+ FilterConfig filterConfig = (FilterConfig) configc.getMock();
+
+ filterConfig.getServletContext();
+ configc.setReturnValue(context);
+
+ context.getResource(HiveMindFilter.HIVE_MODULE_XML);
+ contextc.setReturnValue(null);
+
+ replayControls();
+
+ RegistryExposingHiveMindFilterFixture f = new RegistryExposingHiveMindFilterFixture();
+
+ f.init(filterConfig);
+
+ verifyControls();
+
+ Registry r = f.getRegistry();
+
+ assertNotNull(r);
+
+ ShutdownCoordinator coordinator = (ShutdownCoordinator) r
+ .getService(ShutdownCoordinator.class);
+
+ ShutdownListenerFixture l = new ShutdownListenerFixture();
+
+ coordinator.addRegistryShutdownListener(l);
+
+ MockControl requestControl = newControl(HttpServletRequest.class);
+ HttpServletRequest request = (HttpServletRequest) requestControl.getMock();
+ HttpServletResponse response = (HttpServletResponse) newMock(HttpServletResponse.class);
+ FilterChain chain = new RebuildRegistryChainFixture();
+
+ request.setAttribute(HiveMindFilter.REQUEST_KEY, r);
+
+ request.setAttribute(HiveMindFilter.REBUILD_REQUEST_KEY, Boolean.TRUE);
+
+ request.getAttribute(HiveMindFilter.REBUILD_REQUEST_KEY);
+ requestControl.setReturnValue(Boolean.TRUE);
+
+ filterConfig.getServletContext();
+ configc.setReturnValue(context);
+
+ context.getResource(HiveMindFilter.HIVE_MODULE_XML);
+ contextc.setReturnValue(null);
+
+ replayControls();
+
+ f.doFilter(request, response, chain);
+
+ verifyControls();
+
+ assertEquals(true, l.getDidShutdown());
+ }
+
+ private FilterConfig newFilterConfig() throws Exception
+ {
+ MockControl control = newControl(ServletContext.class);
+
+ ServletContext context = (ServletContext) control.getMock();
+
+ context.getResource(HiveMindFilter.HIVE_MODULE_XML);
+ control.setReturnValue(null);
+
+ return newFilterConfig(context);
+ }
+
+ private FilterConfig newFilterConfig(ServletContext context)
+ {
+ MockControl control = newControl(FilterConfig.class);
+ FilterConfig config = (FilterConfig) control.getMock();
+
+ config.getServletContext();
+ control.setReturnValue(context);
+
+ return config;
+ }
+
+
+}
\ No newline at end of file