Skip to content

Commit

Permalink
First simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Aug 26, 2014
1 parent 0585830 commit a9463d3
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 61 deletions.
109 changes: 62 additions & 47 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<camel.version>2.13.0</camel.version>
<cdi.version>1.2</cdi.version>
<slf4j.version>1.7.7</slf4j.version>
<weld.version>2.2.4.Final</weld.version>
<owb.version>2.0.0-SNAPSHOT</owb.version>
<arquillian.version>1.1.5.Final</arquillian.version>
Expand Down Expand Up @@ -215,24 +216,10 @@

<!-- test dependencies -->

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>

Expand All @@ -243,13 +230,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-reflect</artifactId>
Expand All @@ -275,17 +255,6 @@
<type>pom</type>
</dependency>

<!-- TODO: should be removed when the depchain is included in the BOM
see https://github.com/shrinkwrap/descriptors/pull/94
and https://issues.jboss.org/browse/SHRINKDESC-154 -->
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-depchain</artifactId>
<version>${shrinkwrap.descriptors.version}</version>
<scope>test</scope>
<type>pom</type>
</dependency>

<!-- Arquillian -->

<dependency>
Expand All @@ -306,20 +275,6 @@
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-se-embedded-1.1</artifactId>
<version>${arquillian.weld.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>${arquillian.weld.version}</version>
<scope>test</scope>
</dependency>

<!-- OpenWebBeans -->

<dependency>
Expand Down Expand Up @@ -358,6 +313,66 @@
<scope>provided</scope>
</dependency>

<!-- test dependencies -->

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>

<!-- TODO: should be removed when the depchain is included in the BOM
see https://github.com/shrinkwrap/descriptors/pull/94
and https://issues.jboss.org/browse/SHRINKDESC-154 -->
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-depchain</artifactId>
<version>${shrinkwrap.descriptors.version}</version>
<scope>test</scope>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-se-embedded-1.1</artifactId>
<version>${arquillian.weld.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
15 changes: 5 additions & 10 deletions src/main/java/io/astefanutti/camel/cdi/CdiBeanRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
*/
package io.astefanutti.camel.cdi;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.camel.spi.Registry;
import org.apache.camel.util.ObjectHelper;

import javax.enterprise.inject.Vetoed;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;

import org.apache.camel.spi.Registry;
import org.apache.camel.util.ObjectHelper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Vetoed
class CdiBeanRegistry implements Registry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private static MockEndpoint createMockEndpoint(InjectionPoint point, CamelContex
MockEndpoint endpoint = camelContext.getEndpoint(uri, MockEndpoint.class);
if (endpoint == null)
throw new NoSuchEndpointException(uri);

return endpoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
import org.apache.camel.component.properties.DefaultPropertiesParser;
import org.apache.camel.component.properties.PropertiesComponent;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.Properties;

@ApplicationScoped
@Named("properties")
class CdiPropertiesComponent extends PropertiesComponent {

@Inject
CdiPropertiesComponent(@Configuration Instance<Properties> properties) {
CdiPropertiesComponent(@Config Instance<Properties> properties) {
setPropertiesParser(properties.isUnsatisfied() ? new DefaultPropertiesParser() : new CdiPropertiesParser(properties.get()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
@Documented
@Retention(RUNTIME)
@Target({ METHOD, FIELD, PARAMETER, TYPE })
public @interface Configuration {
public @interface Config {
}
85 changes: 85 additions & 0 deletions src/test/java/io/astefanutti/camel/cdi/SimpleRouteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed 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 io.astefanutti.camel.cdi;

import io.astefanutti.camel.cdi.bean.SimpleRoute;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;
import java.util.concurrent.TimeUnit;

import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;

@RunWith(Arquillian.class)
public class SimpleRouteTest {

@Inject
@Uri("direct:inbound")
private ProducerTemplate inbound;

@Inject
@Mock("mock:outbound")
private MockEndpoint outbound;

@Inject
private CamelContext camelContext;

@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class)
// Camel CDI
.addPackages(true, Filters.exclude(".*Test.*"), CdiCamelExtension.class.getPackage())
// Test class
.addClass(SimpleRoute.class)
// Bean archive deployment descriptor
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Test
@InSequence(1)
public void startCamelContext() throws Exception {
camelContext.start();
}

@Test
@InSequence(2)
public void sendInboundMessage() throws InterruptedException {
outbound.expectedMessageCount(1);
outbound.expectedBodiesReceived("test");

inbound.sendBody("test");

assertIsSatisfied(2L, TimeUnit.SECONDS, outbound);
}

@Test
@InSequence(3)
public void stopCamelContext() throws Exception {
camelContext.stop();
}
}
27 changes: 27 additions & 0 deletions src/test/java/io/astefanutti/camel/cdi/bean/SimpleRoute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2014 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed 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 io.astefanutti.camel.cdi.bean;


import org.apache.camel.builder.RouteBuilder;

public class SimpleRoute extends RouteBuilder {

@Override
public void configure() {
from("direct:inbound").to("mock:outbound");
}
}

0 comments on commit a9463d3

Please sign in to comment.