[seam-commits] Seam SVN: r8776 - trunk/src/test/unit/org/jboss/seam/test/unit.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Aug 22 07:13:20 EDT 2008
Author: shane.bryzak at jboss.com
Date: 2008-08-22 07:13:20 -0400 (Fri, 22 Aug 2008)
New Revision: 8776
Added:
trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java
Modified:
trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
Log:
unit test for JBSEAM-3295
Added: trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java (rev 0)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java 2008-08-22 11:13:20 UTC (rev 8776)
@@ -0,0 +1,26 @@
+package org.jboss.seam.test.unit;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
+ at Name("fooBar")
+ at Scope(ScopeType.APPLICATION)
+public class FooBar
+{
+ @In Foo foo;
+
+ public Foo delayedGetFoo(CountDownLatch latch)
+ {
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException ex) {}
+
+ return foo;
+ }
+}
Property changes on: trunk/src/test/unit/org/jboss/seam/test/unit/FooBar.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
===================================================================
--- trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java 2008-08-22 09:44:00 UTC (rev 8775)
+++ trunk/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java 2008-08-22 11:13:20 UTC (rev 8776)
@@ -2,6 +2,7 @@
package org.jboss.seam.test.unit;
import java.lang.reflect.Method;
+import java.util.concurrent.CountDownLatch;
import javax.faces.context.ExternalContext;
import javax.faces.event.PhaseId;
@@ -25,6 +26,7 @@
import org.jboss.seam.core.Manager;
import org.jboss.seam.ejb.RemoveInterceptor;
import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.intercept.InvocationContext;
import org.jboss.seam.mock.MockApplication;
import org.jboss.seam.mock.MockExternalContext;
import org.jboss.seam.mock.MockFacesContext;
@@ -235,6 +237,104 @@
}
@Test
+ public void testReentrantBijection() throws Exception
+ {
+ MockServletContext servletContext = new MockServletContext();
+ ServletLifecycle.beginApplication(servletContext);
+ MockExternalContext externalContext = new MockExternalContext(servletContext);
+ Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
+ appContext.set( Seam.getComponentName(Init.class), new Init() );
+ appContext.set( Seam.getComponentName(ConversationEntries.class) + ".component",
+ new Component(ConversationEntries.class, appContext) );
+ appContext.set( Seam.getComponentName(Manager.class) + ".component",
+ new Component(Manager.class, appContext) );
+ appContext.set( Seam.getComponentName(Foo.class) + ".component",
+ new Component(Foo.class, appContext) );
+ appContext.set( Seam.getComponentName(FooBar.class) + ".component",
+ new Component(FooBar.class, appContext) );
+
+ FacesLifecycle.beginRequest(externalContext);
+ Manager.instance().setCurrentConversationId("1");
+ FacesLifecycle.resumeConversation(externalContext);
+ FacesLifecycle.setPhaseId(PhaseId.RENDER_RESPONSE);
+
+ final Foo foo = new Foo();
+ final FooBar fooBar = new FooBar();
+
+ Contexts.getSessionContext().set("foo", foo);
+
+ final BijectionInterceptor bi = new BijectionInterceptor();
+ bi.setComponent( new Component(FooBar.class, appContext) );
+
+ final Method m = FooBar.class.getMethod("delayedGetFoo", CountDownLatch.class);
+
+ final CountDownLatch latchA = new CountDownLatch(1);
+ final CountDownLatch latchB = new CountDownLatch(1);
+ final CountDownLatch latchC = new CountDownLatch(1);
+ final CountDownLatch latchD = new CountDownLatch(1);
+
+ final InvocationContext invocationA = new MockInvocationContext() {
+ @Override public Object getTarget() { return fooBar; }
+ @Override public Method getMethod() { return m; }
+ @Override public Object[] getParameters() { return new Object[] { latchA }; }
+ };
+
+ final InvocationContext invocationB = new MockInvocationContext() {
+ @Override public Object getTarget() { return fooBar; }
+ @Override public Method getMethod() { return m; }
+ @Override public Object[] getParameters() { return new Object[] { latchB }; }
+ };
+
+ new Thread(new Runnable() {
+ public void run() {
+ try
+ {
+ Foo result = (Foo) bi.aroundInvoke( invocationA );
+ assert result == foo;
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ finally
+ {
+ latchC.countDown();
+ }
+ }
+ }).start();
+
+ new Thread(new Runnable() {
+ public void run() {
+ try
+ {
+ Foo result = (Foo) bi.aroundInvoke( invocationB );
+ assert result == foo;
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ finally
+ {
+ latchD.countDown();
+ }
+ }
+ }).start();
+
+ // Allow invocationA to complete
+ latchA.countDown();
+
+ // Wait for invocationA to finalise
+ latchC.await();
+
+ // Allow invocationB to proceed
+ latchB.countDown();
+
+ // Wait for invocationB
+ latchD.await();
+ }
+
+ @Test
public void testConversationInterceptor() throws Exception
{
MockServletContext servletContext = new MockServletContext();
More information about the seam-commits
mailing list