-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bba05b
commit a3b0c37
Showing
7 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/test/java/io/astefanutti/camel/cdi/AdvisedRouteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters