cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r380967 - in /cocoon/trunk/cocoon-core/src: main/java/org/apache/cocoon/core/ main/java/org/apache/cocoon/core/container/spring/ test/java/org/apache/cocoon/ test/java/org/apache/cocoon/core/ test/java/org/apache/cocoon/core/container/
Date Sat, 25 Feb 2006 19:06:00 GMT
Author: cziegeler
Date: Sat Feb 25 11:05:58 2006
New Revision: 380967

URL: http://svn.apache.org/viewcvs?rev=380967&view=rev
Log:
Make tests compilable again

Removed:
    cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/CoreServiceManagerTestCase.java
Modified:
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java
    cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/CocoonTestCase.java
    cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
    cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java
    cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java
    cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java Sat Feb 25
11:05:58 2006
@@ -739,6 +739,10 @@
         }
     }
 
+    public CocoonXmlWebApplicationContext getContainer() {
+        return this.container;
+    }
+
     /**
      * Retreives the "extra-classpath" attribute, that needs to be
      * added to the class path.

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
Sat Feb 25 11:05:58 2006
@@ -103,7 +103,7 @@
      * @return A new root application context.
      * @throws Exception
      */
-    public static ApplicationContext createRootApplicationContext(AvalonEnvironment  env)
+    public static CocoonXmlWebApplicationContext createRootApplicationContext(AvalonEnvironment
 env)
     throws Exception {
         final ApplicationContext parent = (ApplicationContext)env.servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
         CocoonXmlWebApplicationContext context = new CocoonXmlWebApplicationContext(parent);

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ComponentInfo.java
Sat Feb 25 11:05:58 2006
@@ -292,6 +292,10 @@
         return defaultValue;
     }
 
