[jboss-svn-commits] JBoss Common SVN: r4665 - in arquillian/trunk/containers/weld-ee-embedded-1.1/src: test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1 and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 2 09:52:00 EDT 2010
Author: aslak
Date: 2010-07-02 09:51:59 -0400 (Fri, 02 Jul 2010)
New Revision: 4665
Added:
arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationConversationScopeTestCase.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationSessionScopeTestCase.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/Chicken.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/TalkingChicken.java
Modified:
arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleCreator.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleDestoryer.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleCreator.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleDestroyer.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEEMockContainer.java
arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/MyBean.java
Log:
ARQ-185 Fixed Conversation restore issue between calls.
Modified: arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleCreator.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleCreator.java 2010-07-02 11:02:08 UTC (rev 4664)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleCreator.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -47,7 +47,11 @@
{
id = new CDIConversationID(null); // when null creates a new empty conversation id.
}
- conversationManager.setupContext();
+
+ if(!conversationManager.isContextActive())
+ {
+ conversationManager.setupContext();
+ }
conversationManager.setupConversation(id.getId());
}
}
\ No newline at end of file
Modified: arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleDestoryer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleDestoryer.java 2010-07-02 11:02:08 UTC (rev 4664)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/ConversationLifeCycleDestoryer.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -51,6 +51,6 @@
ConversationManager2 conversationManager = BeanUtils.getBeanReference(manager, ConversationManager2.class);
conversationManager.teardownConversation();
- conversationManager.teardownContext();
+ //conversationManager.teardownContext();
}
}
\ No newline at end of file
Modified: arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleCreator.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleCreator.java 2010-07-02 11:02:08 UTC (rev 4664)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleCreator.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -49,7 +49,9 @@
String requestId = UUID.randomUUID().toString();
BeanStore beanStore = new ConcurrentHashMapBeanStore();
- lifeCycle.beginRequest(requestId, beanStore);
+ lifeCycle.getDependentContext().setActive(true);
+ lifeCycle.getRequestContext().setActive(true);
+ lifeCycle.getRequestContext().setBeanStore(beanStore);
context.add(CDIRequestID.class, new CDIRequestID(requestId, beanStore));
}
Modified: arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleDestroyer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleDestroyer.java 2010-07-02 11:02:08 UTC (rev 4664)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/RequestLifeCycleDestroyer.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -38,7 +38,10 @@
CDIRequestID id = context.get(CDIRequestID.class);
if(id != null)
{
- manager.getServices().get(ContextLifecycle.class).endRequest(id.getId(), id.getBeanStore());
+ ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
+
+ lifeCycle.getDependentContext().setActive(false);
+ lifeCycle.getRequestContext().setActive(false);
}
}
}
Modified: arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEEMockContainer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEEMockContainer.java 2010-07-02 11:02:08 UTC (rev 4664)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEEMockContainer.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -16,6 +16,11 @@
*/
package org.jboss.arquillian.container.weld.ee.embedded_1_1;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
import org.jboss.arquillian.container.weld.ee.embedded_1_1.mock.MockEELifecycle;
import org.jboss.arquillian.container.weld.ee.embedded_1_1.mock.MockHttpSession;
import org.jboss.arquillian.container.weld.ee.embedded_1_1.mock.MockServletContext;
@@ -80,15 +85,23 @@
// 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>()
{
+ private Map<String, HttpSession> sessionStore = new HashMap<String, HttpSession>();
+
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("/")));
+ HttpSessionManager sessionManager = BeanUtils.getBeanReference(manager, HttpSessionManager.class);
+
+ HttpSession session = sessionStore.get(id.getId());
+ if(session == null)
+ {
+ session = new MockHttpSession(id.getId(), new MockServletContext("/"));
+ }
+ sessionManager.setSession(session);
+ sessionStore.put(id.getId(), session);
}
}
});
Added: arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationConversationScopeTestCase.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationConversationScopeTestCase.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationConversationScopeTestCase.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -0,0 +1,101 @@
+/*
+ * 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.container.weld.ee.embedded_1_1;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.container.weld.ee.embedded_1_1.beans.TalkingChicken;
+import org.jboss.arquillian.junit.Arquillian;
+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.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * WeldEmbeddedIntegrationTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at Ignore // Can't guarantee method order in JUnit
+ at RunWith(Arquillian.class)
+public class WeldEmbeddedIntegrationConversationScopeTestCase
+{
+ @Deployment
+ public static JavaArchive createdeployment()
+ {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(
+ WeldEmbeddedIntegrationConversationScopeTestCase.class,
+ TalkingChicken.class)
+ .addManifestResource(
+ new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ private TalkingChicken chicken;
+
+ @Inject Conversation conversation;
+
+ @Test
+ public void shouldBeAbleToSetAgeWithoutStartingAConversation() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ chicken);
+
+ chicken.setAge(10);
+ }
+
+ @Test
+ public void shouldNotBeAbleToReadAgeConversationNotStarted() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ chicken);
+
+ Assert.assertEquals(new Integer(-1), chicken.getAge());
+ }
+
+ @Test
+ public void shouldBeAbleToSetAgeAndStartAConversation() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ chicken);
+
+ chicken.setAge(10);
+ conversation.begin();
+ }
+
+ @Test
+ public void shouldBeAbleToReadAgeAfterConversationWasStarted() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ chicken);
+
+ Assert.assertEquals(new Integer(10), chicken.getAge());
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationSessionScopeTestCase.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationSessionScopeTestCase.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationSessionScopeTestCase.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -0,0 +1,77 @@
+/*
+ * 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.container.weld.ee.embedded_1_1;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.container.weld.ee.embedded_1_1.beans.Chicken;
+import org.jboss.arquillian.junit.Arquillian;
+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.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * WeldEmbeddedIntegrationTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at Ignore // Can't guarantee method order in JUnit
+ at RunWith(Arquillian.class)
+public class WeldEmbeddedIntegrationSessionScopeTestCase
+{
+ @Deployment
+ public static JavaArchive createdeployment()
+ {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(
+ WeldEmbeddedIntegrationSessionScopeTestCase.class,
+ Chicken.class)
+ .addManifestResource(
+ new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ private Chicken chicken;
+
+ @Test
+ public void shouldBeAbleToSetAge() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ chicken);
+
+ chicken.setAge(10);
+ }
+
+ @Test
+ public void shouldBeAbleToReadAge() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ chicken);
+
+ Assert.assertEquals(new Integer(10), chicken.getAge());
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/Chicken.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/Chicken.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/Chicken.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -0,0 +1,43 @@
+/*
+ * 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.container.weld.ee.embedded_1_1.beans;
+
+import javax.enterprise.context.SessionScoped;
+
+/**
+ * Chicken
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at SessionScoped
+public class Chicken implements java.io.Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private Integer age;
+
+ public Integer getAge()
+ {
+ return age;
+ }
+
+ public void setAge(Integer age)
+ {
+ this.age = age;
+ }
+}
Modified: arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/MyBean.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/MyBean.java 2010-07-02 11:02:08 UTC (rev 4664)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/MyBean.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -31,8 +31,15 @@
{
private static final long serialVersionUID = 1L;
+ private String name = "aslak";
+
public String getName()
{
- return "aslak";
+ return name;
}
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
}
Added: arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/TalkingChicken.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/TalkingChicken.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/beans/TalkingChicken.java 2010-07-02 13:51:59 UTC (rev 4665)
@@ -0,0 +1,43 @@
+/*
+ * 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.container.weld.ee.embedded_1_1.beans;
+
+import javax.enterprise.context.ConversationScoped;
+
+/**
+ * Chicken
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at ConversationScoped
+public class TalkingChicken implements java.io.Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private Integer age = -1;
+
+ public Integer getAge()
+ {
+ return age;
+ }
+
+ public void setAge(Integer age)
+ {
+ this.age = age;
+ }
+}
More information about the jboss-svn-commits
mailing list