[seam-commits] Seam SVN: r13167 - in modules/faces/branches/exception_handling/impl/src: main/java/org/jboss/seam/faces and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 15 17:29:49 EDT 2010


Author: lightguard
Date: 2010-06-15 17:29:48 -0400 (Tue, 15 Jun 2010)
New Revision: 13167

Added:
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandlerFactory.java
   modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java
Removed:
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandler.java
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandlerFactory.java
Modified:
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java
   modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java
   modules/faces/branches/exception_handling/impl/src/main/resources/META-INF/faces-config.xml
   modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java
   modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java
Log:
First working test

Moving things around a bit to seperate the core exception handling from the impl

Also a couple of TODOs to support unwrapping and walking the exception type chain.

Modified: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/ExceptionHandlerExecutor.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -21,14 +21,11 @@
  */
 package org.jboss.seam.exceptionhandling;
 
-import org.jboss.seam.faces.util.BeanManagerUtils;
-
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 /**
  * Finds and invokes all {@link ExceptionHandler} instants for a particular
@@ -50,18 +47,20 @@
       final Throwable exception = event.getException();
       final State state = event.getState();
       final BeanManager beanManager = state.getBeanManager();
-      final BeanManagerUtils managerUtils = BeanManagerUtils.getContextualInstance(beanManager, BeanManagerUtils.class);
       ExceptionHandler bean;
-      final List<ExceptionHandler> beans = managerUtils.getContextualInstances(ExceptionHandler.class);
+      final List<ExceptionHandler> beans = this.getContextualExceptionHandlerInstances(beanManager);
 
       // Finding the correct exception handlers using reflection based on the method
-      // to determine if it's the correct 
+      // to determine if it's the correct
+
+      // TODO: Uwrap the exception
       for (Iterator<ExceptionHandler> iter = beans.iterator(); iter.hasNext();)
       {
          bean = iter.next();
          try
          {
-            bean.getClass().getMethod("handle", HandlerChain.class, FacesState.class, exception.getClass());
+            // TODO: search for type hierarchy as well.
+            bean.getClass().getMethod("handle", HandlerChain.class, state.getClass().getInterfaces()[0], exception.getClass());
          }
          catch (NoSuchMethodException e)
          {
@@ -69,6 +68,7 @@
          }
       }
 
+      // TODO: if priorities are the same look for type hierarchy
       Collections.sort(beans, new Comparator<ExceptionHandler>()
       {
          public int compare(ExceptionHandler lhs, ExceptionHandler rhs)
@@ -83,4 +83,19 @@
          event.setExceptionHandled(true);
       }
    }
+
+   @SuppressWarnings("unchecked")
+   private <T> List<T> getContextualExceptionHandlerInstances(BeanManager manager)
+   {
+      List<T> result = new ArrayList<T>();
+      for (Bean<?> bean : manager.getBeans(ExceptionHandler.class))
+      {
+         CreationalContext<T> context = (CreationalContext<T>) manager.createCreationalContext(bean);
+         if (context != null)
+         {
+            result.add((T) manager.getReference(bean, ExceptionHandler.class, context));
+         }
+      }
+      return result;
+   }
 }

Modified: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/FacesStateImpl.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -29,15 +29,19 @@
 
 public class FacesStateImpl implements FacesState
 {
-   @Inject
    private BeanManager beanManager;
 
-   @Inject
    private FacesContext facesContext;
 
-   @Inject
    private NavigationHandler navigationHandler;
 
+   public FacesStateImpl(BeanManager beanManager, FacesContext facesContext)
+   {
+      this.beanManager = beanManager;
+      this.facesContext = facesContext;
+      this.navigationHandler = facesContext.getApplication().getNavigationHandler();
+   }
+
    /**
     * @return the currently active Faces Context object
     */
