tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1576927 - /tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/StatefulConversationScopedTOMEE1138Test.java
Date Wed, 12 Mar 2014 21:33:55 GMT
Author: rmannibucau
Date: Wed Mar 12 21:33:54 2014
New Revision: 1576927

URL: http://svn.apache.org/r1576927
Log:
TOMEE-1138 adding a test on conversationscoped beans

Added:
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/StatefulConversationScopedTOMEE1138Test.java

Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/StatefulConversationScopedTOMEE1138Test.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/StatefulConversationScopedTOMEE1138Test.java?rev=1576927&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/StatefulConversationScopedTOMEE1138Test.java
(added)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/cdi/StatefulConversationScopedTOMEE1138Test.java
Wed Mar 12 21:33:54 2014
@@ -0,0 +1,154 @@
+/**
+ * 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.openejb.cdi;
+
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Module;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.spi.ConversationService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Stateful;
+import javax.el.BeanELResolver;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(ApplicationComposer.class)
+public class StatefulConversationScopedTOMEE1138Test {
+    @Module
+    public Class<?>[] beans() {
+        return new Class<?>[] { MyConversation.class };
+    }
+
+    @Inject
+    private BeanManager bm;
+
+    @Inject
+    private MyConversation conversation;
+
+    @Inject
+    @Named("myConversation")
+    private MyConversation conversationByName;
+
+    @Before
+    public void startConversation() {
+        final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+        webBeansContext.registerService(ConversationService.class, new ConversationService()
{
+            @Override
+            public String getConversationId() {
+                return "conversation-test";
+            }
+
+            @Override
+            public String getConversationSessionId() {
+                return "session-test";
+            }
+        });
+        webBeansContext.getService(ContextsService.class).startContext(ConversationScoped.class,
null);
+    }
+
+    @After
+    public void stopConversation() {
+        WebBeansContext.currentInstance().getService(ContextsService.class).endContext(ConversationScoped.class,
null);
+    }
+
+    private static void doTest(final MyConversation conversation) {
+        assertEquals("John", conversation.getName());
+        conversation.setName("foo1");
+        assertEquals("foo1", conversation.getName());
+    }
+
+    @Test
+    public void injectionByType() {
+        assertNotNull(conversation);
+        doTest(conversation);
+    }
+
+    @Test
+    public void injectionByName() {
+        assertNotNull(conversationByName);
+        doTest(conversationByName);
+    }
+
+    @Test
+    public void injectionByNameLookup() {
+        final MyConversation conv = MyConversation.class.cast(bm.getReference(bm.resolve(bm.getBeans("myConversation")),
Object.class, null));
+        doTest(conv);
+    }
+
+    @Test
+    public void el() {
+        final BeanELResolver elResolver = new BeanELResolver();
+        assertEquals("John", elResolver.getValue(new ELContext() {
+            @Override
+            public ELResolver getELResolver() {
+                return elResolver;
+            }
+
+            @Override
+            public FunctionMapper getFunctionMapper() {
+                return new FunctionMapper() {
+                    @Override
+                    public Method resolveFunction(final String prefix, final String localName)
{
+                        return null;
+                    }
+                };
+            }
+
+            @Override
+            public VariableMapper getVariableMapper() {
+                return new VariableMapper() {
+                    @Override
+                    public ValueExpression resolveVariable(final String variable) {
+                        return null;
+                    }
+
+                    @Override
+                    public ValueExpression setVariable(String variable, ValueExpression expression)
{
+                        return null;
+                    }
+                };
+            }
+        }, conversationByName, "name"));
+    }
+
+    @Named
+    @Stateful
+    @ConversationScoped
+    public static class MyConversation implements Serializable {
+        private String name = "John";
+
+        public String getName() { return name; }
+        public void setName(final String name) { this.name = name; }
+    }
+}



Mime
View raw message