Skip to content

Commit

Permalink
Camel context advise test
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Aug 27, 2014
1 parent 1bba05b commit a3b0c37
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 28 deletions.
29 changes: 6 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>

<dependencies>

<!-- provided dependencies -->
Expand Down Expand Up @@ -104,20 +105,11 @@

<profile>
<id>owb</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- JUL configuration for OWB -->
<argLine>-Djava.util.logging.config.file=src/test/resources/logging.properties</argLine>
<!-- JaCoCo agent if activated -->
<argLine>${jacoco.agent.arg}</argLine>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<!-- JUL configuration for OWB -->
<argLine>-Djava.util.logging.config.file=src/test/resources/logging.properties</argLine>
</properties>

<dependencies>

Expand Down Expand Up @@ -191,7 +183,6 @@
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.arg</propertyName>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<append>true</append>
<includes>
Expand All @@ -201,14 +192,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${jacoco.agent.arg}</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private BeanManagerUtil() {

@SuppressWarnings("unchecked")
static <T> Set<T> getContextualReferences(BeanManager beanManager, Class<T> type, Annotation... qualifiers) {
Set<T> references = new HashSet<T>();
Set<T> references = new HashSet<>();
for (Bean<?> bean : beanManager.getBeans(type, qualifiers))
references.add((T) beanManager.getReference(bean, type, beanManager.createCreationalContext(bean)));

Expand Down
104 changes: 104 additions & 0 deletions src/test/java/io/astefanutti/camel/cdi/AdvisedRouteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* 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.PropertyEndpointRoute;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.model.ModelCamelContext;
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.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

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

@RunWith(Arquillian.class)
public class AdvisedRouteTest {

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

@Config
@Produces
private static Properties configuration() {
Properties configuration = new Properties();
configuration.put("from", "inbound");
configuration.put("to", "direct:outbound");
configuration.put("header.message", "n/a");
return configuration;
}

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

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

@Test
@InSequence(1)
public void startCamelContext(ModelCamelContext context) throws Exception {
context.getRouteDefinition("route").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() {
interceptSendToEndpoint("{{to}}").skipSendToOriginalEndpoint().to("mock:outbound");
}
});

context.start();
}

@Test
@InSequence(2)
public void sendMessageToInboundConsumer() throws InterruptedException {
outbound.expectedMessageCount(1);
outbound.expectedBodiesReceived("test");
outbound.expectedHeaderReceived("header", "n/a");

inbound.sendBody("test");

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

@Test
@InSequence(3)
public void stopCamelContext(CamelContext context) throws Exception {
context.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;

@RunWith(Arquillian.class)
public class InjectedEndpointRouteTest {
public class InjectedEndpointTest {

@Deployment
public static Archive<?> deployment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;

@RunWith(Arquillian.class)
public class PropertyEndpointRouteTest {
public class PropertyEndpointTest {

@Deployment
public static Archive<?> deployment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;

@RunWith(Arquillian.class)
public class UriEndpointRouteTest {
public class UriEndpointTest {

@Deployment
public static Archive<?> deployment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class PropertyEndpointRoute extends RouteBuilder {

@Override
public void configure() {
from("direct:{{from}}").setHeader("header", simple("properties:header.message")).to("{{to}}");
from("direct:{{from}}")
.routeId("route")
.setHeader("header", simple("properties:header.message"))
.to("{{to}}");
}
}

0 comments on commit a3b0c37

Please sign in to comment.