cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r395376 - in /cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl: ./ src/main/java/org/apache/cocoon/portal/event/impl/ src/main/java/org/apache/cocoon/portal/pluto/om/ src/test/java/org/apache/cocoon/portal/ src/test/java/org/apache/coco...
Date Wed, 19 Apr 2006 20:02:25 GMT
Author: cziegeler
Date: Wed Apr 19 13:02:23 2006
New Revision: 395376

URL: http://svn.apache.org/viewcvs?rev=395376&view=rev
Log:
Update test case
Minor code improvements

Added:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java
  (with props)
Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/pom.xml
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/event/impl/NewPageLabelEventConverter.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/event/impl/DefaultEventManagerTestCase.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/pom.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/pom.xml?rev=395376&r1=395375&r2=395376&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/pom.xml (original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/pom.xml Wed Apr 19 13:02:23 2006
@@ -142,11 +142,34 @@
       <artifactId>cocoon-core</artifactId>
       <version>2.2.0-SNAPSHOT</version>
       <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <!--  
+          Test dependencies
+          TODO remove these when MNG-1378 is fixed, these are inherited from the root pom
normally
+     -->
+    <dependency>
+      <groupId>xmlunit</groupId>
+      <artifactId>xmlunit</artifactId>
+      <version>0.8</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <version>1.0.1</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>1.1</version>
       <scope>test</scope>
     </dependency>
   </dependencies>

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/event/impl/NewPageLabelEventConverter.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/event/impl/NewPageLabelEventConverter.java?rev=395376&r1=395375&r2=395376&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/event/impl/NewPageLabelEventConverter.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/event/impl/NewPageLabelEventConverter.java
Wed Apr 19 13:02:23 2006
@@ -21,6 +21,7 @@
 import org.apache.cocoon.portal.event.EventConverter;
 import org.apache.cocoon.portal.event.layout.ChangeTabEvent;
 import org.apache.cocoon.portal.layout.Item;
+import org.apache.cocoon.portal.layout.Layout;
 import org.apache.cocoon.portal.layout.NamedItem;
 
 /**
@@ -38,11 +39,10 @@
      */
     public String encode(Event event) {
         if ( event instanceof ChangeTabEvent ) {
-            // TODO - populate tabs
             final Item item = ((ChangeTabEvent)event).getItem();
             final boolean useName = ((ChangeTabEvent)event).isUseName();
             if ( useName ) {
-                return ((NamedItem)item).getName();
+                return this.getPageLabel((NamedItem)item);
             } else {
                 return String.valueOf(item.getParent().getItems().indexOf(item));
             }
@@ -58,5 +58,26 @@
             // TODO
         }
         return null;
+    }
+
+    protected String getPageLabel(NamedItem item) {
+        // first search parent
+        Layout layout = item.getParent();
+        NamedItem parent = null;
+        while ( parent == null && layout != null ) {
+            if ( layout.getParent() != null ) {
+                if ( layout.getParent() instanceof NamedItem ) {
+                    parent = (NamedItem)layout.getParent();
+                } else {
+                    layout = layout.getParent().getParent();
+                }
+            } else {
+                layout = null;
+            }
+        }
+        if ( parent != null ) {
+            return this.getPageLabel(parent) + '.' + item.getName();
+        }
+        return item.getName();
     }
 }

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java?rev=395376&r1=395375&r2=395376&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/pluto/om/PortletDefinitionRegistryImpl.java
Wed Apr 19 13:02:23 2006
@@ -76,6 +76,7 @@
 
     private static final String WEB_XML = "WEB-INF/web.xml";
     private static final String PORTLET_XML = "WEB-INF/portlet.xml";
+    private static final String COPLET_XML = "WEB-INF/coplet.xml";
 
     /** The mapping */
     public static final String PORTLET_MAPPING = "resource://org/apache/cocoon/portal/pluto/om/portletdefinitionmapping.xml";
@@ -97,9 +98,12 @@
     protected String contextName;
 
     /** The entity resolver */
-    protected EntityResolver resolver;
+    protected EntityResolver entityResolver;
 
+    /** Path to the webapp directory containing all web apps. This is used to find already
+     * deployed portlets and to deploy new portlets. */
     protected String  webAppDir;
+
     protected String  localAppDir  = "conf/portlets";
     protected boolean stripLoggers = false;
 
