[jboss-svn-commits] JBoss Common SVN: r4635 - in arquillian/trunk/containers/weld-ee-embedded: src/main/java/org/jboss/arquillian/weldee and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 30 09:33:40 EDT 2010
Author: aslak
Date: 2010-06-30 09:33:39 -0400 (Wed, 30 Jun 2010)
New Revision: 4635
Added:
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/BeanUtils.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIConversationID.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIRequestID.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDISessionID.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleCreator.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleDestoryer.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleCreator.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleDestroyer.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleCreator.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleDestoryer.java
arquillian/trunk/containers/weld-ee-embedded/src/test/resources/arquillian.xml
Removed:
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java
Modified:
arquillian/trunk/containers/weld-ee-embedded/pom.xml
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java
Log:
ARQ-185 Added Session / Request and Conversation scope activators. Use Configuration to activate Conversation scope for non JSFRequests.
Modified: arquillian/trunk/containers/weld-ee-embedded/pom.xml
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/pom.xml 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/pom.xml 2010-06-30 13:33:39 UTC (rev 4635)
@@ -24,10 +24,24 @@
<properties>
<!-- Versioning -->
- <version.weld_core>1.0.1-SP1</version.weld_core>
+ <version.weld_core>1.0.2-SNAPSHOT</version.weld_core>
</properties>
+ <repositories> <!-- TEMP, only needed until 1.0.2/1.1.0 is released. We're dependent on ConversationManager2 -->
+ <repository>
+ <id>weld-sonatype</id>
+ <url>https://oss.sonatype.org/content/repositories/jboss-snapshots/</url>
+ <snapshots>
+ <updatePolicy>never</updatePolicy>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+ </repositories>
+
<dependencyManagement>
<dependencies>
<!-- org.jboss.weld -->
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/BeanUtils.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/BeanUtils.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/BeanUtils.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * BeanUtils
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+final class BeanUtils
+{
+ private BeanUtils() {}
+
+ @SuppressWarnings("unchecked")
+ static <T> T getBeanReference(BeanManager manager, Class<T> type)
+ {
+ Bean bean = manager.resolve(manager.getBeans(type));
+ return (T)manager.getReference(
+ bean,
+ type,
+ manager.createCreationalContext(null));
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIConversationID.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIConversationID.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIConversationID.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+/**
+ * Simple CDI COnversation ID holder object. Bound to the Class context
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class CDIConversationID
+{
+ private String id;
+
+ public CDIConversationID(final String id)
+ {
+ this.id = id;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+}
+
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIRequestID.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIRequestID.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDIRequestID.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import org.jboss.weld.context.api.BeanStore;
+
+/**
+ * Simple CDI COnversation ID holder object. Bound to the Class context
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class CDIRequestID
+{
+ private String id;
+ private BeanStore beanStore;
+
+ public CDIRequestID(final String id, BeanStore beanStore)
+ {
+ this.id = id;
+ this.beanStore = beanStore;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public BeanStore getBeanStore()
+ {
+ return beanStore;
+ }
+}
+
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDISessionID.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDISessionID.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/CDISessionID.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import org.jboss.weld.context.api.BeanStore;
+
+/**
+ * Simple CDI COnversation ID holder object. Bound to the Class context
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class CDISessionID
+{
+ private String id;
+ private BeanStore beanStore;
+
+ public CDISessionID(final String id, BeanStore beanStore)
+ {
+ this.id = id;
+ this.beanStore = beanStore;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public BeanStore getBeanStore()
+ {
+ return beanStore;
+ }
+}
+
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleCreator.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleCreator.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleCreator.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.conversation.ConversationManager2;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * SessionLifeCycleController
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ConversationLifeCycleCreator implements EventHandler<Event>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ if(manager == null)
+ {
+ throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
+ }
+
+ ConversationManager2 conversationManager = BeanUtils.getBeanReference(manager, ConversationManager2.class);
+ CDIConversationID id = context.get(CDIConversationID.class);
+ if(id == null)
+ {
+ id = new CDIConversationID(null); // when null creates a new empty conversation id.
+ }
+ conversationManager.setupContext();
+ conversationManager.setupConversation(id.getId());
+ }
+}
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleDestoryer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleDestoryer.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/ConversationLifeCycleDestoryer.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import javax.enterprise.context.Conversation;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.conversation.ConversationManager2;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * DestorySession
+ *
+ * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ConversationLifeCycleDestoryer implements EventHandler<Event> {
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+
+ Conversation conversation = BeanUtils.getBeanReference(manager, Conversation.class);
+ if(!conversation.isTransient())
+ {
+ context.add(CDIConversationID.class, new CDIConversationID(conversation.getId()));
+ }
+ else
+ {
+ context.add(CDIConversationID.class, new CDIConversationID(null));
+ }
+
+ ConversationManager2 conversationManager = BeanUtils.getBeanReference(manager, ConversationManager2.class);
+ conversationManager.teardownConversation();
+ conversationManager.teardownContext();
+ }
+}
\ No newline at end of file
Deleted: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -1,94 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * 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.jboss.arquillian.weldee;
-
-import java.util.UUID;
-
-import org.jboss.arquillian.spi.Context;
-import org.jboss.arquillian.spi.event.Event;
-import org.jboss.arquillian.spi.event.suite.EventHandler;
-import org.jboss.weld.context.ContextLifecycle;
-import org.jboss.weld.context.api.BeanStore;
-import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
-import org.jboss.weld.manager.api.WeldManager;
-
-/**
- * SessionLifeCycleController
- *
- * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class RequestLifeCycleController implements EventHandler<Event>
-{
- private Class<? extends Event> endRequestEvent;
-
- public RequestLifeCycleController(Class<? extends Event> endRequestEvent)
- {
- if(endRequestEvent == null)
- {
- throw new IllegalArgumentException("EndSessionEvent must be specified");
- }
- this.endRequestEvent = endRequestEvent;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
- */
- public void callback(Context context, Event event) throws Exception
- {
- WeldManager manager = context.get(WeldManager.class);
- if(manager == null)
- {
- throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
- }
- ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
-
- String requestId = UUID.randomUUID().toString();
- BeanStore beanStore = new ConcurrentHashMapBeanStore();
-
- lifeCycle.beginRequest(requestId, beanStore);
-
- context.register(endRequestEvent, new DestoryRequest(requestId, beanStore));
- }
-
- /**
- * DestorySession
- *
- * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
- * @version $Revision: $
- */
- private static class DestoryRequest implements EventHandler<Event> {
-
- private String requestId;
- private BeanStore beanStore;
-
- public DestoryRequest(String requestId, BeanStore beanStore)
- {
- this.requestId = requestId;
- this.beanStore = beanStore;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
- */
- public void callback(Context context, Event event) throws Exception
- {
- WeldManager manager = context.get(WeldManager.class);
- manager.getServices().get(ContextLifecycle.class).endRequest(requestId, beanStore);
- }
- }
-}
Copied: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleCreator.java (from rev 4529, arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java)
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleCreator.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleCreator.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import java.util.UUID;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * SessionLifeCycleController
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RequestLifeCycleCreator implements EventHandler<Event>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ if(manager == null)
+ {
+ throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
+ }
+ ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
+
+ String requestId = UUID.randomUUID().toString();
+ BeanStore beanStore = new ConcurrentHashMapBeanStore();
+
+ lifeCycle.beginRequest(requestId, beanStore);
+
+ context.add(CDIRequestID.class, new CDIRequestID(requestId, beanStore));
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleDestroyer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleDestroyer.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleDestroyer.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ *
+ * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RequestLifeCycleDestroyer implements EventHandler<Event> {
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ CDIRequestID id = context.get(CDIRequestID.class);
+ if(id != null)
+ {
+ manager.getServices().get(ContextLifecycle.class).endRequest(id.getId(), id.getBeanStore());
+ }
+ }
+}
Deleted: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * 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.jboss.arquillian.weldee;
-
-import java.util.UUID;
-
-import org.jboss.arquillian.spi.Context;
-import org.jboss.arquillian.spi.event.Event;
-import org.jboss.arquillian.spi.event.suite.EventHandler;
-import org.jboss.weld.context.ContextLifecycle;
-import org.jboss.weld.context.api.BeanStore;
-import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
-import org.jboss.weld.manager.api.WeldManager;
-
-/**
- * SessionLifeCycleController
- *
- * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class SessionLifeCycleController implements EventHandler<Event>
-{
- private Class<? extends Event> endSessionEvent;
-
- public SessionLifeCycleController(Class<? extends Event> endSessionEvent)
- {
- if(endSessionEvent == null)
- {
- throw new IllegalArgumentException("EndSessionEvent must be specified");
- }
- this.endSessionEvent = endSessionEvent;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
- */
- public void callback(Context context, Event event) throws Exception
- {
- WeldManager manager = context.get(WeldManager.class);
- if(manager == null)
- {
- throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
- }
- ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
-
- String sessionId = UUID.randomUUID().toString();
- BeanStore beanStore = new ConcurrentHashMapBeanStore();
-
- lifeCycle.restoreSession(sessionId, beanStore);
- context.register(endSessionEvent, new DestorySession(sessionId, beanStore));
- }
-
- /**
- * DestorySession
- *
- * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
- * @version $Revision: $
- */
- private static class DestorySession implements EventHandler<Event> {
-
- private String sessionId;
- private BeanStore beanStore;
-
- public DestorySession(String sessionId, BeanStore beanStore)
- {
- this.sessionId = sessionId;
- this.beanStore = beanStore;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
- */
- public void callback(Context context, Event event) throws Exception
- {
- WeldManager manager = context.get(WeldManager.class);
- manager.getServices().get(ContextLifecycle.class).endSession(sessionId, beanStore);
- }
- }
-}
Copied: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleCreator.java (from rev 4529, arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java)
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleCreator.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleCreator.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.arquillian.weldee;
+
+import java.util.UUID;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * SessionLifeCycleController
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class SessionLifeCycleCreator implements EventHandler<Event>
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ if(manager == null)
+ {
+ throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
+ }
+ ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
+
+ String sessionId = UUID.randomUUID().toString();
+ BeanStore beanStore = new ConcurrentHashMapBeanStore();
+
+ lifeCycle.restoreSession(sessionId, beanStore);
+ context.add(CDISessionID.class, new CDISessionID(sessionId, beanStore));
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleDestoryer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleDestoryer.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleDestoryer.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,29 @@
+package org.jboss.arquillian.weldee;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * DestorySession
+ *
+ * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class SessionLifeCycleDestoryer implements EventHandler<Event> {
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ CDISessionID id = context.get(CDISessionID.class);
+ if(id != null)
+ {
+ manager.getServices().get(ContextLifecycle.class).endSession(id.getId(), id.getBeanStore());
+ }
+ }
+}
Modified: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -27,10 +27,23 @@
*/
public class WeldEEMockConfiguration implements ContainerConfiguration
{
-
+ /**
+ * Flag to enable the Conversation Scope outside a JSF Request
+ */
+ private boolean enableConversationScope = false;
+
public ContainerProfile getContainerProfile()
{
return ContainerProfile.STANDALONE;
}
+ public void setEnableConversationScope(boolean enableConversationScope)
+ {
+ this.enableConversationScope = enableConversationScope;
+ }
+
+ public boolean isEnableConversationScope()
+ {
+ return enableConversationScope;
+ }
}
Modified: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -23,16 +23,21 @@
import org.jboss.arquillian.spi.DeployableContainer;
import org.jboss.arquillian.spi.DeploymentException;
import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.arquillian.spi.event.container.AfterDeploy;
import org.jboss.arquillian.spi.event.container.BeforeUnDeploy;
import org.jboss.arquillian.spi.event.suite.After;
import org.jboss.arquillian.spi.event.suite.Before;
-import org.jboss.arquillian.spi.event.suite.BeforeClass;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.arquillian.spi.event.suite.TestEvent;
import org.jboss.arquillian.weldee.mock.MockEELifecycle;
+import org.jboss.arquillian.weldee.mock.MockHttpSession;
+import org.jboss.arquillian.weldee.mock.MockServletContext;
import org.jboss.arquillian.weldee.mock.TestContainer;
import org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchive;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.weld.bootstrap.WeldBootstrap;
import org.jboss.weld.manager.api.WeldManager;
+import org.jboss.weld.servlet.HttpSessionManager;
/**
* WeldEEMockConainer
@@ -52,6 +57,10 @@
public ContainerMethodExecutor deploy(Context context, Archive<?> archive) throws DeploymentException
{
+ boolean enableConversation = context.get(Configuration.class)
+ .getContainerConfig(WeldEEMockConfiguration.class)
+ .isEnableConversationScope();
+
MockEELifecycle lifecycle = new MockEELifecycle(
archive.as(ShrinkwrapBeanDeploymentArchive.class));
@@ -62,9 +71,34 @@
context.add(WeldBootstrap.class, lifecycle.getBootstrap());
context.add(WeldManager.class, container.getBeanManager());
- context.register(BeforeClass.class, new SessionLifeCycleController(BeforeUnDeploy.class));
- context.register(Before.class, new RequestLifeCycleController(After.class));
+ context.register(AfterDeploy.class, new SessionLifeCycleCreator());
+ context.register(BeforeUnDeploy.class, new SessionLifeCycleDestoryer());
+ context.register(Before.class, new RequestLifeCycleCreator());
+
+ // handler to 'Produce' a fake HTTPSession
+ // TODO: Weld ConversationManager should communicate with a Service so it's possible to override the HttpSessionManager as part of Bootstrap.
+ context.register(Before.class, new EventHandler<TestEvent>()
+ {
+ public void callback(Context context, TestEvent event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ CDISessionID id = context.get(CDISessionID.class);
+ if(id != null)
+ {
+ BeanUtils.getBeanReference(manager, HttpSessionManager.class)
+ .setSession(
+ new MockHttpSession(id.getId(), new MockServletContext("/")));
+ }
+ }
+ });
+ if(enableConversation)
+ {
+ context.register(Before.class, new ConversationLifeCycleCreator());
+ context.register(After.class, new ConversationLifeCycleDestoryer());
+ }
+ context.register(After.class, new RequestLifeCycleDestroyer());
+
return new LocalMethodExecutor();
}
Modified: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -117,27 +117,6 @@
}
/**
- * Utility method which ensures a request is active and available for use
- *
- */
- public TestContainer ensureRequestActive()
- {
- if (!getLifecycle().isSessionActive())
- {
- getLifecycle().beginSession();
- }
- if (!getLifecycle().isConversationActive())
- {
- ((ConversationContext) getLifecycle().getConversationContext()).setActive(true);
- }
- if (!getLifecycle().isRequestActive())
- {
- getLifecycle().beginRequest();
- }
- return this;
- }
-
- /**
* Clean up the container, ending any active contexts
*
*/
Modified: arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java 2010-06-30 09:53:44 UTC (rev 4634)
+++ arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java 2010-06-30 13:33:39 UTC (rev 4635)
@@ -16,6 +16,8 @@
*/
package org.jboss.arquillian.weldee.beans;
+import java.io.Serializable;
+
import javax.enterprise.context.ApplicationScoped;
/**
@@ -25,8 +27,10 @@
* @version $Revision: $
*/
@ApplicationScoped
-public class MyBean
+public class MyBean implements Serializable
{
+ private static final long serialVersionUID = 1L;
+
public String getName()
{
return "aslak";
Added: arquillian/trunk/containers/weld-ee-embedded/src/test/resources/arquillian.xml
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/test/resources/arquillian.xml (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/test/resources/arquillian.xml 2010-06-30 13:33:39 UTC (rev 4635)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian xmlns="http://jboss.com/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:weld="urn:arq:org.jboss.arquillian.weldee">
+
+ <weld:container>
+ <weld:enableConversationScope>true</weld:enableConversationScope>
+ </weld:container>
+
+</arquillian>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list