You can now create unit tests for SwitchYard services using a simple forge command : create-service-test. This command is available once you install the "switchyard" facet in your forge project. Generating a new test only requires a service name:
switchyard create-service-test --serviceName MyService
The service name passed in via --serviceName is not required to exist at the time the test is created. Of course, the test will fail if you don't create a service with this name in the application. The generated test class looks like this:
@RunWith(SwitchYardRunner.class) @SwitchYardTestCaseConfig(mixins=CDIMixIn.class, config=SwitchYardTestCaseConfig.SWITCHYARD_XML) public class MyServiceTest { @ServiceOperation("MyService") private Invoker service; @Test public void sendMessage() { service.sendInOnly("Message content goes here!"); } }
The generated test class is just a starting point. Here are some changes you might want to make to the generated test:
- If you want to invoke a specific operation name on the service, then add it to the @ServiceOperation annotation. For example, if you wanted to invoke the "process" operation on the "MyService" service, then the annotation value would be "MyService.process".
- If the service operation is in-out then you will want to change the test method to invoke service.sendInOut().
- Replace "Message content goes here!" with the actual payload for the message.
- Consider the use of additional MixIns depending on what you are testing (BPM, transformation, web service, etc.).
- Add more test methods! You can have as many as you want per test class.
Comments