+    public void setDefaultValue(String defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+
     /**
      * Create a new component info with the same configuration
      * as the current one.

Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/CocoonTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/CocoonTestCase.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/CocoonTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/CocoonTestCase.java Sat Feb 25
11:05:58 2006
@@ -16,12 +16,10 @@
 
 package org.apache.cocoon;
 
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.cocoon.core.container.CoreServiceManager;
-import org.apache.cocoon.core.container.StandaloneServiceSelector;
 import org.apache.cocoon.core.container.ContainerTestCase;
+import org.apache.cocoon.core.container.spring.ComponentInfo;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.apache.excalibur.source.SourceFactory;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.source.impl.ResourceSourceFactory;
 import org.apache.excalibur.source.impl.SourceResolverImpl;
@@ -34,33 +32,40 @@
  */
 public abstract class CocoonTestCase extends ContainerTestCase {
 
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.CocoonServiceManager)
+    /**
+     * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext)
      */
-    protected void addComponents(CoreServiceManager manager) 
-    throws ServiceException, ConfigurationException {
-        super.addComponents(manager);
+    protected void addComponents(ConfigurationInfo info) 
+    throws Exception {
+        super.addComponents(info);
         if ( this.addSourceFactories() ) {
-            // Create configuration for source-factories
-            final DefaultConfiguration df = new DefaultConfiguration("source-factories");
-            DefaultConfiguration factory = new DefaultConfiguration("component-instance");
-            factory.setAttribute("class", ResourceSourceFactory.class.getName());
-            factory.setAttribute("name", "resource");
-            df.addChild(factory);
-            factory = new DefaultConfiguration("component-instance");
-            factory.setAttribute("class", URLSourceFactory.class.getName());
-            factory.setAttribute("name", "*");
-            df.addChild(factory);
-            manager.addComponent("org.apache.excalibur.source.SourceFactorySelector", 
-                                 StandaloneServiceSelector.class.getName(), 
-                                 df,
-                                 null);
+            ComponentInfo component;
+            // Add resource source factory
+            component = new ComponentInfo();
+            component.setComponentClassName(ResourceSourceFactory.class.getName());
+            component.setRole(SourceFactory.ROLE + "/resource");
+            info.addComponent(component);
+
+            // Add url source source factory
+            component = new ComponentInfo();
+            component.setComponentClassName(URLSourceFactory.class.getName());
+            component.setRole(SourceFactory.ROLE + "/*");
+            info.addComponent(component);
+
+            // add source factory selector
+            component = new ComponentInfo();
+            component.setModel(ComponentInfo.MODEL_SINGLETON);
+            component.setComponentClassName(SourceFactory.ROLE + "Selector");
+            component.setRole("org.apache.cocoon.core.container.DefaultServiceSelector");
+            component.setAlias("source-factories");
+            component.setDefaultValue("*");
+            info.addComponent(component);
         }
         if ( this.addSourceResolver() ) {
-            manager.addComponent(SourceResolver.ROLE, 
-                    SourceResolverImpl.class.getName(), 
-                    new DefaultConfiguration("", "-"),
-                    null);
+            ComponentInfo component = new ComponentInfo();
+            component.setComponentClassName(SourceResolverImpl.class.getName());
+            component.setRole(SourceResolver.ROLE);
+            info.addComponent(component);
         }
     }
     

Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
(original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
Sat Feb 25 11:05:58 2006
@@ -28,8 +28,6 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.context.DefaultContext;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
@@ -40,8 +38,8 @@
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.components.flow.Interpreter;
 import org.apache.cocoon.components.source.SourceResolverAdapter;
-import org.apache.cocoon.core.container.CoreServiceManager;
-import org.apache.cocoon.core.container.StandaloneServiceSelector;
+import org.apache.cocoon.core.container.spring.ComponentInfo;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 import org.apache.cocoon.environment.mock.MockContext;
@@ -107,7 +105,7 @@
         context.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, getContext());
     }
 
-    /* (non-Javadoc)
+    /**
      * @see junit.framework.TestCase#setUp()
      */
     public void setUp() throws Exception {
@@ -126,28 +124,31 @@
         redirector.reset();
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.cocoon.core.container.ContainerTestCase#addComponents(org.apache.cocoon.core.container.CocoonServiceManager)
+    /**
+     * @see org.apache.cocoon.CocoonTestCase#addComponents(org.apache.cocoon.core.container.spring.ConfigurationInfo)
      */
-    protected void addComponents(CoreServiceManager manager) 
-    throws ServiceException, ConfigurationException {
-        super.addComponents(manager);
+    protected void addComponents(ConfigurationInfo info) 
+    throws Exception {
+        super.addComponents(info);
         final String[] o = this.getSitemapComponentInfo();
         if ( o != null ) {
             final String typeClassName = o[0];
             final String componentClassName = o[1];
             final String key = o[2];
-            
-            // Create configuration for selector
-            final DefaultConfiguration df = new DefaultConfiguration("transformers");
-            final DefaultConfiguration factory = new DefaultConfiguration("component-instance");
-            factory.setAttribute("class", componentClassName);
-            factory.setAttribute("name", key);
-            df.addChild(factory);
-            manager.addComponent(typeClassName + "Selector", 
-                                 StandaloneServiceSelector.class.getName(), 
-                                 df,
-                                 null);
+
+            // Add component
+            ComponentInfo component = new ComponentInfo();
+            component.setComponentClassName(componentClassName);
+            component.setRole(typeClassName + "/" + key);
+            info.addComponent(component);
+
+            // add selector
+            component = new ComponentInfo();
+            component.setModel(ComponentInfo.MODEL_SINGLETON);
+            component.setComponentClassName(typeClassName + "Selector");
+            component.setRole("org.apache.cocoon.core.container.DefaultServiceSelector");
+            component.setDefaultValue(key);
+            info.addComponent(component);
         }
     }
 

Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java Sat Feb
25 11:05:58 2006
@@ -26,12 +26,14 @@
 import org.apache.avalon.framework.logger.ConsoleLogger;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.Cocoon;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.core.BootstrapEnvironment;
 import org.apache.cocoon.core.CoreUtil;
 import org.apache.cocoon.core.TestBootstrapEnvironment;
 import org.apache.cocoon.core.TestCoreUtil;
+import org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.mock.MockContext;
 import org.apache.cocoon.environment.mock.MockEnvironment;
@@ -49,7 +51,9 @@
     private CoreUtil coreUtil;
     private Processor processor;
     private String classDir;
-    
+    private CocoonXmlWebApplicationContext container;
+    private ServiceManager serviceManager;
+
     protected String processorClassName = Cocoon.class.getName();
 
     protected void setUp() throws Exception {
@@ -78,6 +82,8 @@
 
         this.coreUtil = new TestCoreUtil(env);
         this.processor = this.coreUtil.createProcessor();
+        this.container = this.coreUtil.getContainer();
+        this.serviceManager = (ServiceManager)this.container.getBean(ServiceManager.class.getName());
     }
 
     protected void tearDown() throws Exception {
@@ -91,17 +97,11 @@
     }
     
     protected final Object lookup( final String key ) throws ServiceException {
-        if (this.processor instanceof Cocoon) {
-            return ((Cocoon)this.processor).getServiceManager().lookup( key );
-        } else {
-            throw new ServiceException(key, "The processor have no service manager");
-        }
+        return this.serviceManager.lookup(key);
     }
 
     protected final void release( final Object object ) {
-        if (this.processor instanceof Cocoon) {
-            ((Cocoon)this.processor).getServiceManager().release( object );
-        }
+        this.serviceManager.release(object);
     }
     
     protected String getConfiguration() {

Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/TestCoreUtil.java Sat Feb
25 11:05:58 2006
@@ -26,11 +26,6 @@
         this.classloader = TestCoreUtil.class.getClassLoader();
     }
 
-    // Simplified logging
-    protected void initLogger() {
-        this.log = ((TestBootstrapEnvironment)this.env).logger;
-    }
-
     // Simplified classloader handling
     protected void updateEnvironment() throws Exception {}
 }

Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java?rev=380967&r1=380966&r2=380967&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
(original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
Sat Feb 25 11:05:58 2006
@@ -21,10 +21,8 @@
 
 import junit.framework.TestCase;
 
-import org.apache.avalon.excalibur.logger.LoggerManager;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 import org.apache.avalon.framework.container.ContainerUtil;
@@ -38,6 +36,12 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.core.Core;
 import org.apache.cocoon.core.MutableSettings;
+import org.apache.cocoon.core.container.spring.ApplicationContextFactory;
+import org.apache.cocoon.core.container.spring.AvalonEnvironment;
+import org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext;
+import org.apache.cocoon.core.container.spring.ConfigReader;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.apache.cocoon.environment.mock.MockContext;
 
 /**
  * JUnit TestCase for Cocoon Components.
@@ -129,18 +133,21 @@
 
     /** The context */
     private Context context;
-    
+
+    /** The root application context. */
+    private CocoonXmlWebApplicationContext rootContext;
+
     /** Return the logger */
     protected Logger getLogger() {
         return logger;
     }
 
-    /** Return the service manager */
+    /** Return the service manager. */
     protected ServiceManager getManager() {
         return this.manager;
     }
-    
-    /* (non-Javadoc)
+
+    /**
      * @see junit.framework.TestCase#setUp()
      */
     protected void setUp() throws Exception {
@@ -196,32 +203,13 @@
             conf = new DefaultConfiguration("", "-");
         }
 
-        this.prepare( conf.getChild( "context" ),
-                      conf.getChild( "roles" ),
-                      conf.getChild( "components" ) );
-    }
-
-    /**
-     * Initializes the ComponentLocator
-     *
-     * @param context The configuration object for the context
-     * @param roles The configuration object for the roles
-     * @param components The configuration object for the components
-     *
-     * More detailed control over configuration can be achieved by
-     * overriding <code>prepare()</code>, construct the configuration
-     *  objects and call this method.
-     */
-    protected final void prepare( final Configuration context,
-                                  final Configuration roles,
-                                  final Configuration components )
-    throws Exception {
-        this.context = this.setupContext( context );
+        // setup context
+        this.context = this.setupContext( conf.getChild( "context" ) );
 
-        this.setupManagers( components, roles );
+        this.setupManagers( conf.getChild( "components" ),  conf.getChild( "roles" ) );
     }
 
-    /* (non-Javadoc)
+    /**
      * @see junit.framework.TestCase#tearDown()
      */
     protected void tearDown() throws Exception {
@@ -233,10 +221,13 @@
      * Disposes the <code>ComponentLocator</code>
      */
     final private void done() {
-        if( manager != null ) {
-            ContainerUtil.dispose(manager);
-            manager = null;
+        if( this.rootContext != null ) {
+            this.rootContext.destroy();
+            this.rootContext = null;
         }
+        this.manager = null;
+        this.context = null;
+        this.logger = null;
     }
 
     /**
@@ -268,6 +259,7 @@
             }
         }
         this.addContext( context );
+        context.makeReadOnly();
         return context ;
     }
 
@@ -283,34 +275,32 @@
      * This method may be overwritten by subclasses to add aditional
      * components.
      */
-    protected void addComponents( CoreServiceManager manager) 
-    throws ServiceException, ConfigurationException {
+    protected void addComponents(ConfigurationInfo info) 
+    throws Exception {
         // subclasses can add components here
     }
     
     final private void setupManagers( final Configuration confCM,
                                       final Configuration confRM)
     throws Exception {
-        // Setup the RoleManager
-        RoleManager roleManager = new RoleManager();
-        roleManager.enableLogging( this.getLogger() );
-        roleManager.configure( confRM );
-
-        // Set up root manager for Core
-        Core core = new Core(new MutableSettings(), this.context);
-        ((DefaultContext)this.context).put(Core.ROLE, core);
-        SingleComponentServiceManager rsm = new SingleComponentServiceManager(null, core,
Core.ROLE);
- 
-        // Set up the ComponentLocator
-        CoreServiceManager ecManager = new CoreServiceManager(rsm);
-        ecManager.enableLogging( this.getLogger() );
-        ecManager.contextualize( this.context );
-        ecManager.setRoleManager( roleManager );
-        ecManager.setLoggerManager( new DefaultLoggerManager(this.logger));
-        ecManager.configure( confCM );
-        this.addComponents( ecManager );
-        ecManager.initialize();
-        this.manager = ecManager;
+        final AvalonEnvironment avalonEnv = new AvalonEnvironment();
+        avalonEnv.logger = this.logger;
+        avalonEnv.context = this.context;
+        avalonEnv.settings = new MutableSettings();
+        avalonEnv.core = new Core(avalonEnv.settings, avalonEnv.context);
+        avalonEnv.servletContext = new MockContext();
+
+        this.rootContext = ApplicationContextFactory.createRootApplicationContext(avalonEnv);
+        // read roles
+        ConfigurationInfo rolesInfo = ConfigReader.readConfiguration(confRM, null, avalonEnv);
+        CocoonXmlWebApplicationContext rolesContext = ApplicationContextFactory.createApplicationContext(avalonEnv,
rolesInfo, rootContext, true);
+
+        // read components
+        ConfigurationInfo componentsInfo = ConfigReader.readConfiguration(confCM, rolesInfo,
avalonEnv);
+        this.addComponents( componentsInfo );
+        CocoonXmlWebApplicationContext componentsContext = ApplicationContextFactory.createApplicationContext(avalonEnv,
componentsInfo, rolesContext, false);
+
+        this.manager = (ServiceManager)componentsContext.getBean(ServiceManager.class.getName());
     }
 
     protected final Object lookup( final String key )
@@ -363,29 +353,5 @@
     protected Object getComponent(String classname) 
     throws Exception {
         return this.getComponent(classname, null, null);
-    }
-
-    /**
-     * We use this simple logger manager that sends all output to the console (logger)
-     */
-    protected static class DefaultLoggerManager implements LoggerManager {
-        
-        private Logger logger;
-        
-        public DefaultLoggerManager(Logger logger) {
-            this.logger = logger;
-        }
-        /* (non-Javadoc)
-         * @see org.apache.avalon.excalibur.logger.LoggerManager#getDefaultLogger()
-         */
-        public Logger getDefaultLogger() {
-            return this.logger;
-        }
-        /* (non-Javadoc)
-         * @see org.apache.avalon.excalibur.logger.LoggerManager#getLoggerForCategory(java.lang.String)
-         */
-        public Logger getLoggerForCategory(String arg0) {
-            return this.logger;
-        }
     }
 }



Mime
View raw message