Updated Branches: refs/heads/master 4939550ed -> b4aa7777f
DELTASPIKE-488 grouped-conversation tests Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/b4aa7777 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/b4aa7777 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/b4aa7777 Branch: refs/heads/master Commit: b4aa7777f1cd67327a7d60b1e00c0c34dea42062 Parents: 4939550 Author: gpetracek <[email protected]> Authored: Fri Jan 3 12:30:55 2014 +0100 Committer: gpetracek <[email protected]> Committed: Fri Jan 3 12:40:18 2014 +0100 ---------------------------------------------------------------------- .../GroupedConversationContext.java | 2 +- .../scope/conversation/ExplicitTestGroup.java | 23 +++ .../conversation/ExplicitlyGroupedBeanX.java | 53 +++++++ .../conversation/ExplicitlyGroupedBeanY.java | 53 +++++++ .../ExplicitlyGroupedConversationsTest.java | 158 +++++++++++++++++++ .../conversation/ImplicitlyGroupedBean.java | 51 ++++++ .../ImplicitlyGroupedConversationsTest.java | 146 +++++++++++++++++ 7 files changed, 485 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java index 106a85e..55bc043 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java @@ -65,7 +65,7 @@ public class GroupedConversationContext extends AbstractContext implements Group protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) { ConversationKey conversationKey = ConversationUtils.convertToConversationKey(contextual); - return this.conversationBeanHolder.getContextualStorage(beanManager, conversationKey, createIfNotExist); + return this.conversationBeanHolder.getContextualStorage(this.beanManager, conversationKey, createIfNotExist); } @Override http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitTestGroup.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitTestGroup.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitTestGroup.java new file mode 100644 index 0000000..e328385 --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitTestGroup.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.deltaspike.test.core.api.scope.conversation; + +public interface ExplicitTestGroup +{ +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanX.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanX.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanX.java new file mode 100644 index 0000000..9a44626 --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanX.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.deltaspike.test.core.api.scope.conversation; + +import org.apache.deltaspike.core.api.scope.ConversationGroup; +import org.apache.deltaspike.core.api.scope.GroupedConversation; +import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; + +import javax.inject.Inject; +import java.io.Serializable; + +@GroupedConversationScoped +@ConversationGroup(ExplicitTestGroup.class) +public class ExplicitlyGroupedBeanX implements Serializable +{ + private static final long serialVersionUID = -1291355584482007178L; + + private String value; + + @Inject + private GroupedConversation conversation; + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } + + public void done() + { + this.conversation.close(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanY.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanY.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanY.java new file mode 100644 index 0000000..0cb6df7 --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedBeanY.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.deltaspike.test.core.api.scope.conversation; + +import org.apache.deltaspike.core.api.scope.ConversationGroup; +import org.apache.deltaspike.core.api.scope.GroupedConversation; +import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; + +import javax.inject.Inject; +import java.io.Serializable; + +@GroupedConversationScoped +@ConversationGroup(ExplicitTestGroup.class) +public class ExplicitlyGroupedBeanY implements Serializable +{ + private static final long serialVersionUID = -1291355584482007178L; + + private String value; + + @Inject + private GroupedConversation conversation; + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } + + public void done() + { + this.conversation.close(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedConversationsTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedConversationsTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedConversationsTest.java new file mode 100644 index 0000000..223d31f --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ExplicitlyGroupedConversationsTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.deltaspike.test.core.api.scope.conversation; + +import org.apache.deltaspike.core.api.scope.ConversationGroup; +import org.apache.deltaspike.core.spi.scope.conversation.GroupedConversationManager; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.test.util.ArchiveUtils; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +@RunWith(Arquillian.class) +@Category(SeCategory.class) +public class ExplicitlyGroupedConversationsTest +{ + @Deployment + public static WebArchive deploy() + { + String simpleName = ExplicitlyGroupedConversationsTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") + .addPackage(ExplicitlyGroupedConversationsTest.class.getPackage().getName()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + + return ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Inject + private WindowContext windowContext; + + @Inject + @ConversationGroup(ExplicitTestGroup.class) + private ExplicitlyGroupedBeanX explicitlyGroupedBeanX; + + @Inject + @ConversationGroup(ExplicitTestGroup.class) + private ExplicitlyGroupedBeanY explicitlyGroupedBeanY; + + @Inject + private GroupedConversationManager conversationManager; + + @Test + public void parallelConversationsTest() + { + windowContext.activateWindow("w1"); + + explicitlyGroupedBeanX.setValue("x1"); + explicitlyGroupedBeanY.setValue("x2"); + Assert.assertEquals("x1", explicitlyGroupedBeanX.getValue()); + Assert.assertEquals("x2", explicitlyGroupedBeanY.getValue()); + + windowContext.activateWindow("w2"); + + Assert.assertNull(explicitlyGroupedBeanX.getValue()); + Assert.assertNull(explicitlyGroupedBeanY.getValue()); + + explicitlyGroupedBeanX.setValue("y1"); + explicitlyGroupedBeanY.setValue("y2"); + Assert.assertEquals("y1", explicitlyGroupedBeanX.getValue()); + Assert.assertEquals("y2", explicitlyGroupedBeanY.getValue()); + } + + @Test + public void immediatelyClosedConversationTest() + { + windowContext.activateWindow("w1"); + + explicitlyGroupedBeanX.setValue("x1"); + explicitlyGroupedBeanY.setValue("x2"); + Assert.assertEquals("x1", explicitlyGroupedBeanX.getValue()); + Assert.assertEquals("x2", explicitlyGroupedBeanY.getValue()); + + explicitlyGroupedBeanX.done(); + + Assert.assertNull(explicitlyGroupedBeanX.getValue()); + Assert.assertNull(explicitlyGroupedBeanY.getValue()); + } + + @Test + public void immediatelyClosedConversationViaConversationManagerTest() + { + windowContext.activateWindow("w1"); + + explicitlyGroupedBeanX.setValue("x1"); + explicitlyGroupedBeanY.setValue("x2"); + Assert.assertEquals("x1", explicitlyGroupedBeanX.getValue()); + Assert.assertEquals("x2", explicitlyGroupedBeanY.getValue()); + + this.conversationManager.closeConversationGroup(ExplicitTestGroup.class); + + Assert.assertNull(explicitlyGroupedBeanX.getValue()); + Assert.assertNull(explicitlyGroupedBeanY.getValue()); + } + + @Test + public void immediatelyClosedConversationsTest() + { + windowContext.activateWindow("w1"); + + explicitlyGroupedBeanX.setValue("x1"); + explicitlyGroupedBeanY.setValue("x2"); + Assert.assertEquals("x1", explicitlyGroupedBeanX.getValue()); + Assert.assertEquals("x2", explicitlyGroupedBeanY.getValue()); + + this.conversationManager.closeConversations(); + + Assert.assertNull(explicitlyGroupedBeanX.getValue()); + Assert.assertNull(explicitlyGroupedBeanY.getValue()); + } + + @Test + public void immediatelyClosedConversationsViaWindowContextTest() + { + windowContext.activateWindow("w1"); + + explicitlyGroupedBeanX.setValue("x1"); + explicitlyGroupedBeanY.setValue("x2"); + Assert.assertEquals("x1", explicitlyGroupedBeanX.getValue()); + Assert.assertEquals("x2", explicitlyGroupedBeanY.getValue()); + + Assert.assertTrue(this.windowContext.closeWindow("w1")); + windowContext.activateWindow("w1"); + + Assert.assertNull(explicitlyGroupedBeanX.getValue()); + Assert.assertNull(explicitlyGroupedBeanY.getValue()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedBean.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedBean.java new file mode 100644 index 0000000..874c29c --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedBean.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.deltaspike.test.core.api.scope.conversation; + +import org.apache.deltaspike.core.api.scope.GroupedConversation; +import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; + +import javax.inject.Inject; +import java.io.Serializable; + +@GroupedConversationScoped +public class ImplicitlyGroupedBean implements Serializable +{ + private static final long serialVersionUID = -4722854711870629520L; + + private String value; + + @Inject + private GroupedConversation conversation; + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } + + public void done() + { + this.conversation.close(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4aa7777/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedConversationsTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedConversationsTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedConversationsTest.java new file mode 100644 index 0000000..e727df6 --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/scope/conversation/ImplicitlyGroupedConversationsTest.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.deltaspike.test.core.api.scope.conversation; + +import org.apache.deltaspike.core.spi.scope.conversation.GroupedConversationManager; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; +import org.apache.deltaspike.test.category.SeCategory; +import org.apache.deltaspike.test.util.ArchiveUtils; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +@RunWith(Arquillian.class) +@Category(SeCategory.class) +public class ImplicitlyGroupedConversationsTest +{ + @Deployment + public static WebArchive deploy() + { + String simpleName = ImplicitlyGroupedConversationsTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") + .addPackage(ImplicitlyGroupedConversationsTest.class.getPackage().getName()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + + return ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Inject + private WindowContext windowContext; + + @Inject + private ImplicitlyGroupedBean implicitlyGroupedBean; + + @Inject + private GroupedConversationManager conversationManager; + + @Test + public void parallelConversationsTest() + { + windowContext.activateWindow("w1"); + + implicitlyGroupedBean.setValue("x"); + Assert.assertEquals("x", implicitlyGroupedBean.getValue()); + + windowContext.activateWindow("w2"); + + Assert.assertNull(implicitlyGroupedBean.getValue()); + + implicitlyGroupedBean.setValue("y"); + Assert.assertEquals("y", implicitlyGroupedBean.getValue()); + + windowContext.activateWindow("w1"); + Assert.assertEquals("x", implicitlyGroupedBean.getValue()); + } + + @Test + public void immediatelyClosedConversationTest() + { + windowContext.activateWindow("w1"); + + implicitlyGroupedBean.setValue("x"); + Assert.assertEquals("x", implicitlyGroupedBean.getValue()); + + implicitlyGroupedBean.done(); + + Assert.assertNull(implicitlyGroupedBean.getValue()); + } + + @Test + public void immediatelyClosedConversationViaConversationManagerTest() + { + windowContext.activateWindow("w1"); + + implicitlyGroupedBean.setValue("x"); + Assert.assertEquals("x", implicitlyGroupedBean.getValue()); + + this.conversationManager.closeConversation(ImplicitlyGroupedBean.class); + + Assert.assertNull(implicitlyGroupedBean.getValue()); + + + implicitlyGroupedBean.setValue("y"); + Assert.assertEquals("y", implicitlyGroupedBean.getValue()); + + this.conversationManager.closeConversationGroup(ImplicitlyGroupedBean.class); + + Assert.assertNull(implicitlyGroupedBean.getValue()); + } + + @Test + public void immediatelyClosedConversationsTest() + { + windowContext.activateWindow("w1"); + + implicitlyGroupedBean.setValue("x"); + Assert.assertEquals("x", implicitlyGroupedBean.getValue()); + + this.conversationManager.closeConversations(); + + Assert.assertNull(implicitlyGroupedBean.getValue()); + } + + @Test + public void immediatelyClosedConversationsViaWindowContextTest() + { + windowContext.activateWindow("w1"); + + implicitlyGroupedBean.setValue("x"); + Assert.assertEquals("x", implicitlyGroupedBean.getValue()); + + Assert.assertTrue(this.windowContext.closeWindow("w1")); + windowContext.activateWindow("w1"); + + Assert.assertNull(implicitlyGroupedBean.getValue()); + } +}
