http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java new file mode 100644 index 0000000..f19eeca --- /dev/null +++ b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java @@ -0,0 +1,218 @@ +/* + * 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.partialbean.impl.proxy; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import javax.enterprise.inject.Typed; +import org.apache.deltaspike.core.util.ClassUtils; + +@Typed +public abstract class PartialBeanProxyFactory +{ + private static final String CLASSNAME_SUFFIX = "$$DSPartialBeanProxy"; + + private PartialBeanProxyFactory() + { + // prevent instantiation + } + + public static <T> Class<T> getProxyClass(Class<T> targetClass, + Class<? extends InvocationHandler> invocationHandlerClass) + { + Class<T> proxyClass = ClassUtils.tryToLoadClassForName(constructProxyClassName(targetClass), targetClass); + if (proxyClass == null) + { + proxyClass = createProxyClass(targetClass.getClassLoader(), targetClass, invocationHandlerClass); + } + + return proxyClass; + } + + private static synchronized <T> Class<T> createProxyClass(ClassLoader classLoader, Class<T> targetClass, + Class<? extends InvocationHandler> invocationHandlerClass) + { + Class<T> proxyClass = ClassUtils.tryToLoadClassForName(constructProxyClassName(targetClass), targetClass); + if (proxyClass == null) + { + ArrayList<Method> redirectMethods = new ArrayList<Method>(); + ArrayList<Method> interceptionMethods = new ArrayList<Method>(); + collectMethods(targetClass, redirectMethods, interceptionMethods); + + proxyClass = AsmProxyClassGenerator.generateProxyClass(classLoader, + targetClass, + invocationHandlerClass, + CLASSNAME_SUFFIX, + redirectMethods.toArray(new Method[redirectMethods.size()]), + interceptionMethods.toArray(new Method[interceptionMethods.size()])); + } + + return proxyClass; + } + + private static String constructProxyClassName(Class<?> clazz) + { + return clazz.getCanonicalName() + CLASSNAME_SUFFIX; + } + + /** + * Checks if the given class is DS proxy class. + * + * @param clazz + * @return + */ + public static boolean isProxyClass(Class<?> clazz) + { + return clazz.getName().endsWith(CLASSNAME_SUFFIX); + } + + private static void collectMethods(Class<?> clazz, + ArrayList<Method> redirectMethods, + ArrayList<Method> interceptionMethods) + { + List<Method> methods = new ArrayList<Method>(); + for (Method method : clazz.getDeclaredMethods()) + { + if (!ignoreMethod(method, methods)) + { + methods.add(method); + } + } + for (Method method : clazz.getMethods()) + { + if (!ignoreMethod(method, methods)) + { + methods.add(method); + } + } + + // collect methods from abstract super classes... + Class currentSuperClass = clazz.getSuperclass(); + while (currentSuperClass != null) + { + if (Modifier.isAbstract(currentSuperClass.getModifiers())) + { + for (Method method : currentSuperClass.getDeclaredMethods()) + { + if (!ignoreMethod(method, methods)) + { + methods.add(method); + } + } + for (Method method : currentSuperClass.getMethods()) + { + if (!ignoreMethod(method, methods)) + { + methods.add(method); + } + } + } + currentSuperClass = currentSuperClass.getSuperclass(); + } + + // sort out somewhere implemented abstract methods + Class currentClass = clazz; + while (currentClass != null) + { + Iterator<Method> methodIterator = methods.iterator(); + while (methodIterator.hasNext()) + { + Method method = methodIterator.next(); + if (Modifier.isAbstract(method.getModifiers())) + { + try + { + Method foundMethod = currentClass.getMethod(method.getName(), method.getParameterTypes()); + // if method is implementent in the current class -> remove it + if (foundMethod != null && !Modifier.isAbstract(foundMethod.getModifiers())) + { + methodIterator.remove(); + } + } + catch (Exception e) + { + // ignore... + } + } + } + + currentClass = currentClass.getSuperclass(); + } + + Iterator<Method> it = methods.iterator(); + while (it.hasNext()) + { + Method method = it.next(); + + if (Modifier.isAbstract(method.getModifiers())) + { + redirectMethods.add(method); + } + else if (Modifier.isPublic(method.getModifiers()) && !Modifier.isFinal(method.getModifiers())) + { + interceptionMethods.add(method); + } + } + + } + + private static boolean ignoreMethod(Method method, List<Method> methods) + { + // we have no interest in generics bridge methods + if (method.isBridge()) + { + return true; + } + + // we do not proxy finalize() + if ("finalize".equals(method.getName())) + { + return true; + } + + // same method... + if (methods.contains(method)) + { + return true; + } + + // check if a method with the same signature is already available + for (Method currentMethod : methods) + { + if (hasSameSignature(currentMethod, method)) + { + return true; + } + } + + return false; + } + + private static boolean hasSameSignature(Method a, Method b) + { + return a.getName().equals(b.getName()) + && a.getReturnType().equals(b.getReturnType()) + && Arrays.equals(a.getParameterTypes(), b.getParameterTypes()); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptor.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptor.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptor.java index 89930a3..b9fc7b8 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptor.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptor.java @@ -23,11 +23,12 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; @Retention(RUNTIME) -@Target(TYPE) +@Target({ TYPE, METHOD }) @InterceptorBinding public @interface CustomInterceptor { -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorImpl.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorImpl.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorImpl.java index 206427e..b2f2a81 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorImpl.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorImpl.java @@ -18,32 +18,22 @@ */ package org.apache.deltaspike.test.core.api.partialbean.shared; -import org.apache.deltaspike.core.util.ClassUtils; - +import java.io.Serializable; +import javax.inject.Inject; import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; -import java.io.Serializable; @Interceptor @CustomInterceptor public class CustomInterceptorImpl implements Serializable { + @Inject private CustomInterceptorState interceptionStateHolder; + @AroundInvoke public Object interceptIt(InvocationContext invocationContext) throws Exception { - //interceptor gets enabled globally -> restrict it the the use-case which contains the test for it - if (ClassUtils.tryToLoadClassForName( - "org.apache.deltaspike.test.core.api.partialbean.uc007.PartialBean") != null) - { - Object target = invocationContext.getTarget(); - - if (target instanceof TestInterceptorAware) - { - ((TestInterceptorAware)target).setIntercepted(true); - } - } - + interceptionStateHolder.setIntercepted(true); return invocationContext.proceed(); } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorState.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorState.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorState.java new file mode 100644 index 0000000..7fad111 --- /dev/null +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/shared/CustomInterceptorState.java @@ -0,0 +1,37 @@ +/* + * 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.partialbean.shared; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class CustomInterceptorState +{ + private boolean intercepted; + + public boolean isIntercepted() + { + return intercepted; + } + + public void setIntercepted(boolean intercepted) + { + this.intercepted = intercepted; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBean.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBean.java index 72ba7e9..0bbf7d4 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBean.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBean.java @@ -1,30 +1,30 @@ -/* - * 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.partialbean.uc001; - -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; - -import javax.enterprise.context.RequestScoped; - -@TestPartialBeanBinding -@RequestScoped -public interface PartialBean -{ - String getResult(); +/* + * 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.partialbean.uc001; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; + +import javax.enterprise.context.RequestScoped; + +@TestPartialBeanBinding +@RequestScoped +public interface PartialBean +{ + String getResult(); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceEarFileTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceEarFileTest.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceEarFileTest.java index 89b86ca..fbf9cfd 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceEarFileTest.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceEarFileTest.java @@ -1,43 +1,43 @@ -/* - * 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.partialbean.uc001; - -import org.apache.deltaspike.test.category.EnterpriseArchiveProfileCategory; -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.spec.EnterpriseArchive; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - -@RunWith(Arquillian.class) -@Category(EnterpriseArchiveProfileCategory.class) -public class PartialBeanAsInterfaceEarFileTest extends PartialBeanAsInterfaceTest -{ - @Deployment - public static EnterpriseArchive deployEar() - { - //workaround for tomee - the ear-file needs to have the same name as the war-file - String simpleName = PartialBeanAsInterfaceWarFileTest.class.getSimpleName(); - String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); - - return ShrinkWrap.create(EnterpriseArchive.class, archiveName + ".ear") - .addAsModule(PartialBeanAsInterfaceWarFileTest.deploy()); - } -} +/* + * 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.partialbean.uc001; + +import org.apache.deltaspike.test.category.EnterpriseArchiveProfileCategory; +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.spec.EnterpriseArchive; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +@Category(EnterpriseArchiveProfileCategory.class) +public class PartialBeanAsInterfaceEarFileTest extends PartialBeanAsInterfaceTest +{ + @Deployment + public static EnterpriseArchive deployEar() + { + //workaround for tomee - the ear-file needs to have the same name as the war-file + String simpleName = PartialBeanAsInterfaceWarFileTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + return ShrinkWrap.create(EnterpriseArchive.class, archiveName + ".ear") + .addAsModule(PartialBeanAsInterfaceWarFileTest.deploy()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceTest.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceTest.java index 8e92182..2b54bcb 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceTest.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/PartialBeanAsInterfaceTest.java @@ -1,40 +1,40 @@ -/* - * 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.partialbean.uc001; - -import org.junit.Assert; -import org.junit.Test; - -import javax.inject.Inject; - -public abstract class PartialBeanAsInterfaceTest -{ - @Inject - private PartialBean partialBean; - - @Test - public void testPartialBeanAsInterface() throws Exception - { - String result = this.partialBean.getResult(); - - Assert.assertEquals("partial-test-false", result); - - //TODO test pre-destroy callback - } -} +/* + * 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.partialbean.uc001; + +import org.junit.Assert; +import org.junit.Test; + +import javax.inject.Inject; + +public abstract class PartialBeanAsInterfaceTest +{ + @Inject + private PartialBean partialBean; + + @Test + public void testPartialBeanAsInterface() throws Exception + { + String result = this.partialBean.getResult(); + + Assert.assertEquals("partial-test-false", result); + + //TODO test pre-destroy callback + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java index 1d02907..29d3c7f 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc001/TestPartialBeanHandler.java @@ -1,64 +1,63 @@ -/* - * 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.partialbean.uc001; - -import org.apache.deltaspike.test.core.api.partialbean.shared.CustomInterceptor; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.Dependent; -import javax.inject.Inject; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -@TestPartialBeanBinding -@Dependent //normal-scopes are possible as well -public class TestPartialBeanHandler implements InvocationHandler, /*just needed for testing interceptors: */TestInterceptorAware -{ - @Inject - private TestBean testBean; - - private String value; - private boolean intercepted; - - @PostConstruct - protected void onCreate() - { - this.value = "partial"; - } - - @PreDestroy - protected void onDestroy() - { - //TODO check in a test - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - return this.value + "-" + this.testBean.getValue() + "-" + this.intercepted; - } - - public void setIntercepted(boolean intercepted) - { - this.intercepted = intercepted; - } -} +/* + * 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.partialbean.uc001; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +@TestPartialBeanBinding +@Dependent //normal-scopes are possible as well +public class TestPartialBeanHandler implements InvocationHandler, /*just needed for testing interceptors: */TestInterceptorAware +{ + @Inject + private TestBean testBean; + + private String value; + private boolean intercepted; + + @PostConstruct + protected void onCreate() + { + this.value = "partial"; + } + + @PreDestroy + protected void onDestroy() + { + //TODO check in a test + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable + { + return this.value + "-" + this.testBean.getValue() + "-" + this.intercepted; + } + + public void setIntercepted(boolean intercepted) + { + this.intercepted = intercepted; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBean.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBean.java index a9db392..ca39f57 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBean.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBean.java @@ -1,56 +1,56 @@ -/* - * 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.partialbean.uc002; - -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -@TestPartialBeanBinding -@RequestScoped -public abstract class PartialBean -{ - @Inject - private TestBean testBean; - - private String value; - - public abstract String getResult(); - - @PostConstruct - protected void onCreate() - { - this.value = "manual"; - } - - @PreDestroy - protected void onDestroy() - { - //TODO check in a test - } - - public String getManualResult() - { - return this.value + "-" + this.testBean.getValue(); - } -} \ No newline at end of file +/* + * 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.partialbean.uc002; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +@TestPartialBeanBinding +@RequestScoped +public abstract class PartialBean +{ + @Inject + private TestBean testBean; + + private String value; + + public abstract String getResult(String value); + + @PostConstruct + protected void onCreate() + { + this.value = "manual"; + } + + @PreDestroy + protected void onDestroy() + { + //TODO check in a test + } + + public String getManualResult() + { + return this.value + "-" + this.testBean.getValue(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBeanAsAbstractClassTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBeanAsAbstractClassTest.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBeanAsAbstractClassTest.java index 5fa167f..6fbad0b 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBeanAsAbstractClassTest.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc002/PartialBeanAsAbstractClassTest.java @@ -1,73 +1,73 @@ -/* - * 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.partialbean.uc002; - -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; -import org.apache.deltaspike.test.core.api.partialbean.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.runner.RunWith; - -import javax.inject.Inject; - -@RunWith(Arquillian.class) -public class PartialBeanAsAbstractClassTest -{ - @Inject - private PartialBean partialBean; - - @Deployment - public static WebArchive war() - { - String simpleName = PartialBeanAsAbstractClassTest.class.getSimpleName(); - String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); - - JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") - .addPackage(PartialBeanAsAbstractClassTest.class.getPackage()) - .addPackage(TestPartialBeanBinding.class.getPackage()) - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - - WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war") - .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) - .addAsLibraries(testJar) - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); - - return webArchive; - } - - @Test - public void testPartialBeanAsAbstractClass() throws Exception - { - String result = this.partialBean.getResult(); - - Assert.assertEquals("partial-test-false", result); - - result = this.partialBean.getManualResult(); - - Assert.assertEquals("manual-test", result); - - //TODO test pre-destroy callback - } -} +/* + * 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.partialbean.uc002; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; +import org.apache.deltaspike.test.core.api.partialbean.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.runner.RunWith; + +import javax.inject.Inject; + +@RunWith(Arquillian.class) +public class PartialBeanAsAbstractClassTest +{ + @Inject + private PartialBean partialBean; + + @Deployment + public static WebArchive war() + { + String simpleName = PartialBeanAsAbstractClassTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") + .addPackage(PartialBeanAsAbstractClassTest.class.getPackage()) + .addPackage(TestPartialBeanBinding.class.getPackage()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + + WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + + return webArchive; + } + + @Test + public void testPartialBeanAsAbstractClass() throws Exception + { + String result = this.partialBean.getResult("test"); + + Assert.assertEquals("partial-test-false", result); + + result = this.partialBean.getManualResult(); + + Assert.assertEquals("manual-test", result); + + //TODO test pre-destroy callback + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBean.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBean.java index 898d6d1..42e77a7 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBean.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBean.java @@ -1,66 +1,29 @@ -/* - * 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.partialbean.uc003; - -import org.apache.deltaspike.test.core.api.partialbean.shared.CustomInterceptor; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -@TestPartialBeanBinding -@RequestScoped -@CustomInterceptor //doesn't work currently -public abstract class PartialBean implements /*just needed for testing interceptors: */ TestInterceptorAware -{ - @Inject - private TestBean testBean; - - private String value; - private boolean intercepted; - - public abstract String getResult(); - - @PostConstruct - protected void onCreate() - { - this.value = "manual"; - } - - @PreDestroy - protected void onDestroy() - { - //TODO check in a test - } - - public String getManualResult() - { - return this.value + "-" + this.testBean.getValue() + "-" + this.intercepted; - } - - @Override - public void setIntercepted(boolean intercepted) - { - this.intercepted = intercepted; - } +/* + * 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.partialbean.uc003; + +import javax.enterprise.context.ApplicationScoped; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; + +@TestPartialBeanBinding +@ApplicationScoped +public interface PartialBean extends SuperInterface<Object>, SuperInterface2<Object> +{ + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanAsAbstractClassWithInterceptorTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanAsAbstractClassWithInterceptorTest.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanAsAbstractClassWithInterceptorTest.java deleted file mode 100644 index 6c44830..0000000 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanAsAbstractClassWithInterceptorTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.partialbean.uc003; - -import org.apache.deltaspike.core.api.provider.BeanProvider; -import org.apache.deltaspike.test.category.SeCategory; -import org.apache.deltaspike.test.core.api.partialbean.shared.CustomInterceptorImpl; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; -import org.apache.deltaspike.test.core.api.partialbean.util.ArchiveUtils; -import org.apache.deltaspike.test.utils.CdiContainerUnderTest; -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.Asset; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - - -@RunWith(Arquillian.class) -@Category(SeCategory.class) //TODO use different category (only new versions of weld) -public class PartialBeanAsAbstractClassWithInterceptorTest -{ - public static final String CONTAINER_WELD_2_0_0 = "weld-2\\.0\\.0\\..*"; - - @Deployment - public static WebArchive war() - { - Asset beansXml = new StringAsset( - "<beans><interceptors><class>" + - CustomInterceptorImpl.class.getName() + - "</class></interceptors></beans>" - ); - - String simpleName = PartialBeanAsAbstractClassWithInterceptorTest.class.getSimpleName(); - String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); - - //don't create a completely empty web-archive - if (CdiContainerUnderTest.is(CONTAINER_WELD_2_0_0)) - { - return ShrinkWrap.create(WebArchive.class, archiveName + ".war") - .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()); - } - - JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") - .addPackage(PartialBeanAsAbstractClassWithInterceptorTest.class.getPackage()) - .addPackage(TestPartialBeanBinding.class.getPackage()) - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - - return ShrinkWrap.create(WebArchive.class, archiveName + ".war") - .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) - .addAsLibraries(testJar) - .addAsWebInfResource(beansXml, "beans.xml"); - } - - @Test - public void testPartialBeanAsAbstractClassWithInterceptor() throws Exception - { - // this test is known to not work under weld-2.0.0.Final and weld-2.0.0.SP1 - Assume.assumeTrue(!CdiContainerUnderTest.is(CONTAINER_WELD_2_0_0)); - - // we only inject an Instance as the proxy creation for the Bean itself - // would trigger a nasty bug in Weld-2.0.0 - PartialBean partialBean = BeanProvider.getContextualReference(PartialBean.class); - Assert.assertNotNull(partialBean); - - String result = partialBean.getResult(); - - Assert.assertEquals("partial-test-true", result); - - result = partialBean.getManualResult(); - - //"manual-test-true" would be the goal, but it isn't supported (for now) - Assert.assertEquals("manual-test-false", result); - - //TODO test pre-destroy callback - } -} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanTest.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanTest.java new file mode 100644 index 0000000..8125678 --- /dev/null +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/PartialBeanTest.java @@ -0,0 +1,70 @@ +/* + * 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.partialbean.uc003; + +import org.apache.deltaspike.core.api.provider.BeanProvider; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; +import org.apache.deltaspike.test.core.api.partialbean.util.ArchiveUtils; +import org.apache.deltaspike.test.utils.CdiContainerUnderTest; +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.Assume; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class PartialBeanTest +{ + private static final String CONTAINER_OWB_1_2_x_BEFORE_1_2_8 = "owb-1\\.2\\.[0-7]"; + private static final String CONTAINER_TOMEE_1_7_x = "tomee-1\\.7\\..*"; + + @Deployment + public static WebArchive war() + { + String simpleName = PartialBeanTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") + .addPackage(PartialBeanTest.class.getPackage()) + .addPackage(TestPartialBeanBinding.class.getPackage()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + + WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + + return webArchive; + } + + @Test + public void testPartialBeanWithApplicationScope() throws Exception + { + // this test is known to not work under OWB 1.2.0 till 1.2.7 - see OWB #1036 + Assume.assumeTrue(!CdiContainerUnderTest.is(CONTAINER_OWB_1_2_x_BEFORE_1_2_8) + && !CdiContainerUnderTest.is(CONTAINER_TOMEE_1_7_x)); + + PartialBean bean = BeanProvider.getContextualReference(PartialBean.class); + bean.test(this); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface.java new file mode 100644 index 0000000..dbfa156 --- /dev/null +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface.java @@ -0,0 +1,24 @@ +/* + * 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.partialbean.uc003; + +public interface SuperInterface<E> +{ + E test(E entity); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface2.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface2.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface2.java new file mode 100644 index 0000000..a271904 --- /dev/null +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/SuperInterface2.java @@ -0,0 +1,24 @@ +/* + * 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.partialbean.uc003; + +public interface SuperInterface2<E> +{ + E test(E entity); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/TestPartialBeanHandler.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/TestPartialBeanHandler.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/TestPartialBeanHandler.java index dc3f96b..aa5b3b5 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/TestPartialBeanHandler.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc003/TestPartialBeanHandler.java @@ -1,65 +1,63 @@ -/* - * 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.partialbean.uc003; - -import org.apache.deltaspike.test.core.api.partialbean.shared.CustomInterceptor; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.Dependent; -import javax.inject.Inject; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -@TestPartialBeanBinding -@CustomInterceptor //for uc003 -@Dependent //normal-scopes are possible as well -public class TestPartialBeanHandler implements InvocationHandler, /*just needed for testing interceptors: */TestInterceptorAware -{ - @Inject - private TestBean testBean; - - private String value; - private boolean intercepted; - - @PostConstruct - protected void onCreate() - { - this.value = "partial"; - } - - @PreDestroy - protected void onDestroy() - { - //TODO check in a test - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - return this.value + "-" + this.testBean.getValue() + "-" + this.intercepted; - } - - public void setIntercepted(boolean intercepted) - { - this.intercepted = intercepted; - } -} +/* + * 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.partialbean.uc003; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestBean; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestInterceptorAware; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +@TestPartialBeanBinding +@Dependent //normal-scopes are possible as well +public class TestPartialBeanHandler implements InvocationHandler, /*just needed for testing interceptors: */TestInterceptorAware +{ + @Inject + private TestBean testBean; + + private String value; + private boolean intercepted; + + @PostConstruct + protected void onCreate() + { + this.value = "partial"; + } + + @PreDestroy + protected void onDestroy() + { + //TODO check in a test + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable + { + return this.value + "-" + this.testBean.getValue() + "-" + this.intercepted; + } + + public void setIntercepted(boolean intercepted) + { + this.intercepted = intercepted; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/AbstractSuper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/AbstractSuper.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/AbstractSuper.java index 7136b5e..2fb9363 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/AbstractSuper.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/AbstractSuper.java @@ -1,24 +1,24 @@ -/* - * 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.partialbean.uc004; - -public abstract class AbstractSuper implements SuperInterface -{ - -} +/* + * 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.partialbean.uc004; + +public abstract class AbstractSuper implements SuperInterface +{ + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/ApplicationScopedPartialBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/ApplicationScopedPartialBean.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/ApplicationScopedPartialBean.java index 13474fc..9226526 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/ApplicationScopedPartialBean.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/ApplicationScopedPartialBean.java @@ -1,37 +1,37 @@ -/* - * 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.partialbean.uc004; - -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; - -import javax.enterprise.context.ApplicationScoped; - -@TestPartialBeanBinding -@ApplicationScoped -public abstract class ApplicationScopedPartialBean extends AbstractSuper -{ - private int count; - - public abstract String getResult(); - - public int getManualResult() - { - return count++; - } -} +/* + * 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.partialbean.uc004; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; + +import javax.enterprise.context.ApplicationScoped; + +@TestPartialBeanBinding +@ApplicationScoped +public abstract class ApplicationScopedPartialBean extends AbstractSuper +{ + private int count; + + public abstract String getResult(); + + public int getManualResult() + { + return count++; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/SuperInterface.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/SuperInterface.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/SuperInterface.java index be2acf0..5e6b9e5 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/SuperInterface.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc004/SuperInterface.java @@ -1,24 +1,24 @@ -/* - * 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.partialbean.uc004; - -public interface SuperInterface -{ - String willFail(); -} +/* + * 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.partialbean.uc004; + +public interface SuperInterface +{ + String willFail(); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/AbstractSuper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/AbstractSuper.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/AbstractSuper.java index e7dd2b9..0327f6e 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/AbstractSuper.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/AbstractSuper.java @@ -1,24 +1,24 @@ -/* - * 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.partialbean.uc005; - -public abstract class AbstractSuper -{ - abstract String willFail2(); -} +/* + * 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.partialbean.uc005; + +public abstract class AbstractSuper +{ + public abstract String willFail2(); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ApplicationScopedPartialBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ApplicationScopedPartialBean.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ApplicationScopedPartialBean.java index af64475..284bb3b 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ApplicationScopedPartialBean.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ApplicationScopedPartialBean.java @@ -1,37 +1,37 @@ -/* - * 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.partialbean.uc005; - -import javax.enterprise.context.ApplicationScoped; - -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; - -@TestPartialBeanBinding -@ApplicationScoped -public abstract class ApplicationScopedPartialBean extends AbstractSuper implements SuperInterface -{ - private int count; - - public abstract String getResult(); - - public int getManualResult() - { - return count++; - } -} +/* + * 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.partialbean.uc005; + +import javax.enterprise.context.ApplicationScoped; + +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; + +@TestPartialBeanBinding +@ApplicationScoped +public abstract class ApplicationScopedPartialBean extends AbstractSuper implements SuperInterface +{ + private int count; + + public abstract String getResult(); + + public int getManualResult() + { + return count++; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e90019fd/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ScopedPartialBeanTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ScopedPartialBeanTest.java b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ScopedPartialBeanTest.java index 02d9be0..3c052bc 100644 --- a/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ScopedPartialBeanTest.java +++ b/deltaspike/modules/partial-bean/impl/src/test/java/org/apache/deltaspike/test/core/api/partialbean/uc005/ScopedPartialBeanTest.java @@ -1,82 +1,84 @@ -/* - * 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.partialbean.uc005; - -import org.apache.deltaspike.core.api.provider.BeanProvider; -import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; -import org.apache.deltaspike.test.core.api.partialbean.util.ArchiveUtils; -import org.apache.deltaspike.test.utils.CdiContainerUnderTest; -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.Assume; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(Arquillian.class) -public class ScopedPartialBeanTest -{ - private static final String CONTAINER_OWB_1_2_x_BEFORE_1_2_8 = "owb-1\\.2\\.[0-7]"; - private static final String CONTAINER_TOMEE_1_7_x = "tomee-1\\.7\\..*"; - - @Deployment - public static WebArchive war() - { - String simpleName = ScopedPartialBeanTest.class.getSimpleName(); - String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); - - JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") - .addPackage(ScopedPartialBeanTest.class.getPackage()) - .addPackage(TestPartialBeanBinding.class.getPackage()) - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); - - WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war") - .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) - .addAsLibraries(testJar) - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); - - return webArchive; - } - - @Test - public void testPartialBeanWithApplicationScope() throws Exception - { - // this test is known to not work under OWB 1.2.0 till 1.2.7 - see OWB #1036 - Assume.assumeTrue(!CdiContainerUnderTest.is(CONTAINER_OWB_1_2_x_BEFORE_1_2_8) - && !CdiContainerUnderTest.is(CONTAINER_TOMEE_1_7_x)); - - String result = BeanProvider.getContextualReference(ApplicationScopedPartialBean.class).willFail(); - - Assert.assertEquals("partial-test-false", result); - - String result2 = BeanProvider.getContextualReference(ApplicationScopedPartialBean.class).willFail2(); - - Assert.assertEquals("partial-test-false", result2); - - int count = BeanProvider.getContextualReference(ApplicationScopedPartialBean.class).getManualResult(); - Assert.assertEquals(0, count); - - count = BeanProvider.getContextualReference(ApplicationScopedPartialBean.class).getManualResult(); - Assert.assertEquals(1, count); - } -} +/* + * 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.partialbean.uc005; + +import org.apache.deltaspike.core.api.provider.BeanProvider; +import org.apache.deltaspike.test.core.api.partialbean.shared.TestPartialBeanBinding; +import org.apache.deltaspike.test.core.api.partialbean.util.ArchiveUtils; +import org.apache.deltaspike.test.utils.CdiContainerUnderTest; +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.Assume; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class ScopedPartialBeanTest +{ + private static final String CONTAINER_OWB_1_2_x_BEFORE_1_2_8 = "owb-1\\.2\\.[0-7]"; + private static final String CONTAINER_TOMEE_1_7_x = "tomee-1\\.7\\..*"; + + @Deployment + public static WebArchive war() + { + String simpleName = ScopedPartialBeanTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") + .addPackage(ScopedPartialBeanTest.class.getPackage()) + .addPackage(TestPartialBeanBinding.class.getPackage()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + + WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + + return webArchive; + } + + @Test + public void testPartialBeanWithApplicationScope() throws Exception + { + // this test is known to not work under OWB 1.2.0 till 1.2.7 - see OWB #1036 + Assume.assumeTrue(!CdiContainerUnderTest.is(CONTAINER_OWB_1_2_x_BEFORE_1_2_8) + && !CdiContainerUnderTest.is(CONTAINER_TOMEE_1_7_x)); + + ApplicationScopedPartialBean bean = BeanProvider.getContextualReference(ApplicationScopedPartialBean.class); + + String result = bean.willFail(); + + Assert.assertEquals("partial-test-false", result); + + String result2 = bean.willFail2(); + + Assert.assertEquals("partial-test-false", result2); + + int count = bean.getManualResult(); + Assert.assertEquals(0, count); + + count = bean.getManualResult(); + Assert.assertEquals(1, count); + } +}
