You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/06/06 16:28:48 UTC
cvs commit: jakarta-turbine-2/src/test/org/apache/turbine DestroyTest.java
henning 2003/06/06 07:28:48
Modified: src/java/org/apache/turbine Turbine.java
Added: src/test/org/apache/turbine DestroyTest.java
Log:
Move the serviceManager member into a getter so we can assure that it is
never null. Makes it possible to call destroy() unconditionally on a
Turbine object without getting NPEs.
Added a test for this.
Revision Changes Path
1.42 +16 -13 jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- Turbine.java 6 Jun 2003 09:43:56 -0000 1.41
+++ Turbine.java 6 Jun 2003 14:28:48 -0000 1.42
@@ -84,6 +84,7 @@
import org.apache.turbine.modules.ActionLoader;
import org.apache.turbine.modules.PageLoader;
+import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
import org.apache.turbine.services.component.ComponentService;
@@ -186,9 +187,6 @@
*/
private static String webappRoot;
- /** instance of turbine services */
- private static TurbineServices serviceManager = null;
-
/** Our internal configuration object */
private static Configuration configuration = null;
@@ -325,8 +323,6 @@
String confPath;
String confStyle = "unset";
-
-
if (StringUtils.isNotEmpty(confFile))
{
confPath = getRealPath(confFile);
@@ -395,10 +391,7 @@
setTurbineServletConfig(config);
setTurbineServletContext(context);
- // Get the instance of the service manager
- serviceManager = (TurbineServices) TurbineServices.getInstance();
-
- serviceManager.setApplicationRoot(applicationRoot);
+ getServiceManager().setApplicationRoot(applicationRoot);
// We want to set a few values in the configuration so
// that ${variable} interpolation will work for
@@ -420,13 +413,13 @@
AvalonComponentService.SERVICE_NAME + ".earlyInit",
Boolean.TRUE);
- serviceManager.setConfiguration(configuration);
+ getServiceManager().setConfiguration(configuration);
// Initialize the service manager. Services
// that have its 'earlyInit' property set to
// a value of 'true' will be started when
// the service manager is initialized.
- serviceManager.init();
+ getServiceManager().init();
}
/**
@@ -661,7 +654,7 @@
public final void destroy()
{
// Shut down all Turbine Services.
- serviceManager.shutdownServices();
+ getServiceManager().shutdownServices();
System.gc();
log.info("Turbine: Done shutting down!");
@@ -1130,5 +1123,15 @@
}
return new File(getApplicationRoot(), path).getAbsolutePath();
+ }
+
+ /**
+ * Return an instance of the currently configured Service Manager
+ *
+ * @return A service Manager instance
+ */
+ private ServiceManager getServiceManager()
+ {
+ return TurbineServices.getInstance();
}
}
1.1 jakarta-turbine-2/src/test/org/apache/turbine/DestroyTest.java
Index: DestroyTest.java
===================================================================
package org.apache.turbine;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.turbine.Turbine;
import org.apache.turbine.util.TurbineConfig;
/**
* Can we call "destroy" unconditionally on our Turbine Servlet, even if
* it hasn't configured?
*
* @version $Id: DestroyTest.java,v 1.1 2003/06/06 14:28:48 henning Exp $
*/
public class DestroyTest
extends TestCase
{
private static TurbineConfig tc = null;
public DestroyTest(String name)
{
super(name);
tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
}
public static Test suite()
{
return new TestSuite(DestroyTest.class);
}
public void testDestroy()
throws Exception
{
Turbine t = new Turbine();
t.destroy();
}
public void testInitAndDestroy()
throws Exception
{
tc.initialize();
tc.dispose();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org