Author: jstrachan Date: Mon Sep 3 12:39:51 2012 New Revision: 1380220 URL: http://svn.apache.org/viewvc?rev=1380220&view=rev Log: fix for CAMEL-5553 so that we can support injection via @EndpointInject and @Produce without any need for @Inject (though we use more usual CDI methods for injecting via @Inject) along with processing of @Consume
Added: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/DelegateInjectionTarget.java (with props) camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CamelEndpointInjectTest.java (with props) camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/support/CamelEndpointInjectedBean.java (with props) Modified: camel/trunk/components/camel-cdi/pom.xml camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContextTestSupport.java camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/InjectCamelAnnotationsTest.java camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/ProduceInjectTest.java Modified: camel/trunk/components/camel-cdi/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/pom.xml?rev=1380220&r1=1380219&r2=1380220&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/pom.xml (original) +++ camel/trunk/components/camel-cdi/pom.xml Mon Sep 3 12:39:51 2012 @@ -117,9 +117,6 @@ <profiles> <profile> <id>owb</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> <dependencies> <dependency> <groupId>org.apache.geronimo.specs</groupId> @@ -149,6 +146,10 @@ <profile> <id>weld</id> + <!-- active by default as the overriding of InvocationTarget is currently broken in owb which breaks ProduceInjectTest --> + <activation> + <activeByDefault>true</activeByDefault> + </activation> <dependencies> <dependency> <groupId>org.apache.deltaspike.cdictrl</groupId> Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java?rev=1380220&r1=1380219&r2=1380220&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java (original) +++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java Mon Sep 3 12:39:51 2012 @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import javax.enterprise.inject.spi.Bean; +import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.impl.CamelPostProcessorHelper; import org.apache.camel.impl.DefaultCamelBeanPostProcessor; @@ -31,29 +32,18 @@ import org.apache.camel.impl.DefaultCame * Contains the bean and the consume methods */ public class BeanAdapter { - private final Bean<?> bean; private final List<Method> consumeMethods = new ArrayList<Method>(); private final List<Method> produceMethods = new ArrayList<Method>(); + private final List<Method> endpointMethods = new ArrayList<Method>(); private final List<Field> produceFields = new ArrayList<Field>(); + private final List<Field> endpointFields = new ArrayList<Field>(); - public BeanAdapter(Bean<?> bean) { - this.bean = bean; - } - - public Bean<?> getBean() { - return bean; - } - - public List<Method> getConsumeMethods() { - return consumeMethods; - } - - public List<Method> getProduceMethods() { - return produceMethods; - } - - public List<Field> getProduceFields() { - return produceFields; + /** + * Returns true if this adapter is empty (i.e. has no custom adapter code) + */ + public boolean isEmpty() { + return consumeMethods.isEmpty() && produceMethods.isEmpty() && produceFields.isEmpty() && + endpointMethods.isEmpty() && endpointFields.isEmpty(); } public void addConsumeMethod(Method method) { @@ -68,30 +58,52 @@ public class BeanAdapter { produceFields.add(field); } + public void addEndpointField(Field field) { + endpointFields.add(field); + } + + public void addEndpointMethod(Method method) { + endpointMethods.add(method); + } + /** - * Perform processing of the various @Consume, @Produce methods on the given bean reference + * Perform injections */ - public void initialiseBean(DefaultCamelBeanPostProcessor postProcessor, Object reference, - String beanName) { + public void inject(DefaultCamelBeanPostProcessor postProcessor, Object reference, + String beanName) { CamelPostProcessorHelper postProcessorHelper = postProcessor.getPostProcessorHelper(); for (Method method : consumeMethods) { postProcessorHelper.consumerInjection(method, reference, beanName); } for (Method method : produceMethods) { - Produce produce = method.getAnnotation(Produce.class); - if (produce != null && postProcessorHelper.matchContext(produce.context())) { - postProcessor.setterInjection(method, bean, beanName, produce.uri(), produce.ref(), - produce.property()); + Produce annotation = method.getAnnotation(Produce.class); + if (annotation != null && postProcessorHelper.matchContext(annotation.context())) { + postProcessor.setterInjection(method, reference, beanName, annotation.uri(), annotation.ref(), + annotation.property()); + + } + } + for (Method method : endpointMethods) { + EndpointInject annotation = method.getAnnotation(EndpointInject.class); + if (annotation != null && postProcessorHelper.matchContext(annotation.context())) { + postProcessor.setterInjection(method, reference, beanName, annotation.uri(), annotation.ref(), + annotation.property()); } } for (Field field : produceFields) { - Produce produce = field.getAnnotation(Produce.class); - if (produce != null && postProcessorHelper.matchContext(produce.context())) { - postProcessor.injectField(field, produce.uri(), produce.ref(), - produce.property(), reference, beanName); + Produce annotation = field.getAnnotation(Produce.class); + if (annotation != null && postProcessorHelper.matchContext(annotation.context())) { + postProcessor.injectField(field, annotation.uri(), annotation.ref(), + annotation.property(), reference, beanName); + } + } + for (Field field : endpointFields) { + EndpointInject annotation = field.getAnnotation(EndpointInject.class); + if (annotation != null && postProcessorHelper.matchContext(annotation.context())) { + postProcessor.injectField(field, annotation.uri(), annotation.ref(), + annotation.property(), reference, beanName); } } } - } Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java?rev=1380220&r1=1380219&r2=1380220&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java (original) +++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java Mon Sep 3 12:39:51 2012 @@ -18,10 +18,9 @@ package org.apache.camel.component.cdi.i import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.Set; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.event.Observes; import javax.enterprise.inject.spi.AfterBeanDiscovery; @@ -31,16 +30,18 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.BeforeShutdown; import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.InjectionTarget; import javax.enterprise.inject.spi.ProcessAnnotatedType; import javax.enterprise.inject.spi.ProcessBean; +import javax.enterprise.inject.spi.ProcessInjectionTarget; import javax.inject.Inject; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.Consume; +import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.component.cdi.CdiCamelContext; -import org.apache.camel.impl.CamelPostProcessorHelper; import org.apache.camel.impl.DefaultCamelBeanPostProcessor; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ReflectionHelper; @@ -56,6 +57,7 @@ public class CamelExtension implements E * Context instance. */ private CamelContext camelContext; + private DefaultCamelBeanPostProcessor postProcessor; private Map<Bean<?>, BeanAdapter> beanAdapters = new HashMap<Bean<?>, BeanAdapter>(); @@ -65,7 +67,8 @@ public class CamelExtension implements E * @param process Annotated type. * @throws Exception In case of exceptions. */ - protected void contextAwareness(@Observes ProcessAnnotatedType<CamelContextAware> process) throws Exception { + protected void contextAwareness(@Observes ProcessAnnotatedType<CamelContextAware> process) + throws Exception { AnnotatedType<CamelContextAware> annotatedType = process.getAnnotatedType(); Class<CamelContextAware> javaClass = annotatedType.getJavaClass(); if (CamelContextAware.class.isAssignableFrom(javaClass)) { @@ -94,7 +97,8 @@ public class CamelExtension implements E * @param manager Bean manager. */ protected void registerManagedCamelContext(@Observes AfterBeanDiscovery abd, BeanManager manager) { - abd.addBean(new CamelContextBean(manager.createInjectionTarget(manager.createAnnotatedType(CdiCamelContext.class)))); + abd.addBean(new CamelContextBean( + manager.createInjectionTarget(manager.createAnnotatedType(CdiCamelContext.class)))); } /** @@ -119,6 +123,9 @@ public class CamelExtension implements E } } + /** + * Lets detect all beans annotated with @Consume + */ public void detectConsumeBeans(@Observes ProcessBean<?> event) { final Bean<?> bean = event.getBean(); ReflectionHelper.doWithMethods(bean.getBeanClass(), new ReflectionHelper.MethodCallback() { @@ -129,51 +136,111 @@ public class CamelExtension implements E BeanAdapter beanAdapter = getBeanAdapter(bean); beanAdapter.addConsumeMethod(method); } - Produce produce = method.getAnnotation(Produce.class); - if (produce != null) { - BeanAdapter beanAdapter = getBeanAdapter(bean); - beanAdapter.addProduceMethod(method); - } - } - }); - ReflectionHelper.doWithFields(bean.getBeanClass(), new ReflectionHelper.FieldCallback() { - @Override - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { - Produce produce = field.getAnnotation(Produce.class); - if (produce != null && !injectAnnotatedField(field)) { - BeanAdapter beanAdapter = getBeanAdapter(bean); - beanAdapter.addProduceField(field); - } } }); } /** - * Returns true if this field is annotated with @Inject + * Lets force the CDI container to create all beans annotated with @Consume so that the consumer becomes active */ - protected static boolean injectAnnotatedField(Field field) { - return field.getAnnotation(Inject.class) != null; - } - - public void initializeBeans(@Observes AfterDeploymentValidation event, BeanManager beanManager) { + public void startConsumeBeans(@Observes AfterDeploymentValidation event, BeanManager beanManager) { ObjectHelper.notNull(getCamelContext(), "camelContext"); - DefaultCamelBeanPostProcessor postProcessor = new DefaultCamelBeanPostProcessor(getCamelContext()); - Collection<BeanAdapter> adapters = beanAdapters.values(); - for (BeanAdapter adapter : adapters) { - Bean<?> bean = adapter.getBean(); + Set<Map.Entry<Bean<?>, BeanAdapter>> entries = beanAdapters.entrySet(); + for (Map.Entry<Bean<?>, BeanAdapter> entry : entries) { + Bean<?> bean = entry.getKey(); + BeanAdapter adapter = entry.getValue(); CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean); Object reference = beanManager.getReference(bean, Object.class, creationalContext); - String beanName = bean.getName(); + } + } + + + /** + * Lets perform injection of all beans which use Camel annotations + */ + public void onInjectionTarget(@Observes ProcessInjectionTarget event) { + final InjectionTarget injectionTarget = event.getInjectionTarget(); + final Class beanClass = event.getAnnotatedType().getJavaClass(); + // TODO this is a bit of a hack - what should the bean name be? + final String beanName = event.getInjectionTarget().toString(); + final BeanAdapter adapter = createBeanAdapter(beanClass); + if (!adapter.isEmpty()) { + DelegateInjectionTarget newTarget = new DelegateInjectionTarget(injectionTarget) { + + @Override + public void postConstruct(Object instance) { + super.postConstruct(instance); + + // now lets do the post instruct to inject our Camel injections + adapter.inject(getPostProcessor(), instance, beanName); + } + }; + event.setInjectionTarget(newTarget); + } + } + + /** + * Perform injection on an existing bean such as a test case which is created directly by a testing framework. + * + * This is because BeanProvider.injectFields() does not invoke the onInjectionTarget() method so the injection + * of @Produce / @EndpointInject and processing of the @Consume annotations are not performed. + */ + public void inject(Object bean) { + final BeanAdapter adapter = createBeanAdapter(bean.getClass()); + if (!adapter.isEmpty()) { + // TODO this is a bit of a hack - what should the bean name be? + final String beanName = bean.toString(); + adapter.inject(getPostProcessor(), bean, beanName); + } + } + + private BeanAdapter createBeanAdapter(Class beanClass) { + final BeanAdapter adapter = new BeanAdapter(); + ReflectionHelper.doWithFields(beanClass, new ReflectionHelper.FieldCallback() { + @Override + public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { + Produce produce = field.getAnnotation(Produce.class); + if (produce != null && !injectAnnotatedField(field)) { + adapter.addProduceField(field); + } + EndpointInject endpointInject = field.getAnnotation(EndpointInject.class); + if (endpointInject != null) { + adapter.addEndpointField(field); + } + } + }); + ReflectionHelper.doWithMethods(beanClass, new ReflectionHelper.MethodCallback() { + @Override + public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { + Consume consume = method.getAnnotation(Consume.class); + if (consume != null) { + adapter.addConsumeMethod(method); + } + Produce produce = method.getAnnotation(Produce.class); + if (produce != null) { + adapter.addProduceMethod(method); + } + EndpointInject endpointInject = method.getAnnotation(EndpointInject.class); + if (endpointInject != null) { + adapter.addEndpointMethod(method); + } + } + }); + return adapter; + } - adapter.initialiseBean(postProcessor, reference, beanName); + protected DefaultCamelBeanPostProcessor getPostProcessor() { + if (postProcessor == null) { + postProcessor = new DefaultCamelBeanPostProcessor(getCamelContext()); } + return postProcessor; } protected BeanAdapter getBeanAdapter(Bean<?> bean) { BeanAdapter beanAdapter = beanAdapters.get(bean); if (beanAdapter == null) { - beanAdapter = new BeanAdapter(bean); + beanAdapter = new BeanAdapter(); beanAdapters.put(bean, beanAdapter); } return beanAdapter; @@ -185,4 +252,12 @@ public class CamelExtension implements E } return camelContext; } + + + /** + * Returns true if this field is annotated with @Inject + */ + protected static boolean injectAnnotatedField(Field field) { + return field.getAnnotation(Inject.class) != null; + } } Added: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/DelegateInjectionTarget.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/DelegateInjectionTarget.java?rev=1380220&view=auto ============================================================================== --- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/DelegateInjectionTarget.java (added) +++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/DelegateInjectionTarget.java Mon Sep 3 12:39:51 2012 @@ -0,0 +1,64 @@ +/** + * + * 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.camel.component.cdi.internal; + +import java.util.Set; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.InjectionTarget; + +/** + * A helper class for creating delegate implementations of {@link InjectionTarget} + */ +public abstract class DelegateInjectionTarget implements InjectionTarget { + private final InjectionTarget delegate; + + public DelegateInjectionTarget(InjectionTarget delegate) { + this.delegate = delegate; + } + + @Override + public void dispose(Object instance) { + delegate.dispose(instance); + } + + @Override + public Set<InjectionPoint> getInjectionPoints() { + return delegate.getInjectionPoints(); + } + + @Override + public void inject(Object instance, CreationalContext ctx) { + delegate.inject(instance, ctx); + } + + @Override + public void postConstruct(Object instance) { + delegate.postConstruct(instance); + } + + @Override + public void preDestroy(Object instance) { + delegate.preDestroy(instance); + } + + @Override + public Object produce(CreationalContext creationalContext) { + return delegate.produce(creationalContext); + } +} Propchange: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/DelegateInjectionTarget.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CamelEndpointInjectTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CamelEndpointInjectTest.java?rev=1380220&view=auto ============================================================================== --- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CamelEndpointInjectTest.java (added) +++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CamelEndpointInjectTest.java Mon Sep 3 12:39:51 2012 @@ -0,0 +1,48 @@ +/** + * 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.camel.cdi; + +import javax.inject.Inject; + +import org.apache.camel.Endpoint; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.cdi.support.CamelEndpointInjectedBean; +import org.apache.camel.cdi.support.ProduceInjectedBean; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +/** + * Test endpoint injection using vanilla camel annotations without the use of @Inject + */ +public class CamelEndpointInjectTest extends CdiTestSupport { + + @Inject + private CamelEndpointInjectedBean bean; + + @Test + public void shouldInjectEndpoint() { + assertNotNull(bean); + Endpoint endpoint = bean.getEndpoint(); + assertNotNull("Could not find injected endpoint!", endpoint); + assertEquals("endpoint URI", "direct://inject", endpoint.getEndpointUri()); + + MockEndpoint mockEndpoint = bean.getMockEndpoint(); + assertNotNull("Could not find injected mock endpoint!", mockEndpoint); + assertEquals("mock endpoint URI", "mock://result", mockEndpoint.getEndpointUri()); + } + +} Propchange: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CamelEndpointInjectTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContextTestSupport.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContextTestSupport.java?rev=1380220&r1=1380219&r2=1380220&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContextTestSupport.java (original) +++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContextTestSupport.java Mon Sep 3 12:39:51 2012 @@ -19,6 +19,7 @@ package org.apache.camel.cdi; import java.util.logging.LogManager; import org.apache.camel.CamelContext; +import org.apache.camel.component.cdi.internal.CamelExtension; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.deltaspike.cdise.api.CdiContainer; import org.apache.deltaspike.cdise.api.CdiContainerLoader; @@ -70,12 +71,9 @@ public abstract class CdiContextTestSupp @Override protected void applyCamelPostProcessor() throws Exception { - // lets do nothing and let CDI do all the injection on this - - // TODO as a workaround until we support backwards compatible injection - // on @Produce / @EndpointInject without the use of @Inject - // lets keep the old behaviour - super.applyCamelPostProcessor(); + // lets perform any custom camel injection on the test case object + CamelExtension camelExtension = BeanProvider.getContextualReference(CamelExtension.class); + camelExtension.inject(this); } } Modified: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/InjectCamelAnnotationsTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/InjectCamelAnnotationsTest.java?rev=1380220&r1=1380219&r2=1380220&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/InjectCamelAnnotationsTest.java (original) +++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/InjectCamelAnnotationsTest.java Mon Sep 3 12:39:51 2012 @@ -16,36 +16,38 @@ */ package org.apache.camel.cdi; -import org.apache.camel.*; +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.Endpoint; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.cdi.store.Item; -import org.apache.camel.cdi.store.ShoppingBean; import org.apache.camel.component.mock.MockEndpoint; import org.junit.Test; -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - public class InjectCamelAnnotationsTest extends CdiContextTestSupport { @EndpointInject(uri="direct:inject") Endpoint directInjectEndpoint; @EndpointInject(uri="mock:result") - MockEndpoint mockResultendpoint; + MockEndpoint mockResultEndpoint; @Produce(uri = "mock:result") ProducerTemplate myProducer; @Test public void beanShouldBeInjected() throws InterruptedException { - mockResultendpoint.expectedMessageCount(1); + mockResultEndpoint.expectedMessageCount(1); myProducer.sendBody("direct:inject", "hello"); assertMockEndpointsSatisfied(); - Exchange exchange = mockResultendpoint.getExchanges().get(0); + Exchange exchange = mockResultEndpoint.getExchanges().get(0); List<?> results = exchange.getIn().getBody(List.class); List<Item> expected = itemsExpected(); assertNotNull(results); @@ -69,7 +71,7 @@ public class InjectCamelAnnotationsTest public void configure() throws Exception { from(directInjectEndpoint) .beanRef("shoppingBean", "listAllProducts") - .to(mockResultendpoint); + .to(mockResultEndpoint); } }; } Modified: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/ProduceInjectTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/ProduceInjectTest.java?rev=1380220&r1=1380219&r2=1380220&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/ProduceInjectTest.java (original) +++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/ProduceInjectTest.java Mon Sep 3 12:39:51 2012 @@ -18,12 +18,8 @@ package org.apache.camel.cdi; import javax.inject.Inject; -import org.apache.camel.Endpoint; import org.apache.camel.ProducerTemplate; -import org.apache.camel.cdi.support.EndpointInjectedBean; import org.apache.camel.cdi.support.ProduceInjectedBean; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Ignore; import org.junit.Test; /** @@ -34,7 +30,7 @@ public class ProduceInjectTest extends C @Inject private ProduceInjectedBean bean; - @Ignore + @Test public void shouldInjectEndpoint() { assertNotNull(bean); ProducerTemplate producer = bean.getProducer(); Added: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/support/CamelEndpointInjectedBean.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/support/CamelEndpointInjectedBean.java?rev=1380220&view=auto ============================================================================== --- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/support/CamelEndpointInjectedBean.java (added) +++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/support/CamelEndpointInjectedBean.java Mon Sep 3 12:39:51 2012 @@ -0,0 +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.camel.cdi.support; + +import javax.inject.Inject; + +import org.apache.camel.Endpoint; +import org.apache.camel.EndpointInject; +import org.apache.camel.component.mock.MockEndpoint; + +public class CamelEndpointInjectedBean { + + @EndpointInject(uri="direct:inject") + Endpoint endpoint; + + @EndpointInject(uri="mock:result") + MockEndpoint mockEndpoint; + + public Endpoint getEndpoint() { + return endpoint; + } + + public MockEndpoint getMockEndpoint() { + return mockEndpoint; + } +} Propchange: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/support/CamelEndpointInjectedBean.java ------------------------------------------------------------------------------ svn:eol-style = native