...
Tip |
---|
You can use RouteBeanNameGenerator for automatic bean names generation. |
Unit tests
Each route implementation must have corresponding unit tests, at least one successful scenario.
- create unit test that extends AbstractTest or AbstractDbTest if database support is needed (both classes are from test module)
- you can use Spring test profiles - see org.openhubframework.openhub.modules.TestProfiles
- use @ActiveRoutes annotation that defines which routes will be activated for specific unit test
Tip |
---|
See How to write unit test? for more details about writing unit tests. |
New synchronous route implementation
Synchronous route is route where source system waits for response. This type of requests are not stored in OpenHub evidence, there are mentions in log files only. Possible error is immediately propagated to source system.
Steps for implementation are identical to those mentioned in previous chapter.
New asynchronous route implementation
...
New synchronous route implementation
Synchronous route is route where source system waits for response. This type of requests are not stored in OpenHub evidence, there are mentions in log files only. Possible error is immediately propagated to source system.
Steps for implementation are identical to those mentioned in previous chapter.
New asynchronous route implementation
How to implement asynchronous routes is described in another page.
...
Code Block |
---|
@CamelConfiguration(value = AsyncHelloRoute.ROUTE_BEAN) @Profile(ExampleProperties.EXAMPLE_PROFILE) public class AsyncHelloRoute extends AbstractBasicRoute { private static final Logger LOG = LoggerFactory.getLogger(AsyncHelloRoute.class); static final String ROUTE_BEAN = "asyncHelloRouteBean"; private static final String OPERATION_NAME = "asyncHello"; static final String ROUTE_ID_ASYNC_IN = getInRouteId(ServiceEnum.HELLO, OPERATION_NAME); static final String ROUTE_ID_ASYNC_OUT = getOutRouteId(ServiceEnum.HELLO, OPERATION_NAME); static final String URI_ASYNC_HELLO_OUT = "direct:" + ROUTE_ID_ASYNC_OUT; private static final String URI_PRINT_GREETING = "direct:printGreeting"; @Override protected void doConfigure() throws Exception { // asyncHello - input asynch message createRouteForAsyncHelloRouteIn(); // asyncHello - process delivery to external systems createRouteForAsyncHelloRouteOut(); } /** * Route for asynchronous <strong>asyncHello</strong> input operation. * <p/> * Prerequisite: none * <p/> * Output: {@link AsyncHelloResponse} */ private void createRouteForAsyncHelloRouteIn() { Namespaces ns = new Namespaces("h", SyncHelloRoute.HELLO_SERVICE_NS); // note: mandatory parameters are set already in XSD, this validation is extra XPathValidator validator = new XPathValidator("/h:asyncHelloRequest", ns, "h:name"); // note: only shows using but without any influence in this case Expression nameExpr = xpath("/h:asyncHelloRequest/h:name").namespaces(ns).stringResult(); AsynchRouteBuilder.newInstance(ServiceEnum.HELLO, OPERATION_NAME, getInWsUri(new QName(SyncHelloRoute.HELLO_SERVICE_NS, "asyncHelloRequest")), new AsynchResponseProcessor() { @Override protected Object setCallbackResponse(CallbackResponse callbackResponse) { AsyncHelloResponse res = new AsyncHelloResponse(); res.setConfirmAsyncHello(callbackResponse); return res; } }, jaxb(AsyncHelloResponse.class)) .withValidator(validator) .withObjectIdExpr(nameExpr) .build(this); } /** * Route for <strong>asyncHello</strong> operation - process delivery to external systems. * <p/> * Prerequisite: none */ private void createRouteForAsyncHelloRouteOut() { from(URI_ASYNC_HELLO_OUT) .routeId(ROUTE_ID_ASYNC_OUT) // xml -> AsyncHelloRequest .unmarshal(jaxb(AsyncHelloRequest.class)) .to("extcall:message:" + URI_PRINT_GREETING); from(URI_PRINT_GREETING) .bean(this, "printGreeting"); } @Handler public void printGreeting(@Body AsyncHelloRequest req) { Assert.notNull(req, "req must not be null"); String greeting = "Hello " + req.getName(); LOG.debug("Greeting: " + greeting); } } |
Unit tests
Each route implementation must have corresponding unit tests, at least one successful scenario.
- create unit test that extends AbstractTest or AbstractDbTest if database support is needed (both classes are from test module)
- you can use Spring test profiles - see org.openhubframework.openhub.modules.TestProfiles
- use @ActiveRoutes annotation that defines which routes will be activated for specific unit test
Tip |
---|
See How to write unit test? for more details about writing unit tests. |
There are corresponding unit tests to each route - SyncHelloRouteTest resp. AsyncHelloRouteTest.
...