Author: pete.muir(a)jboss.org
Date: 2009-09-30 09:21:36 -0400 (Wed, 30 Sep 2009)
New Revision: 3821
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/AbstractHtmlUnitTest.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Foo.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/TxEventTest.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Updated.java
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/faces-config.xml
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/home.xhtml
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/web.xml
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
ri/trunk/tests/pom.xml
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java
ri/trunk/tests/unit-tests.xml
ri/trunk/version-matrix/pom.xml
Log:
WBRI-401
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2009-09-30
12:03:10 UTC (rev 3820)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2009-09-30
13:21:36 UTC (rev 3821)
@@ -34,9 +34,9 @@
private static Log log = Logging.getLog(DeferredEventNotification.class);
// The observer
- protected ObserverMethodImpl<?, T> observer;
+ protected final ObserverMethodImpl<?, T> observer;
// The event object
- protected T event;
+ protected final T event;
/**
* Creates a new deferred event notifier.
@@ -52,22 +52,25 @@
public void run()
{
- Lifecycle lifecycle =
Container.instance().deploymentServices().get(ContextLifecycle.class);
- BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
- lifecycle.beginRequest("async invocation", requestBeanStore);
try
{
log.debug("Sending event [" + event + "] directly to observer
" + observer);
- observer.sendEvent(event);
+ new RunInRequest()
+ {
+
+ @Override
+ protected void execute()
+ {
+ observer.sendEvent(event);
+ }
+
+ }.run();
+
}
catch (Exception e)
{
log.error("Failure while notifying an observer of event [" + event +
"]", e);
}
- finally
- {
- lifecycle.endRequest("async invocation", requestBeanStore);
- }
}
@Override
@@ -76,4 +79,33 @@
return "Deferred event [" + event + "] for [" + observer +
"]";
}
+ private abstract static class RunInRequest
+ {
+
+ protected abstract void execute();
+
+ public void run()
+ {
+ Lifecycle lifecycle =
Container.instance().deploymentServices().get(ContextLifecycle.class);
+ boolean requestActive = lifecycle.isRequestActive();
+ BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+ try
+ {
+ if (!requestActive)
+ {
+ lifecycle.beginRequest("async invocation", requestBeanStore);
+ }
+ execute();
+ }
+ finally
+ {
+ if (!requestActive)
+ {
+ lifecycle.endRequest("async invocation", requestBeanStore);
+ }
+ }
+ }
+
+ }
+
}
Modified: ri/trunk/tests/pom.xml
===================================================================
--- ri/trunk/tests/pom.xml 2009-09-30 12:03:10 UTC (rev 3820)
+++ ri/trunk/tests/pom.xml 2009-09-30 13:21:36 UTC (rev 3821)
@@ -104,6 +104,11 @@
<artifactId>jsf-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ </dependency>
+
</dependencies>
<build>
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java
===================================================================
---
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java 2009-09-30
12:03:10 UTC (rev 3820)
+++
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java 2009-09-30
13:21:36 UTC (rev 3821)
@@ -24,7 +24,6 @@
import org.jboss.webbeans.mock.MockServletContext;
import org.jboss.webbeans.mock.el.EL;
import org.jboss.webbeans.servlet.ServletHelper;
-import org.jboss.webbeans.test.harness.AbstractStandaloneContainersImpl;
import org.jboss.webbeans.util.collections.EnumerationList;
import org.testng.ITestContext;
import org.testng.annotations.AfterClass;
@@ -196,5 +195,10 @@
ELContext elContext = EL.createELContext(getCurrentManager().getCurrent());
return (T) EL.EXPRESSION_FACTORY.createValueExpression(elContext, expression,
expectedType).getValue(elContext);
}
+
+ protected String getPath(String viewId)
+ {
+ return getContextPath() + viewId;
+ }
}
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/AbstractHtmlUnitTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/AbstractHtmlUnitTest.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/AbstractHtmlUnitTest.java 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,50 @@
+package org.jboss.webbeans.test.unit.implementation.event.tx;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public abstract class AbstractHtmlUnitTest extends AbstractWebBeansTest
+{
+
+ public AbstractHtmlUnitTest()
+ {
+ super();
+ }
+
+ protected <T extends HtmlElement> T getFirstMatchingElement(HtmlPage page,
Class<T> elementClass, String id)
+ {
+
+ Set<T> inputs = getElements(page.getBody(), elementClass);
+ for (T input : inputs)
+ {
+ if (input.getId().contains(id))
+ {
+ return input;
+ }
+ }
+ return null;
+ }
+
+ protected <T> Set<T> getElements(HtmlElement rootElement, Class<T>
elementClass)
+ {
+ Set<T> result = new HashSet<T>();
+
+ for (HtmlElement element : rootElement.getAllHtmlChildElements())
+ {
+ result.addAll(getElements(element, elementClass));
+ }
+
+ if (elementClass.isInstance(rootElement))
+ {
+ result.add(elementClass.cast(rootElement));
+ }
+ return result;
+
+ }
+
+}
\ No newline at end of file
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/AbstractHtmlUnitTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Foo.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Foo.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Foo.java 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,49 @@
+package org.jboss.webbeans.test.unit.implementation.event.tx;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.event.TransactionPhase;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.transaction.UserTransaction;
+
+@Named
+@ApplicationScoped
+public class Foo implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ @Inject
+ private UserTransaction utx;
+
+ @Inject @Updated
+ private Event<String> event1;
+
+ public Foo()
+ {
+ }
+
+ public String save()
+ {
+ try
+ {
+ utx.begin();
+ event1.fire("Fired using Event Interface with AnnotationLiteral.");
+ utx.commit();
+ }
+ catch (Exception e)
+ {
+ }
+ return null;
+ }
+
+ public void eventObserver(@Observes(during = TransactionPhase.AFTER_COMPLETION)
@Updated String s)
+ {
+ FacesContext.getCurrentInstance().addMessage(null, new
FacesMessage("AfterCompletion Event Recieved!"));
+ }
+}
\ No newline at end of file
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Foo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/TxEventTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/TxEventTest.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/TxEventTest.java 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,39 @@
+package org.jboss.webbeans.test.unit.implementation.event.tx;
+
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor;
+import org.testng.annotations.Test;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+
+@Artifact(addCurrentPackage=false)
+@IntegrationTest(runLocally=true)
+@Resources({
+ @Resource(source="faces-config.xml",
destination="WEB-INF/faces-config.xml"),
+ @Resource(source="web.xml",
destination=WarArtifactDescriptor.WEB_XML_DESTINATION),
+ @Resource(source="home.xhtml", destination="home.xhtml")
+})
+@Classes({
+ Foo.class,
+ Updated.class
+})
+public class TxEventTest extends AbstractHtmlUnitTest
+{
+
+ @Test(description="WBRI-401")
+ public void testRequestContextLifecycle() throws Exception
+ {
+ WebClient webClient = new WebClient();
+ HtmlPage home = webClient.getPage(getPath("/home.jsf"));
+ HtmlSubmitInput beginConversationButton = getFirstMatchingElement(home,
HtmlSubmitInput.class, "SaveButton");
+ beginConversationButton.click();
+ }
+
+}
\ No newline at end of file
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/TxEventTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Updated.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Updated.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Updated.java 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.test.unit.implementation.event.tx;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+@Retention(RUNTIME)
+@Target( { TYPE, METHOD, FIELD, PARAMETER })
+@Documented
+@interface Updated
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/tx/Updated.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/faces-config.xml
===================================================================
---
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/faces-config.xml
(rev 0)
+++
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/faces-config.xml 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<faces-config version="2.0"
+
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2.0.xsd">
+
+</faces-config>
\ No newline at end of file
Property changes on:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/faces-config.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/home.xhtml
===================================================================
---
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/home.xhtml
(rev 0)
+++
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/home.xhtml 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core">
+
+ <h:head>
+ <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
+ <title>JSF 2.0 Web Beans Example</title>
+ </h:head>
+
+ <h:body>
+ <h:form id="NumberGuessMain">
+ <h:panelGrid styleClass="title-panel">
+ <h:outputText value="Guess Number"
styleClass="title-panel-text"/>
+ <h:outputText value="Powered By JavaServer Faces 2.0 and Web
Beans" styleClass="title-panel-subtext"/>
+ </h:panelGrid>
+
+ <div style="color: black; font-size: 20px;">
+ Transactional Services
+ </div>
+
+ <h:panelGrid border="1" columns="5"
style="font-size: 18px;">
+ <h:commandButton id="SaveButton" value="Save"
action="#{foo.save}" />
+ </h:panelGrid>
+
+ <div style="color: red; font-size: 14px;">
+ <h:messages id="messages" globalOnly="false"/>
+ </div>l
+ </h:form>
+ </h:body>
+
+</html>
Property changes on:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/home.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/web.xml
===================================================================
---
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/web.xml
(rev 0)
+++
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/web.xml 2009-09-30
13:21:36 UTC (rev 3821)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.5"
+
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>Web Beans Test</display-name>
+
+
+ <!-- JSF -->
+
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+
+ <session-config>
+ <session-timeout>10</session-timeout>
+ </session-config>
+
+</web-app>
Property changes on:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/implementation/event/tx/web.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/tests/unit-tests.xml
===================================================================
--- ri/trunk/tests/unit-tests.xml 2009-09-30 12:03:10 UTC (rev 3820)
+++ ri/trunk/tests/unit-tests.xml 2009-09-30 13:21:36 UTC (rev 3821)
@@ -45,6 +45,7 @@
<package
name="org.jboss.webbeans.test.unit.implementation.enterpise.lifecycle" />
<package
name="org.jboss.webbeans.test.unit.implementation.enterprise.sbi" />
<package name="org.jboss.webbeans.test.unit.implementation.event"
/>
+ <package
name="org.jboss.webbeans.test.unit.implementation.event.tx" />
<package
name="org.jboss.webbeans.test.unit.implementation.exceptions" />
<package name="org.jboss.webbeans.test.unit.implementation.named"
/>
<package
name="org.jboss.webbeans.test.unit.implementation.newsimple" />
Modified: ri/trunk/version-matrix/pom.xml
===================================================================
--- ri/trunk/version-matrix/pom.xml 2009-09-30 12:03:10 UTC (rev 3820)
+++ ri/trunk/version-matrix/pom.xml 2009-09-30 13:21:36 UTC (rev 3821)
@@ -425,6 +425,12 @@
<version>4.7</version>
</dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>2.4</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>