JBoss.orgCommunity Documentation
Testing your applications is dead simple with the comprehensive unit test support provided in SwitchYard. There are two primary elements to test support in SwitchYard:
SwitchYardTestCase
- base unit test class which takes care of bootstrapping an embedded SwitchYard runtime and deploying the project as a SwitchYard application.
TestMixIn
s - composition-based method for adding specific testing tools to your test case. Each MixIn provides customized testing tools for things like service implementations, gateway bindings, and transformers.
Adding test support to your SwitchYard application is simply a matter of adding a dependency to the switchyard-test module in your application's pom.xml.
<dependency> <groupId>org.switchyard</groupId> <artifactId>switchyard-test</artifactId> <version>[release-version]</version> <!-- e.g. "0.1.0" --> <scope>test</scope> </dependency>
To take advantage of the test support in SwitchYard, your unit test should extend the base
SwitchYardTestCase
class.
SwitchYardTestCase
takes care of creating and starting an embedded runtime for each test method. After the embedded runtime is started, the project containing the test is packaged as a SwitchYard application and deployed to it. You can take advantage of various helper methods in the base test class to invoke your service and assert against the result.
@SwitchYardTestCaseConfig(config = "META-INF/switchyard.xml") public class MyServiceTest extends SwitchYardTestCase { @Test public void testOperation() { newInvoker("MyService") .operation("acceptMessage") .sendInOnly("Test message content"); } }
The optional
SwitchYardTestCaseConfig
can be used if you would like to use a different application descriptor than the default META-INF/switchyard.xml to test your application.
The
TestMixIn
feature allows you to selectively enable additional test functionality based on the capabilities of your application. The following MixIn types are available in 0.1:
CDIMixIn
: boostraps a stand-alone CDI environment, automatically discovers CDI beans, registers bean services, and injects references to SwitchYard services.
HTTPMixIn
: client methods for testing HTTP-based services.
SmooksMixIn
: stand-alone testing of any Smoooks transformers in your application.