@@ -137,7 +141,7 @@
     public void service(ServiceManager manager) 
     throws ServiceException {
         super.service(manager);
-        this.resolver = (EntityResolver) this.manager.lookup(EntityResolver.ROLE);
+        this.entityResolver = (EntityResolver) this.manager.lookup(EntityResolver.ROLE);
     }
 
     /**
@@ -158,8 +162,8 @@
      */
     public void dispose() {
         if ( this.manager != null ) {
-            this.manager.release(this.resolver);
-            this.resolver = null;
+            this.manager.release(this.entityResolver);
+            this.entityResolver = null;
         }
         super.dispose();
     }
@@ -336,17 +340,16 @@
             portletSource.setSystemId(url.toExternalForm());
 
             url = servletContext.getResource("/" + WEB_XML);
-            InputSource webSource = null;
-            if (url != null) {
-                webSource = new InputSource(url.openStream());
-                webSource.setSystemId(url.toExternalForm());
-            }
-            else {
-                webSource = new InputSource();
-                webSource.setSystemId("no web.xml!");
-            }
+            final InputSource webSource = new InputSource(url.openStream());
+            webSource.setSystemId(url.toExternalForm());
 
-            this.load(portletSource, webSource, this.contextName);
+            url = servletContext.getResource("/" + COPLET_XML);
+            InputSource copletSource = null;
+            if ( url != null ) {
+                copletSource = new InputSource(url.openStream());
+                copletSource.setSystemId(url.toExternalForm());                
+            }
+            this.load(portletSource, webSource, copletSource, this.contextName);
         }
     }
 
@@ -355,23 +358,28 @@
         if (this.getLogger().isDebugEnabled()) {
             this.getLogger().debug("Searching war " + warFile.getName());
         }
