You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/11/06 14:56:22 UTC
svn commit: r1406139 -
/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorMultipleDelegateCallsTest.java
Author: rmannibucau
Date: Tue Nov 6 13:56:22 2012
New Revision: 1406139
URL: http://svn.apache.org/viewvc?rev=1406139&view=rev
Log:
adding broken cdi decorator test - work in progress
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorMultipleDelegateCallsTest.java
- copied, changed from r1405862, openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorTest.java
Copied: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorMultipleDelegateCallsTest.java (from r1405862, openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorMultipleDelegateCallsTest.java?p2=openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorMultipleDelegateCallsTest.java&p1=openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorTest.java&r1=1405862&r2=1406139&rev=1406139&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/cdi/CdiDecoratorMultipleDelegateCallsTest.java Tue Nov 6 13:56:22 2012
@@ -16,283 +16,72 @@
*/
package org.apache.openejb.cdi;
-import junit.framework.TestCase;
-import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
-import org.apache.openejb.assembler.classic.SecurityServiceInfo;
-import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
-import org.apache.openejb.assembler.classic.TransactionServiceInfo;
-import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.core.ivm.naming.InitContextFactory;
import org.apache.openejb.jee.Beans;
import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.StatelessBean;
-import org.junit.Before;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Classes;
+import org.apache.openejb.junit.Module;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
-import javax.annotation.PostConstruct;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.ejb.Local;
-import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Inject;
-import javax.inject.Qualifier;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InterceptorBinding;
-import javax.interceptor.Interceptors;
-import javax.interceptor.InvocationContext;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-@SuppressWarnings("deprecation")
-public class CdiDecoratorTest extends TestCase {
-
- private InitialContext ctx;
-
- @Before
- public void setUp() throws Exception {
-
- ConfigurationFactory config = new ConfigurationFactory();
- Assembler assembler = new Assembler();
-
- assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
- assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
- assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
-
- assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
-
- EjbJar ejbJar = new EjbJar();
- ejbJar.addEnterpriseBean(new StatelessBean("HelloOne", RedBean.class));
- ejbJar.addEnterpriseBean(new StatelessBean("HelloTwo", RedBean.class));
- ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
-
- Beans beans = new Beans();
- beans.addInterceptor(OrangeCdiInterceptor.class);
- beans.addDecorator(OrangeOneDecorator.class);
- beans.addDecorator(OrangeTwoDecorator.class);
- beans.addManagedClass(YellowBean.class);
-
- EjbModule module = new EjbModule(ejbJar);
- module.setBeans(beans);
-
- assembler.createApplication(config.configureApplication(module));
-
- Properties properties = new Properties(System.getProperties());
- properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
- ctx = new InitialContext(properties);
- }
-
- public void testSimple() {
- try {
-
- Color color = (Color) ctx.lookup("HelloOneLocal");
- color.hello();
-
- for (String call : callback) {
- System.out.println("callback = " + call);
- }
-
- for (String call : businessMethod) {
- System.out.println("call = " + call);
- }
-
-
- assertTrue(YellowBean.RUN);
- assertTrue(OrangeBean.RUN);
- assertTrue(RedBean.RUN);
- assertTrue(OrangeCdiInterceptor.RUN);
- assertTrue(OrangeOneDecorator.RUN);
-
- } catch (NamingException e) {
- e.printStackTrace();
- }
- }
-
- private static final List<String> businessMethod = new ArrayList<String>();
- private static final List<String> callback = new ArrayList<String>();
-
- @Local
- public static interface Color {
- public void hello();
- }
-
- @InterceptorBinding
- @Target(value = {ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- public static @interface OrangeInterceptorBinding {
-
- }
-
- @Qualifier
- @Retention(RetentionPolicy.RUNTIME)
- @Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
- public static @interface OrangeQualifier {
-
- }
-
- @Stateless
- @Interceptors(RedInterceptor.class)
- public static class RedBean implements Color {
-
- @Inject
- private YellowBean cdiBean;
-
- public static boolean RUN = false;
-
- @PostConstruct
- public void postConstruct() {
- callback.add(this.getClass().getSimpleName());
- }
-
- @Override
- public void hello() {
- businessMethod.add(this.getClass().getSimpleName());
- RUN = true;
- System.out.println("In EJB : " + RedBean.class.getName());
- cdiBean.sayHelloWorld();
- }
- }
-
- public static class RedInterceptor {
- @PostConstruct
- public void postConstruct(InvocationContext ctx) throws Exception {
- callback.add(this.getClass().getSimpleName());
- ctx.proceed();
- }
-
- @AroundInvoke
- public Object aroundInvoke(InvocationContext ctx) throws Exception {
- businessMethod.add(this.getClass().getSimpleName());
- return ctx.proceed();
- }
-
- }
+import javax.inject.Named;
- public static class YellowBean {
+import static org.junit.Assert.assertTrue;
- @Inject
- @OrangeQualifier
- private Color colorEjb;
-
- public static boolean RUN = false;
-
- @PostConstruct
- public void postConstruct() {
- callback.add(this.getClass().getSimpleName());
+@RunWith(ApplicationComposer.class)
+public class CdiDecoratorMultipleDelegateCallsTest {
+ //@Local
+ public static interface Service {
+ String touch();
+ }
+
+ //@Stateless
+ @Named("service")
+ public static class ServiceImpl implements Service {
+ public String touch() {
+ return getClass().getName();
}
- public void sayHelloWorld() {
- businessMethod.add(this.getClass().getSimpleName());
- RUN = true;
- System.out.println("In Managed Bean : " + YellowBean.class.getName());
- this.colorEjb.hello();
- }
- }
-
- @Decorator
- public static class OrangeOneDecorator implements Color {
-
- public static boolean RUN = false;
-
- @Inject
- @Delegate
- @OrangeQualifier
- private Color color;
-
- @Override
- public void hello() {
- businessMethod.add(this.getClass().getSimpleName());
- System.out.println("In CDI Style Decorator : " + OrangeOneDecorator.class.getName());
- RUN = true;
- this.color.hello();
- }
}
@Decorator
- public static class OrangeTwoDecorator implements Color {
-
- public static boolean RUN = false;
+ public static class ServiceDecorator implements Service {
@Inject
@Delegate
- @OrangeQualifier
- private Color color;
+ private Service service;
- @Override
- public void hello() {
- businessMethod.add(this.getClass().getSimpleName());
- System.out.println("In CDI Style Decorator : " + OrangeOneDecorator.class.getName());
- RUN = true;
- this.color.hello();
+ public String touch() { // org.apache.webbeans.decorator.DelegateHandler uses ejbContext.proceed() so that's not possible
+ service.touch();
+ return service.touch();
}
- }
-
- @Interceptor
- @OrangeInterceptorBinding
- public static class OrangeCdiInterceptor {
-
- public static boolean RUN = false;
-
- @PostConstruct
- public void postConstruct(InvocationContext ctx) throws Exception {
- callback.add(this.getClass().getSimpleName());
- ctx.proceed();
- }
-
- @AroundInvoke
- public Object aroundInvoke(InvocationContext ctx) throws Exception {
- businessMethod.add(this.getClass().getSimpleName());
- System.out.println("In CDI Style Interceptor : " + OrangeCdiInterceptor.class.getName());
- RUN = true;
- return ctx.proceed();
- }
}
- @LocalBean
- @OrangeQualifier
- @OrangeInterceptorBinding
- @Interceptors(OrangeEjbInterceptor.class)
- public static class OrangeBean implements Color {
-
- public static boolean RUN = false;
-
- @PostConstruct
- public void postConstruct() {
- callback.add(this.getClass().getSimpleName());
- }
+ @Module
+ @Classes({ ServiceImpl.class })
+ public EjbModule classes() {
+ final Beans beans = new Beans();
+ beans.addDecorator(ServiceDecorator.class);
- @Override
- public void hello() {
- businessMethod.add(this.getClass().getSimpleName());
- System.out.println("In EJB : " + OrangeBean.class.getName());
- RUN = true;
- }
+ final EjbModule jar = new EjbModule(new EjbJar());
+ jar.setBeans(beans);
+ return jar;
}
- public static class OrangeEjbInterceptor {
-
- @PostConstruct
- public void postConstruct(InvocationContext ctx) throws Exception {
- callback.add(this.getClass().getSimpleName());
- ctx.proceed();
- }
-
- @AroundInvoke
- public Object aroundInvoke(InvocationContext ctx) throws Exception {
- businessMethod.add(this.getClass().getSimpleName());
- return ctx.proceed();
- }
+ @Inject
+ private Service service;
+ @Test
+ @Ignore("currently broken")
+ public void check() {
+ assertTrue(service.touch().startsWith("org.apache.openejb.cdi.CdiDecoratorMultipleDelegateCallsTest$ServiceImpl"));
}
}