Author: cmoulliard Date: Tue Sep 4 10:52:48 2012 New Revision: 1380542 URL: http://svn.apache.org/viewvc?rev=1380542&view=rev Log: Add example using @ConfigProperty of DeltaSpike
Added: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/EndpointDefinedUsingConfigPropertyTest.java camel/trunk/components/camel-cdi/src/test/resources/META-INF/camel.properties Modified: camel/trunk/components/camel-cdi/pom.xml camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContextTestSupport.java Modified: camel/trunk/components/camel-cdi/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/pom.xml?rev=1380542&r1=1380541&r2=1380542&view=diff ============================================================================== --- camel/trunk/components/camel-cdi/pom.xml (original) +++ camel/trunk/components/camel-cdi/pom.xml Tue Sep 4 10:52:48 2012 @@ -51,16 +51,23 @@ <dependencies> - <dependency> + <!-- Camel --> + <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> </dependency> + <!-- DeltaSpike --> <dependency> <groupId>org.apache.deltaspike.core</groupId> <artifactId>deltaspike-core-api</artifactId> <version>${deltaspike-version}</version> </dependency> + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-impl</artifactId> + <version>${deltaspike-version}</version> + </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> 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=1380542&r1=1380541&r2=1380542&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 Tue Sep 4 10:52:48 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.CdiCamelContext; import org.apache.camel.component.cdi.internal.CamelExtension; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.deltaspike.cdise.api.CdiContainer; @@ -66,7 +67,7 @@ public abstract class CdiContextTestSupp @Override protected CamelContext createCamelContext() throws Exception { - return BeanProvider.getContextualReference(CamelContext.class); + return BeanProvider.getContextualReference(CdiCamelContext.class); } @Override Added: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/EndpointDefinedUsingConfigPropertyTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/EndpointDefinedUsingConfigPropertyTest.java?rev=1380542&view=auto ============================================================================== --- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/EndpointDefinedUsingConfigPropertyTest.java (added) +++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/EndpointDefinedUsingConfigPropertyTest.java Tue Sep 4 10:52:48 2012 @@ -0,0 +1,76 @@ +/** + * 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 org.apache.camel.*; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.cdi.store.Item; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.deltaspike.core.api.config.annotation.ConfigProperty; +import org.junit.Test; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +public class EndpointDefinedUsingConfigPropertyTest extends CdiContextTestSupport { + + @Inject @ConfigProperty(name="directEndpoint") + String directInjectEndpoint; + + @EndpointInject(uri = "mock:result") + MockEndpoint mockResultEndpoint; + + @Produce(uri = "direct:inject") + ProducerTemplate myProducer; + + @Test + public void beanShouldBeInjected() throws InterruptedException { + mockResultEndpoint.expectedMessageCount(1); + myProducer.sendBody("hello"); + + assertMockEndpointsSatisfied(); + + Exchange exchange = mockResultEndpoint.getExchanges().get(0); + List<?> results = exchange.getIn().getBody(List.class); + List<Item> expected = itemsExpected(); + assertNotNull(results); + assertNotNull(expected); + assertEquals(expected.size(), results.size()); + assertEquals(expected, results); + } + + private List<Item> itemsExpected() { + List<Item> products = new ArrayList<Item>(); + for (int i = 1; i < 10; i++) { + products.add(new Item("Item-" + i, 1500L * i)); + } + return products; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(directInjectEndpoint) + .beanRef("shoppingBean", "listAllProducts") + .to(mockResultEndpoint); + } + }; + } +} Added: camel/trunk/components/camel-cdi/src/test/resources/META-INF/camel.properties URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/resources/META-INF/camel.properties?rev=1380542&view=auto ============================================================================== --- camel/trunk/components/camel-cdi/src/test/resources/META-INF/camel.properties (added) +++ camel/trunk/components/camel-cdi/src/test/resources/META-INF/camel.properties Tue Sep 4 10:52:48 2012 @@ -0,0 +1 @@ +directEndpoint=direct:inject \ No newline at end of file