Repository: deltaspike Updated Branches: refs/heads/master b625f25ed -> c4353b11e
DELTASPIKE-527 @Named support for type-safe messages (first draft) Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/c4353b11 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/c4353b11 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/c4353b11 Branch: refs/heads/master Commit: c4353b11e2753645397cfe55b12c5b3b3e7b6223 Parents: b625f25 Author: gpetracek <[email protected]> Authored: Mon Feb 24 14:01:03 2014 +0100 Committer: gpetracek <[email protected]> Committed: Mon Feb 24 14:18:07 2014 +0100 ---------------------------------------------------------------------- .../core/impl/message/MessageBundleContext.java | 49 +++++++ .../impl/message/MessageBundleExtension.java | 129 +++++++++++++++++++ .../message/MessageBundleInvocationHandler.java | 4 + .../NamedMessageBundleInvocationHandler.java | 96 ++++++++++++++ .../impl/message/NamedTypedMessageBundle.java | 41 ++++++ .../message/NamedTypedMessageBundleLiteral.java | 28 ++++ .../message/TypedMessageBundleProducer.java | 26 ++++ .../core/api/message/ElPickedUpMessages.java | 9 +- .../core/api/message/MinimalMessagesTest.java | 18 ++- .../api/message/TypedMessageWithCustomName.java | 35 +++++ .../customMinimalMessage_en.properties | 1 + 11 files changed, 427 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleContext.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleContext.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleContext.java new file mode 100644 index 0000000..85bf72a --- /dev/null +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleContext.java @@ -0,0 +1,49 @@ +/* + * 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.core.impl.message; + +import javax.enterprise.inject.Typed; +import javax.enterprise.inject.spi.Bean; + +@Typed() +abstract class MessageBundleContext +{ + private static final ThreadLocal<Bean> MESSAGE_BUNDLE_BEAN = new ThreadLocal<Bean>(); + + private MessageBundleContext() + { + // prevent instantiation + } + + static void setBean(Bean bean) + { + MESSAGE_BUNDLE_BEAN.set(bean); + } + + static void reset() + { + MESSAGE_BUNDLE_BEAN.set(null); + MESSAGE_BUNDLE_BEAN.remove(); + } + + static Bean getCurrentMessageBundleBean() + { + return MESSAGE_BUNDLE_BEAN.get(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java index 6835c84..47db06f 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleExtension.java @@ -18,14 +18,19 @@ */ package org.apache.deltaspike.core.impl.message; +import java.beans.Introspector; import java.io.Serializable; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Set; +import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.event.Observes; import javax.enterprise.inject.spi.AfterBeanDiscovery; import javax.enterprise.inject.spi.AfterDeploymentValidation; @@ -35,12 +40,17 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.BeforeBeanDiscovery; import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.PassivationCapable; import javax.enterprise.inject.spi.ProcessAnnotatedType; import javax.enterprise.inject.spi.ProcessProducerMethod; +import javax.inject.Named; +import org.apache.deltaspike.core.api.literal.AnyLiteral; import org.apache.deltaspike.core.api.message.Message; import org.apache.deltaspike.core.api.message.MessageBundle; import org.apache.deltaspike.core.api.message.MessageTemplate; +import org.apache.deltaspike.core.util.bean.ImmutableBeanWrapper; +import org.apache.deltaspike.core.util.bean.ImmutablePassivationCapableBeanWrapper; import org.apache.deltaspike.core.util.bean.WrappingBeanBuilder; import org.apache.deltaspike.core.spi.activation.Deactivatable; import org.apache.deltaspike.core.util.ClassDeactivationUtils; @@ -55,6 +65,9 @@ public class MessageBundleExtension implements Extension, Deactivatable { private final Collection<AnnotatedType<?>> messageBundleTypes = new HashSet<AnnotatedType<?>>(); private Bean<Object> bundleProducerBean; + private Bean<Object> namedBundleProducerBean; + private NamedTypedMessageBundle namedTypedMessageBundle = new NamedTypedMessageBundleLiteral(); + private boolean elSupportEnabled; private List<String> deploymentErrors = new ArrayList<String>(); @@ -64,6 +77,7 @@ public class MessageBundleExtension implements Extension, Deactivatable protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery) { isActivated = ClassDeactivationUtils.isActivated(getClass()); + elSupportEnabled = ClassDeactivationUtils.isActivated(NamedMessageBundleInvocationHandler.class); } @SuppressWarnings("UnusedDeclaration") @@ -176,6 +190,10 @@ public class MessageBundleExtension implements Extension, Deactivatable { bundleProducerBean = (Bean<Object>) bean; } + else if (method.isAnnotationPresent(NamedTypedMessageBundle.class)) + { + namedBundleProducerBean = (Bean<Object>)bean; + } } @SuppressWarnings("UnusedDeclaration") @@ -191,6 +209,15 @@ public class MessageBundleExtension implements Extension, Deactivatable for (AnnotatedType<?> type : messageBundleTypes) { abd.addBean(createMessageBundleBean(bundleProducerBean, type, beanManager)); + + if (this.elSupportEnabled) + { + Bean<?> namedBean = createNamedMessageBundleBean(namedBundleProducerBean, type, beanManager); + if (namedBean.getName() != null) + { + abd.addBean(namedBean); + } + } } } @@ -200,6 +227,12 @@ public class MessageBundleExtension implements Extension, Deactivatable { WrappingBeanBuilder<T> beanBuilder = new WrappingBeanBuilder<T>(delegate, beanManager) .readFromType(annotatedType); + + if (this.elSupportEnabled) + { + /*see namedBundleProducerBean - a producer without injection-point is needed*/ + beanBuilder.name(null); + } //X TODO re-visit type.getBaseType() in combination with #addQualifier beanBuilder.types(annotatedType.getJavaClass(), Object.class, Serializable.class); beanBuilder.passivationCapable(true); @@ -208,6 +241,102 @@ public class MessageBundleExtension implements Extension, Deactivatable return beanBuilder.create(); } + private <T> Bean<T> createNamedMessageBundleBean(Bean<Object> delegate, + AnnotatedType<T> annotatedType, + BeanManager beanManager) + { + WrappingBeanBuilder<T> beanBuilder = new WrappingBeanBuilder<T>(delegate, beanManager) { + @Override + public ImmutableBeanWrapper<T> create() + { + final ImmutableBeanWrapper<T> result = super.create(); + + String beanName = createBeanName(result.getTypes()); + + Set<Annotation> qualifiers = new HashSet<Annotation>(); + qualifiers.add(new AnyLiteral()); + qualifiers.add(namedTypedMessageBundle); + + if (isPassivationCapable()) + { + return new ImmutablePassivationCapableBeanWrapper<T>(result, + beanName, qualifiers, result.getScope(), + result.getStereotypes(), result.getTypes(), result.isAlternative(), + result.isNullable(), result.toString(), ((PassivationCapable)result).getId()) { + @Override + public T create(CreationalContext<T> creationalContext) + { + MessageBundleContext.setBean(result); + + try + { + return super.create(creationalContext); + } + finally + { + MessageBundleContext.reset(); + } + } + }; + } + else + { + return new ImmutableBeanWrapper<T>(result, + beanName, qualifiers, result.getScope(), + result.getStereotypes(), result.getTypes(), result.isAlternative(), + result.isNullable(), result.toString()) { + @Override + public T create(CreationalContext<T> creationalContext) + { + MessageBundleContext.setBean(result); + try + { + return super.create(creationalContext); + } + finally + { + MessageBundleContext.reset(); + } + } + }; + } + } + + private String createBeanName(Set<Type> types) + { + for (Object type : types) + { + if (type instanceof Class) + { + Named namedAnnotation = ((Class<?>) type).getAnnotation(Named.class); + + if (namedAnnotation == null) + { + continue; + } + + String result = namedAnnotation.value(); + if (!"".equals(result)) + { + return result; + } + return Introspector.decapitalize(((Class<?>) type).getSimpleName()); + } + } + return null; + } + }; + beanBuilder.readFromType(annotatedType); + + //X TODO re-visit type.getBaseType() in combination with #addQualifier + beanBuilder.types(annotatedType.getJavaClass(), Object.class, Serializable.class); + beanBuilder.passivationCapable(true); + beanBuilder.id("NamedMessageBundleBean#" + annotatedType.getJavaClass().getName()); + + return beanBuilder.create(); + } + + @SuppressWarnings("UnusedDeclaration") protected void cleanup(@Observes AfterDeploymentValidation afterDeploymentValidation) { http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java index 1b5ef59..d031b52 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java @@ -19,6 +19,7 @@ package org.apache.deltaspike.core.impl.message; import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Typed; import javax.inject.Inject; import java.io.Serializable; import java.lang.reflect.InvocationHandler; @@ -42,8 +43,11 @@ import org.apache.deltaspike.core.util.ClassUtils; * {@link org.apache.deltaspike.core.api.message.MessageBundle}s. */ @Dependent +@Typed(MessageBundleInvocationHandler.class) public class MessageBundleInvocationHandler implements InvocationHandler, Serializable { + private static final long serialVersionUID = -8980912335543392357L; + @Inject private MessageContext baseMessageContext = null; http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedMessageBundleInvocationHandler.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedMessageBundleInvocationHandler.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedMessageBundleInvocationHandler.java new file mode 100644 index 0000000..b2eec81 --- /dev/null +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedMessageBundleInvocationHandler.java @@ -0,0 +1,96 @@ +/* + * 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.core.impl.message; + +import org.apache.deltaspike.core.spi.activation.Deactivatable; + +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Typed; +import java.lang.reflect.Method; + +@Dependent +@Typed(NamedMessageBundleInvocationHandler.class) +public class NamedMessageBundleInvocationHandler extends MessageBundleInvocationHandler implements Deactivatable +{ + private static final long serialVersionUID = -7089857581799104783L; + + private Class<?> targetType; + + @Override + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable + { + int argCount = 0; + boolean nullValueFound = false; + String methodName = new RuntimeException().getStackTrace()[1].getMethodName(); + + if (args != null) + { + argCount = args.length; + } + + Class<?>[] paramTypes = new Class[argCount]; + + for (int i = 0; i < argCount; i++) + { + if (args[i] != null) + { + paramTypes[i] = args[i].getClass(); + } + else + { + nullValueFound = true; + } + } + + Method targetMethod = null; + + if (!nullValueFound) + { + targetMethod = this.targetType.getMethod(methodName, paramTypes); + } + else + { + //TODO improve it + for (Method currentMethod : this.targetType.getDeclaredMethods()) + { + if (currentMethod.getParameterTypes().length == argCount && currentMethod.getName().equals(methodName)) + { + if (targetMethod != null) + { + throw new IllegalStateException("Two methods with the same name and parameter-count found. " + + "It isn't possible to select the correct one, because one argument is 'null'."); + } + targetMethod = currentMethod; + } + } + } + + if (targetMethod == null) + { + throw new IllegalStateException(methodName + " can't be found on " + this.targetType); + } + + return super.invoke(proxy, targetMethod, args); + } + + public void setTargetType(Class<?> targetType) + { + this.targetType = targetType; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundle.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundle.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundle.java new file mode 100644 index 0000000..d7b2524 --- /dev/null +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundle.java @@ -0,0 +1,41 @@ +/* + * 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.core.impl.message; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Internal-qualifier used to identify the named typed message bundle producer + */ +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RUNTIME) +@Documented +@interface NamedTypedMessageBundle +{ +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundleLiteral.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundleLiteral.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundleLiteral.java new file mode 100644 index 0000000..3ef8606 --- /dev/null +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/NamedTypedMessageBundleLiteral.java @@ -0,0 +1,28 @@ +/* + * 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.core.impl.message; + +import javax.enterprise.util.AnnotationLiteral; + +class NamedTypedMessageBundleLiteral + extends AnnotationLiteral<NamedTypedMessageBundle> implements NamedTypedMessageBundle +{ + private static final long serialVersionUID = -8841990503456285744L; +} + http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java index fa8bc8a..5e33d94 100644 --- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java +++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java @@ -24,6 +24,7 @@ import java.lang.reflect.Proxy; import javax.enterprise.context.Dependent; import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.InjectionPoint; import org.apache.deltaspike.core.util.ClassUtils; @@ -36,6 +37,7 @@ import org.apache.deltaspike.core.util.ReflectionUtils; public class TypedMessageBundleProducer implements Serializable { private static final long serialVersionUID = -5077306523543940760L; + private static final String JAVA_PACKAGE = "java."; @Produces @Dependent @@ -46,6 +48,30 @@ public class TypedMessageBundleProducer implements Serializable return createMessageBundleProxy(ReflectionUtils.getRawType(injectionPoint.getType()), handler); } + @Produces + @Dependent + @NamedTypedMessageBundle + @SuppressWarnings("UnusedDeclaration") + Object produceTypedMessageBundle(NamedMessageBundleInvocationHandler handler) + { + Bean currentMessageBundleContextBean = MessageBundleContext.getCurrentMessageBundleBean(); + Class<?> type = extractCustomType(currentMessageBundleContextBean); + handler.setTargetType(type); + return createMessageBundleProxy(type, handler); + } + + private Class<?> extractCustomType(Bean currentMessageBundleBean) + { + for (Object type : currentMessageBundleBean.getTypes()) + { + if (type instanceof Class && !((Class)type).getName().startsWith(JAVA_PACKAGE)) + { + return (Class)type; + } + } + throw new IllegalStateException("no custom type found for bean: " + currentMessageBundleBean.toString()); + } + private <T> T createMessageBundleProxy(Class<T> type, MessageBundleInvocationHandler handler) { return type.cast(Proxy.newProxyInstance(ClassUtils.getClassLoader(null), http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/ElPickedUpMessages.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/ElPickedUpMessages.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/ElPickedUpMessages.java index 18ccfec..699641f 100644 --- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/ElPickedUpMessages.java +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/ElPickedUpMessages.java @@ -23,13 +23,7 @@ import javax.inject.Named; import org.apache.deltaspike.core.api.message.MessageBundle; import org.apache.deltaspike.core.api.message.MessageContextConfig; -/** - * This does NOT work atm because we internally - * rely on a producer method which has an InjectionPoint parameter. - * And in EL, you don't have any InjectionPoint... - * TODO for 0.4-incubating - */ -@Named("elPickedUpMessage") +@Named @MessageBundle @MessageContextConfig( localeResolver = FixedEnglishLocalResolver.class, @@ -37,4 +31,5 @@ import org.apache.deltaspike.core.api.message.MessageContextConfig; public interface ElPickedUpMessages { String sayHello(String name); + String text(); } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/MinimalMessagesTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/MinimalMessagesTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/MinimalMessagesTest.java index 2bd8e56..4338654 100644 --- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/MinimalMessagesTest.java +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/MinimalMessagesTest.java @@ -83,11 +83,25 @@ public class MinimalMessagesTest Assert.assertEquals("Hello DeltaSpike", customMinimalMessages.sayHello("DeltaSpike")); } - //X TODO @Test currently disabled as we currently rely on having an InjectionPoint internally... + @Test public void testExpressionLanguageIntegration() { - ElPickedUpMessages elMessage = (ElPickedUpMessages) BeanProvider.getContextualReference("elPickedUpMessage"); + ElPickedUpMessages elMessage = + (ElPickedUpMessages) BeanProvider.getContextualReference("elPickedUpMessages"); + Assert.assertNotNull(elMessage); + Assert.assertEquals("Hello DeltaSpike", elMessage.sayHello("DeltaSpike")); + Assert.assertEquals("Hello 'null'", elMessage.sayHello(null)); + Assert.assertEquals("Text", elMessage.text()); + } + + @Test + public void testExpressionLanguageIntegrationWithCustomName() + { + TypedMessageWithCustomName elMessage = + (TypedMessageWithCustomName) BeanProvider.getContextualReference("namedTypedMessages"); Assert.assertNotNull(elMessage); Assert.assertEquals("Hello DeltaSpike", elMessage.sayHello("DeltaSpike")); + Assert.assertEquals("Hello 'null'", elMessage.sayHello(null)); + Assert.assertEquals("Text", elMessage.text()); } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/TypedMessageWithCustomName.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/TypedMessageWithCustomName.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/TypedMessageWithCustomName.java new file mode 100644 index 0000000..e9f66be --- /dev/null +++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/TypedMessageWithCustomName.java @@ -0,0 +1,35 @@ +/* + * 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.message; + +import org.apache.deltaspike.core.api.message.MessageBundle; +import org.apache.deltaspike.core.api.message.MessageContextConfig; + +import javax.inject.Named; + +@Named("namedTypedMessages") +@MessageBundle +@MessageContextConfig( + localeResolver = FixedEnglishLocalResolver.class, + messageSource = "customMinimalMessage") +public interface TypedMessageWithCustomName +{ + String sayHello(String name); + String text(); +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c4353b11/deltaspike/core/impl/src/test/resources/customMinimalMessage_en.properties ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/test/resources/customMinimalMessage_en.properties b/deltaspike/core/impl/src/test/resources/customMinimalMessage_en.properties index 95d41e9..388c4ee 100644 --- a/deltaspike/core/impl/src/test/resources/customMinimalMessage_en.properties +++ b/deltaspike/core/impl/src/test/resources/customMinimalMessage_en.properties @@ -16,3 +16,4 @@ #under the License. sayHello=Hello %s +text=Text