-        InputSource portletSource;
-        InputSource webSource;
         try {
             ZipFile war = new ZipFile(warFile);
             ZipEntry entry = war.getEntry(PORTLET_XML);
+            // no portlet.xml -> not a portlet web application
             if (entry != null) {
-                portletSource = new InputSource(war.getInputStream(entry));
+                final InputSource portletSource = new InputSource(war.getInputStream(entry));
                 portletSource.setSystemId("/" + PORTLET_XML);
                 entry = war.getEntry(WEB_XML);
-                if (entry != null) {
-                    webSource = new InputSource(war.getInputStream(entry));
-                    webSource.setSystemId("/" + WEB_XML);
-                } else {
-                    webSource = new InputSource();
-                    webSource.setSystemId("no web.xml!");
+                // no web.xml -> not a web application
+                if (entry == null) {
+                    return;
+                }
+                final InputSource webSource = new InputSource(war.getInputStream(entry));
+                webSource.setSystemId("/" + WEB_XML);
+
+                InputSource copletSource = null;
+                entry = war.getEntry(COPLET_XML);
+                if ( entry != null ) {
+                    copletSource = new InputSource(war.getInputStream(entry));
+                    copletSource.setSystemId("/" + COPLET_XML);                    
                 }
-                this.load(portletSource, webSource, webModule);
+                this.load(portletSource, webSource, copletSource, webModule);
             }
         } catch (Exception e) {
             if (this.getLogger().isDebugEnabled()) {
@@ -383,17 +391,16 @@
 
     protected void loadWebApp(String baseDir, String webModule)
     throws Exception {
-        String directory = baseDir + File.separatorChar + webModule + File.separatorChar
+ "WEB-INF" + File.separatorChar;
+        final String directory = baseDir + File.separatorChar + webModule + File.separatorChar
+ "WEB-INF";
         if (this.getLogger().isInfoEnabled()) {
             this.getLogger().info("Searching for portlet application in directory: " + directory);
         }
 
-        File portletXml = new File(directory + "portlet.xml");
-        File webXml = new File(directory + "web.xml");
-
-        // check for the porlet.xml. If there is no portlet.xml this is not a
-        // portlet application web module
-        if (portletXml.exists()) { // && (webXml.exists())) {
+        // check for the portlet.xml and web.xml. If there is no portlet.xml this is not
a
+        // portlet application web module. If there is no web.xml this is not a web app.
+        final File portletXml = new File(directory + File.separatorChar + "portlet.xml");
+        final File webXml = new File(directory + File.separatorChar + "web.xml");
+        if (portletXml.exists()&& webXml.exists()) {
             if (this.getLogger().isDebugEnabled()) {
                 this.getLogger().debug("Loading the following Portlet Applications XML files..."
+
                     portletXml +
@@ -401,20 +408,32 @@
                     webXml);
             }
 
-            InputSource portletSource = new InputSource(new FileInputStream(portletXml));
+            final InputSource portletSource = new InputSource(new FileInputStream(portletXml));
             portletSource.setSystemId(portletXml.toURL().toExternalForm());
-            InputSource webSource = null;
 
+            // web.xml is optional
+            InputSource webSource = null;
             if (webXml.exists()) {
                 webSource = new InputSource(new FileInputStream(webXml));
                 webSource.setSystemId(webXml.toURL().toExternalForm());
             }
 
-            this.load(portletSource, webSource, webModule);
+            // coplet.xml is optional
+            final File copletXml = new File(directory + File.separatorChar + "coplet.xml");
+            InputSource copletSource = null;
+            if ( copletXml.exists() ) {
+                copletSource = new InputSource(new FileInputStream(copletXml));
+                copletSource.setSystemId(copletXml.toURL().toExternalForm());    
+            }
+
+            this.load(portletSource, webSource, copletSource, webModule);
         }
     }
 
-    protected void load(InputSource portletXml, InputSource webXml, String webModule)
+    protected void load(InputSource portletXml,
+                        InputSource webXml,
+                        InputSource copletXml,
+                        String      webModule)
     throws Exception {
         if (this.getLogger().isDebugEnabled()) {
             this.getLogger().debug("Loading the following Portlet Applications XML files..."
+
@@ -425,7 +444,7 @@
 
         Unmarshaller unmarshaller = new Unmarshaller(this.mappingPortletXml);
         unmarshaller.setIgnoreExtraElements(true);
-        unmarshaller.setEntityResolver(this.resolver);
+        unmarshaller.setEntityResolver(this.entityResolver);
         unmarshaller.setValidation(false);
         PortletApplicationDefinitionImpl portletApp =
             (PortletApplicationDefinitionImpl) unmarshaller.unmarshal(portletXml);
@@ -436,7 +455,7 @@
             this.getLogger().info("Loading web.xml...");
             unmarshaller = new Unmarshaller(this.mappingWebXml);
             unmarshaller.setIgnoreExtraElements(true);
-            unmarshaller.setEntityResolver(this.resolver);
+            unmarshaller.setEntityResolver(this.entityResolver);
             unmarshaller.setValidation(false);
             webApp = (WebApplicationDefinitionImpl) unmarshaller.unmarshal(webXml);
 
@@ -492,7 +511,9 @@
                 this.getLogger().info("Adding portlet '" + portlet.getId() + "'.");
             }
             if ( this.createCoplets ) {
+                // TODO - parse coplet.xml if available
                 final CopletBaseData cbd = pcm.getProfileManager().getCopletBaseData(this.copletBaseDataName);
+                // TODO - check portletId for invalid characters!
                 final CopletData cd = pcm.getCopletFactory().newInstance(cbd, portlet.getId().toString());
                 cd.setAttribute("portlet", portlet.getId().toString());
                 cd.setAttribute("buffer", Boolean.TRUE);

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java?rev=395376&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java
Wed Apr 19 13:02:23 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2006 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.cocoon.portal;
+
+import java.util.Collections;
+import java.util.Enumeration;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.cocoon.CocoonTestCase;
+import org.apache.cocoon.core.container.spring.ComponentInfo;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
+import org.apache.cocoon.environment.mock.MockContext;
+import org.apache.cocoon.portal.impl.PortalServiceImpl;
+import org.apache.cocoon.servlet.CocoonServlet;
+
+/**
+ * Abstract test case class that can be used as a base for own portal
+ * test cases.
+ * It provides a service manager with a setup portal service etc.
+ *
+ * $Id$ 
+ */
+public abstract class AbstractPortalTestCase extends CocoonTestCase {
+
+    protected ServletConfig getServletConfig() {
+        return new ServletConfig() {
+
+            public String getInitParameter(String arg0) {
+                return null;
+            }
+
+            public Enumeration getInitParameterNames() {
+                return Collections.enumeration(Collections.EMPTY_LIST);
+            }
+
+            public ServletContext getServletContext() {
+                return new MockContext();
+            }
+
+            public String getServletName() {
+                return "cocoon";
+            }
+            
+        };
+    }
+
+    protected Configuration getPortalServiceConfig() {
+        DefaultConfiguration rootConfig = new DefaultConfiguration("component");
+        DefaultConfiguration portalConfig = new DefaultConfiguration("portal");
+        portalConfig.setAttribute("name", "portaltest");
+        rootConfig.addChild(portalConfig);
+        rootConfig.makeReadOnly();
+        return rootConfig;
+    }
+
+    /**
+     * @see org.apache.cocoon.core.container.ContainerTestCase#addContext(org.apache.avalon.framework.context.DefaultContext)
+     */
+    protected void addContext(DefaultContext context) {
+        super.addContext(context);
+        context.put(CocoonServlet.CONTEXT_SERVLET_CONFIG, this.getServletConfig());
+    }
+
+    /**
+     * @see org.apache.cocoon.CocoonTestCase#addComponents(org.apache.cocoon.core.container.spring.ConfigurationInfo)
+     */
+    protected void addComponents(ConfigurationInfo info) throws Exception {
+        super.addComponents(info);
+        // Add portal service
+        final ComponentInfo portalServiceInfo = new ComponentInfo();
+        portalServiceInfo.setComponentClassName(PortalServiceImpl.class.getName());
+        portalServiceInfo.setRole(PortalService.ROLE);
+        portalServiceInfo.setConfiguration(this.getPortalServiceConfig());
+        info.addComponent(portalServiceInfo);
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/AbstractPortalTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/event/impl/DefaultEventManagerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/event/impl/DefaultEventManagerTestCase.java?rev=395376&r1=395375&r2=395376&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/event/impl/DefaultEventManagerTestCase.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/test/java/org/apache/cocoon/portal/event/impl/DefaultEventManagerTestCase.java
Wed Apr 19 13:02:23 2006
@@ -15,30 +15,19 @@
  */
 package org.apache.cocoon.portal.event.impl;
 
-import java.util.Collections;
-import java.util.Enumeration;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-
-import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.cocoon.CocoonTestCase;
 import org.apache.cocoon.core.container.spring.ComponentInfo;
 import org.apache.cocoon.core.container.spring.ConfigurationInfo;
-import org.apache.cocoon.environment.mock.MockContext;
+import org.apache.cocoon.portal.AbstractPortalTestCase;
 import org.apache.cocoon.portal.PortalService;
 import org.apache.cocoon.portal.event.Event;
 import org.apache.cocoon.portal.event.EventManager;
 import org.apache.cocoon.portal.event.Receiver;
-import org.apache.cocoon.portal.impl.PortalServiceImpl;
-import org.apache.cocoon.servlet.CocoonServlet;
 
 /**
  * $Id$ 
  */
-public class DefaultEventManagerTestCase extends CocoonTestCase {
+public class DefaultEventManagerTestCase extends AbstractPortalTestCase {
 
     protected DefaultEventManager eventManager;
 
@@ -50,57 +39,11 @@
         this.eventManager = (DefaultEventManager)this.getBeanFactory().getBean(EventManager.ROLE);
     }
 
-    protected ServletConfig getServletConfig() {
-        return new ServletConfig() {
-
-            public String getInitParameter(String arg0) {
-                return null;
-            }
-
-            public Enumeration getInitParameterNames() {
-                return Collections.enumeration(Collections.EMPTY_LIST);
-            }
-
-            public ServletContext getServletContext() {
-                return new MockContext();
-            }
-
-            public String getServletName() {
-                return "cocoon";
-            }
-            
-        };
-    }
-
-    protected Configuration getPortalServiceConfig() {
-        DefaultConfiguration rootConfig = new DefaultConfiguration("component");
-        DefaultConfiguration portalConfig = new DefaultConfiguration("portal");
-        portalConfig.setAttribute("name", "portaltest");
-        rootConfig.addChild(portalConfig);
-        rootConfig.makeReadOnly();
-        return rootConfig;
-    }
-
-    /**
-     * @see org.apache.cocoon.core.container.ContainerTestCase#addContext(org.apache.avalon.framework.context.DefaultContext)
-     */
-    protected void addContext(DefaultContext context) {
-        super.addContext(context);
-        context.put(CocoonServlet.CONTEXT_SERVLET_CONFIG, this.getServletConfig());
-    }
-
     /**
      * @see org.apache.cocoon.CocoonTestCase#addComponents(org.apache.cocoon.core.container.spring.ConfigurationInfo)
      */
     protected void addComponents(ConfigurationInfo info) throws Exception {
         super.addComponents(info);
-        // Add portal service
-        final ComponentInfo portalServiceInfo = new ComponentInfo();
-        portalServiceInfo.setComponentClassName(PortalServiceImpl.class.getName());
-        portalServiceInfo.setRole(PortalService.ROLE);
-        portalServiceInfo.setConfiguration(this.getPortalServiceConfig());
-        info.addComponent(portalServiceInfo);
-
         // Add event manager
         final ComponentInfo component = new ComponentInfo();
         component.setComponentClassName(DefaultEventManager.class.getName());
@@ -110,25 +53,230 @@
     }
 
     public void testEventReceiver() throws Exception {
-        EventReceiver1 receiver = new EventReceiver1();
+        EventReceiver receiver = new EventReceiver();
         this.eventManager.subscribe(receiver);
         assertEquals(0, receiver.receiveCount);
         this.eventManager.send(new Event1());
         assertEquals(1, receiver.receiveCount);
         this.eventManager.send(new Event1());
         assertEquals(2, receiver.receiveCount);
+        this.eventManager.send(new Event2());
+        assertEquals(3, receiver.receiveCount);
+        this.eventManager.send(new Event3());
+        assertEquals(4, receiver.receiveCount);
+    }
+
+    public void testMultipleEventReceivers() throws Exception {
+        EventReceiver receiver = new EventReceiver();
+        EventReceiver1 receiver1 = new EventReceiver1();
+        EventReceiver2 receiver2 = new EventReceiver2();
+        EventReceiver3 receiver3 = new EventReceiver3();
+        this.eventManager.subscribe(receiver);
+        this.eventManager.subscribe(receiver1);
+        this.eventManager.subscribe(receiver2);
+        this.eventManager.subscribe(receiver3);
+        assertEquals(0, receiver.receiveCount);
+        assertEquals(0, receiver1.receiveCount);
+        assertEquals(0, receiver2.receiveCount);
+        assertEquals(0, receiver3.receiveCount);
+
+        // each time we send an event we check all four receivers
+        this.eventManager.send(new Event1());
+        assertEquals(1, receiver.receiveCount);
+        assertEquals(1, receiver1.receiveCount);
+        assertEquals(0, receiver2.receiveCount);
+        assertEquals(0, receiver3.receiveCount);
+
+        this.eventManager.send(new Event1());
+        assertEquals(2, receiver.receiveCount);
+        assertEquals(2, receiver1.receiveCount);
+        assertEquals(0, receiver2.receiveCount);
+        assertEquals(0, receiver3.receiveCount);
+
+        this.eventManager.send(new Event2());
+        assertEquals(3, receiver.receiveCount);
+        assertEquals(2, receiver1.receiveCount);
+        assertEquals(1, receiver2.receiveCount);
+        assertEquals(0, receiver3.receiveCount);
+
+        this.eventManager.send(new Event3());
+        assertEquals(4, receiver.receiveCount);
+        assertEquals(2, receiver1.receiveCount);
+        assertEquals(1, receiver2.receiveCount);
+        assertEquals(1, receiver3.receiveCount);
+
+        this.eventManager.send(new Event11());
+        assertEquals(5, receiver.receiveCount);
+        assertEquals(3, receiver1.receiveCount);
+        assertEquals(1, receiver2.receiveCount);
+        assertEquals(1, receiver3.receiveCount);
+
+        this.eventManager.send(new Event12());
+        assertEquals(6, receiver.receiveCount);
+        assertEquals(4, receiver1.receiveCount);
+        assertEquals(1, receiver2.receiveCount);
+        assertEquals(1, receiver3.receiveCount);
+    }
+
+    public void testSimpleHierarchicalEventReceiver() throws Exception {
+        EventReceiver10 receiver = new EventReceiver10();
+        this.eventManager.subscribe(receiver);
+        assertEquals(0, receiver.receiveCount11 + receiver.receiveCount12);
+
+        this.eventManager.send(new Event1());
+        assertEquals(0, receiver.receiveCount11 + receiver.receiveCount12);
+
+        this.eventManager.send(new Event2());
+        assertEquals(0, receiver.receiveCount11 + receiver.receiveCount12);
+
+        this.eventManager.send(new Event3());
+        assertEquals(0, receiver.receiveCount11 + receiver.receiveCount12);
+
+        this.eventManager.send(new Event11());
+        assertEquals(1, receiver.receiveCount11);
+        assertEquals(0, receiver.receiveCount12);
+
+        this.eventManager.send(new Event12());
+        assertEquals(1, receiver.receiveCount11);
+        assertEquals(1, receiver.receiveCount12);
+
+        this.eventManager.send(new Event11());
+        assertEquals(2, receiver.receiveCount11);
+        assertEquals(1, receiver.receiveCount12);
+
+        this.eventManager.send(new Event1());
+        assertEquals(2, receiver.receiveCount11);
+        assertEquals(1, receiver.receiveCount12);
+    }
+
+    public void testHierarchicalEventReceiver() throws Exception {
+        EventReceiver10Full receiver = new EventReceiver10Full();
+        this.eventManager.subscribe(receiver);
+        assertEquals(0, receiver.receiveCount11 + receiver.receiveCount12);
+        assertEquals(0, receiver.receiveCount);
+
+        this.eventManager.send(new Event1());
+        assertEquals(1, receiver.receiveCount);
+        assertEquals(0, receiver.receiveCount11);
+        assertEquals(0, receiver.receiveCount12);
+
+        this.eventManager.send(new Event2());
+        assertEquals(2, receiver.receiveCount);
+        assertEquals(0, receiver.receiveCount11);
+        assertEquals(0, receiver.receiveCount12);
+
+        this.eventManager.send(new Event3());
+        assertEquals(3, receiver.receiveCount);
+        assertEquals(0, receiver.receiveCount11);
+        assertEquals(0, receiver.receiveCount12);
+
+        this.eventManager.send(new Event11());
+        assertEquals(4, receiver.receiveCount);
+        assertEquals(1, receiver.receiveCount11);
+        assertEquals(0, receiver.receiveCount12);
+
+        this.eventManager.send(new Event12());
+        assertEquals(5, receiver.receiveCount);
+        assertEquals(1, receiver.receiveCount11);
+        assertEquals(1, receiver.receiveCount12);
+
+        this.eventManager.send(new Event11());
+        assertEquals(6, receiver.receiveCount);
+        assertEquals(2, receiver.receiveCount11);
+        assertEquals(1, receiver.receiveCount12);
+
+        this.eventManager.send(new Event1());
+        assertEquals(7, receiver.receiveCount);
+        assertEquals(2, receiver.receiveCount11);
+        assertEquals(1, receiver.receiveCount12);
+    }
+
+    public static final class EventReceiver implements Receiver {
+
+        public int receiveCount;
+
+        public void inform(Event event, PortalService service) {
+            receiveCount++;
+        }
     }
 
     public static final class EventReceiver1 implements Receiver {
 
         public int receiveCount;
 
+        public void inform(Event1 event, PortalService service) {
+            receiveCount++;
+        }
+    }
+
+    public static final class EventReceiver2 implements Receiver {
+
+        public int receiveCount;
+
+        public void inform(Event2 event, PortalService service) {
+            receiveCount++;
+        }
+    }
+
+    public static final class EventReceiver3 implements Receiver {
+
+        public int receiveCount;
+
+        public void inform(Event3 event, PortalService service) {
+            receiveCount++;
+        }
+    }
+
+    public static final class EventReceiver10 implements Receiver {
+
+        public int receiveCount11;
+        public int receiveCount12;
+
+        public void inform(Event11 event, PortalService service) {
+            receiveCount11++;
+        }
+
+        public void inform(Event12 event, PortalService service) {
+            receiveCount12++;
+        }
+    }
+
+    public static final class EventReceiver10Full implements Receiver {
+
+        public int receiveCount;
+        public int receiveCount11;
+        public int receiveCount12;
+
         public void inform(Event event, PortalService service) {
             receiveCount++;
         }
+
+        public void inform(Event11 event, PortalService service) {
+            receiveCount11++;
+        }
+
+        public void inform(Event12 event, PortalService service) {
+            receiveCount12++;
+        }
     }
 
     public static class Event1 implements Event {
+        // dummy event
+    }
+
+    public static class Event2 implements Event {
+        // dummy event
+    }
+
+    public static class Event3 implements Event {
+        // dummy event
+    }
+
+    public static class Event11 extends Event1 {
+        // dummy event
+    }
+
+    public static class Event12 extends Event1 {
         // dummy event
     }
 }



Mime
View raw message