@@ -54,7 +58,13 @@
     */
    public void navigate(String viewId)
    {
-      this.navigationHandler.handleNavigation(this.facesContext, null, viewId);
+      String currentViewId = null;
+
+      if (this.facesContext.getViewRoot() != null)
+      {
+         currentViewId = this.facesContext.getViewRoot().getViewId();
+      }
+      this.navigationHandler.handleNavigation(this.facesContext, currentViewId, viewId);
    }
 
    /**

Deleted: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandler.java	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandler.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.exceptionhandling;
-
-import org.jboss.seam.faces.util.BeanManagerUtils;
-import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.util.TypeLiteral;
-import javax.faces.FacesException;
-import javax.faces.context.*;
-import javax.faces.context.ExceptionHandler;
-import javax.faces.event.ExceptionQueuedEvent;
-import javax.inject.Inject;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-public class SeamExceptionHandler extends ExceptionHandlerWrapper
-{
-   private BeanManager beanManager;
-
-   private BeanManagerUtils managerUtils;
-
-   private ExceptionHandler wrapped;
-
-
-   public SeamExceptionHandler() throws NamingException
-   {
-      this.beanManager = BeanManagerAccessor.getManager();
-      this.managerUtils = new BeanManagerUtils();
-   }
-
-   public SeamExceptionHandler(ExceptionHandler wrappedHandler) throws NamingException
-   {
-      this();
-      this.wrapped = wrappedHandler;
-   }
-
-   @Override
-   public void handle() throws FacesException
-   {
-      Set<Bean<?>> beans;
-      ExceptionQueuedEvent event;
-      Throwable exception;
-      HandlerChain chain;
-      FacesState state = BeanManagerUtils.getContextualInstance(this.beanManager, FacesStateImpl.class);
-      Bean<?> bean;
-
-      for (Iterator<ExceptionQueuedEvent> i = this.getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();)
-      {
-         event = i.next();
-         exception = event.getContext().getException();
-
-         final Throwable realException = (this.getRootCause(exception) != null) ? this.getRootCause(exception) : exception;
-
-         ExceptionEvent exceptionEventObject = new ExceptionEvent(realException, this.managerUtils.getContextualInstance(FacesState.class));
-
-         this.beanManager.fireEvent(exceptionEventObject);
-
-         if (exceptionEventObject.isExceptionHandled())
-         {
-            i.remove();
-         }
-      }
-
-      if (this.wrapped != null)
-      {
-         this.wrapped.handle();
-      }
-   }
-
-   @Override
-   public javax.faces.context.ExceptionHandler getWrapped()
-   {
-      return this.wrapped;
-   }
-}

Deleted: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandlerFactory.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandlerFactory.java	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandlerFactory.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.exceptionhandling;
-
-import javax.faces.context.ExceptionHandler;
-import javax.faces.context.ExceptionHandlerFactory;
-import javax.naming.NamingException;
-
-public class SeamExceptionHandlerFactory extends ExceptionHandlerFactory
-{
-   private ExceptionHandlerFactory parent;
-
-   public SeamExceptionHandlerFactory(ExceptionHandlerFactory parent)
-   {
-      this.parent = parent;
-   }
-
-   @Override
-   public javax.faces.context.ExceptionHandler getExceptionHandler()
-   {
-      ExceptionHandler result =  this.parent.getExceptionHandler();
-      try
-      {
-         return new SeamExceptionHandler(result);
-      }
-      catch (NamingException e)
-      {
-         return result;
-      }
-   }
-}

Copied: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java (from rev 13120, modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandler.java)
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java	                        (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.exceptionhandling;
+
+import org.jboss.seam.exceptionhandling.ExceptionEvent;
+import org.jboss.seam.exceptionhandling.FacesState;
+import org.jboss.seam.exceptionhandling.FacesStateImpl;
+import org.jboss.seam.exceptionhandling.HandlerChain;
+import org.jboss.seam.faces.util.BeanManagerUtils;
+import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.util.TypeLiteral;
+import javax.faces.FacesException;
+import javax.faces.context.*;
+import javax.faces.context.ExceptionHandler;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.inject.Inject;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+public class SeamExceptionHandler extends ExceptionHandlerWrapper
+{
+   @Inject
+   private BeanManager beanManager;
+
+   private ExceptionHandler wrapped;
+
+
+   public SeamExceptionHandler()
+   {
+   }
+
+   public SeamExceptionHandler(ExceptionHandler wrappedHandler)
+   {
+      this.wrapped = wrappedHandler;
+   }
+
+   @Override
+   public void handle() throws FacesException
+   {
+      Set<Bean<?>> beans;
+      ExceptionQueuedEvent event;
+      Throwable exception;
+      HandlerChain chain;
+      Bean<?> bean;
+
+      if (this.beanManager == null)
+      {
+         this.beanManager = BeanManagerAccessor.getManager();
+      }
+
+      FacesState state = new FacesStateImpl(beanManager, FacesContext.getCurrentInstance());
+
+      for (Iterator<ExceptionQueuedEvent> i = this.getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();)
+      {
+         event = i.next();
+         exception = event.getContext().getException();
+
+         final Throwable realException = (this.getRootCause(exception) != null) ? this.getRootCause(exception) : exception;
+
+         ExceptionEvent exceptionEventObject = new ExceptionEvent(realException, state);
+
+         this.beanManager.fireEvent(exceptionEventObject);
+
+         if (exceptionEventObject.isExceptionHandled())
+         {
+            i.remove();
+         }
+      }
+
+      if (this.wrapped != null)
+      {
+         this.wrapped.handle();
+      }
+   }
+
+   @Override
+   public javax.faces.context.ExceptionHandler getWrapped()
+   {
+      return this.wrapped;
+   }
+}


Property changes on: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandler.java
___________________________________________________________________
Name: svn:mime-type
   + text/x-java-source
Name: svn:keywords
   + Author Date Id Revision URL
Name: svn:eol-style
   + native

Copied: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandlerFactory.java (from rev 13077, modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/exceptionhandling/SeamExceptionHandlerFactory.java)
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandlerFactory.java	                        (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandlerFactory.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.faces.exceptionhandling;
+
+import javax.faces.context.ExceptionHandler;
+import javax.faces.context.ExceptionHandlerFactory;
+
+public class SeamExceptionHandlerFactory extends ExceptionHandlerFactory
+{
+   private ExceptionHandlerFactory parent;
+
+   public SeamExceptionHandlerFactory(ExceptionHandlerFactory parent)
+   {
+      this.parent = parent;
+   }
+
+   @Override
+   public javax.faces.context.ExceptionHandler getExceptionHandler()
+   {
+      ExceptionHandler result = this.parent.getExceptionHandler();
+      return new SeamExceptionHandler(result);
+
+   }
+}


Property changes on: modules/faces/branches/exception_handling/impl/src/main/java/org/jboss/seam/faces/exceptionhandling/SeamExceptionHandlerFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/x-java-source
Name: svn:keywords
   + Author Date Id Revision URL
Name: svn:eol-style
   + native

Modified: modules/faces/branches/exception_handling/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/faces/branches/exception_handling/impl/src/main/resources/META-INF/faces-config.xml	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/main/resources/META-INF/faces-config.xml	2010-06-15 21:29:48 UTC (rev 13167)
@@ -19,7 +19,7 @@
 	
 	<factory>
 		<external-context-factory>org.jboss.seam.faces.environment.SeamExternalContextFactory</external-context-factory>
-      <exception-handler-factory>org.jboss.seam.exceptionhandling.SeamExceptionHandlerFactory</exception-handler-factory>
+      <exception-handler-factory>org.jboss.seam.faces.exceptionhandling.SeamExceptionHandlerFactory</exception-handler-factory>
 	</factory>
 
 	<application>

Modified: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ExceptionHandlerTest.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -26,44 +26,75 @@
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.seam.faces.environment.FacesContextProducer;
 import org.jboss.seam.faces.environment.MockFacesContext;
+import org.jboss.seam.faces.exceptionhandling.SeamExceptionHandler;
+import org.jboss.seam.faces.exceptionhandling.SeamExceptionHandlerFactory;
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.application.MockApplication;
+import org.jboss.test.faces.mock.application.MockNavigationHandler;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import static org.junit.Assert.*;
 
 import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.application.NavigationHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.ExceptionHandlerFactory;
 import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
 import javax.inject.Inject;
 
+import java.io.IOException;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertTrue;
+
 @RunWith(Arquillian.class)
 public class ExceptionHandlerTest
 {
+   @Inject
+   private SeamExceptionHandler seamHandler;
+
+   @Inject
+   private UnsupportedOperationExceptionHandler handler;
+
+   @Inject
+   private BeanManager beanManager;
+
+   private MockFacesEnvironment environment;
+
    @Deployment
    public static Archive<?> createTestArchive()
    {
       return ShrinkWrap.create("test.jar", JavaArchive.class)
-         .addClass(FacesContextProducer.class)
-         .addClass(UnsupportedOperationExceptionHandler.class)
+         .addClasses(UnsupportedOperationExceptionHandler.class, SeamExceptionHandler.class,
+                     ExceptionHandlerExecutor.class)
          .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
    }
 
-   @Inject
-   private Instance<FacesContext> facesContextInstance;
+   @Before
+   public void setup()
+   {
+      this.environment = MockFacesEnvironment.createEnvironment().withApplication();
 
-   @Inject
-   private UnsupportedOperationExceptionHandler handler;
+      expect(this.environment.getApplication().getNavigationHandler())
+         .andStubReturn(this.environment.createMock(NavigationHandler.class));
 
+      this.environment.replay();
+   }
+
    @Test
-   public void testHandlerIsCalled()
+   public void testHandlerIsCalled() throws IOException
    {
-      new MockFacesContext().set();
-      
-      this.facesContextInstance.get().getApplication();
-
+      ExceptionEvent event = new ExceptionEvent(new UnsupportedOperationException(), new FacesStateImpl(this.beanManager, this.environment.getFacesContext()));
+      this.beanManager.fireEvent(event);
       assertTrue(this.handler.isHandleCalled());
+      assertTrue(event.isExceptionHandled());
    }
 }

Added: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java	                        (rev 0)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.exceptionhandling;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+
+public class ThrowExceptionRenderer extends Renderer
+{
+   /**
+    * <p>Render the beginning specified {@link javax.faces.component.UIComponent} to the
+    * output stream or writer associated with the response we are creating.
+    * If the conversion attempted in a previous call to
+    * <code>getConvertedValue()</code> for this component failed, the state
+    * information saved during execution
+    * of <code>decode()</code> should be used to reproduce the incorrect
+    * input.</p>
+    *
+    * @param context   {@link javax.faces.context.FacesContext} for the request we are processing
+    * @param component {@link javax.faces.component.UIComponent} to be rendered
+    * @throws java.io.IOException  if an input/output error occurs while rendering
+    * @throws NullPointerException if <code>context</code>
+    *                              or <code>component</code> is null
+    */
+   @Override
+   public void encodeBegin(FacesContext context, UIComponent component) throws IOException
+   {
+      throw new UnsupportedOperationException();
+   }
+}


Property changes on: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/ThrowExceptionRenderer.java
___________________________________________________________________
Name: svn:mime-type
   + text/x-java-source
Name: svn:keywords
   + Author Date Id Revision URL
Name: svn:eol-style
   + native

Modified: modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java
===================================================================
--- modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java	2010-06-15 20:53:32 UTC (rev 13166)
+++ modules/faces/branches/exception_handling/impl/src/test/java/org/jboss/seam/exceptionhandling/UnsupportedOperationExceptionHandler.java	2010-06-15 21:29:48 UTC (rev 13167)
@@ -22,6 +22,9 @@
 
 package org.jboss.seam.exceptionhandling;
 
+import javax.enterprise.context.RequestScoped;
+
+ at RequestScoped
 public class UnsupportedOperationExceptionHandler implements ExceptionHandler<UnsupportedOperationException, FacesState>
 {
    private boolean handleCalled;



More information about the seam-commits mailing list