From 82b1b3d16d54432e7124ff81ec802e027788272d Mon Sep 17 00:00:00 2001 From: Jokser Date: Sun, 1 Mar 2015 05:44:47 +0600 Subject: [PATCH] [SWITCHYARD-2580] Make it possible to don't startup service bindings automatically - Changes in common-camel --- .../camel/common/handler/InboundHandler.java | 3 ++- .../common/handler/InboundHandlerTest.java | 13 +++++++++++++ .../common/handler/InboundHandlerTestBase.java | 18 +++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/common/camel/src/main/java/org/switchyard/component/camel/common/handler/InboundHandler.java b/common/camel/src/main/java/org/switchyard/component/camel/common/handler/InboundHandler.java index 71b2d945e..e160a4900 100644 --- a/common/camel/src/main/java/org/switchyard/component/camel/common/handler/InboundHandler.java +++ b/common/camel/src/main/java/org/switchyard/component/camel/common/handler/InboundHandler.java @@ -84,7 +84,8 @@ protected RouteDefinition createRouteDefinition() { addTransactionPolicy(route); addNamespacePolicy(route); - route.setProperty(ExchangeCompletionEvent.GATEWAY_NAME).simple(getBindingModel().getName(), String.class) + route.autoStartup(getBindingModel().isAutoStartup()) + .setProperty(ExchangeCompletionEvent.GATEWAY_NAME).simple(getBindingModel().getName(), String.class) .setProperty(CamelConstants.APPLICATION_NAMESPACE).constant(_serviceName.getNamespaceURI()) .process(new MessageComposerProcessor(getBindingModel())) .process(new OperationSelectorProcessor(getServiceName(), getBindingModel())) diff --git a/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTest.java b/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTest.java index 4b72feac2..34d2b59af 100644 --- a/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTest.java +++ b/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTest.java @@ -18,6 +18,7 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.Assert; import org.junit.Test; /** @@ -115,4 +116,16 @@ public void hasTransactionManager() throws Exception { _camelContext.stop(); } + /** + * Test covering a case when binding camel route does not startup automatically + * @throws Exception If route startup or shutdown fails. + */ + @Test + public void testBindingRouteAutoStartup() throws Exception { + InboundHandler handler = createInboundHandler("direct://autoStartup", false); + _camelContext.start(); + Assert.assertEquals(false, _camelContext.getRouteDefinition(handler.getRouteId()).isAutoStartup(_camelContext)); + _camelContext.stop(); + } + } diff --git a/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTestBase.java b/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTestBase.java index 7efd6b01f..f9c3946fd 100644 --- a/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTestBase.java +++ b/common/camel/src/test/java/org/switchyard/component/camel/common/handler/InboundHandlerTestBase.java @@ -64,23 +64,27 @@ public void startUp() { _configuration = mock(Configuration.class); } + protected InboundHandler createInboundHandler(final String uri, final boolean autoStartup) { + return createInboundHandler(uri, null, autoStartup, null, null, null); + } + protected InboundHandler createInboundHandler(final String uri) { - return createInboundHandler(uri, null, null, null, null); + return createInboundHandler(uri, null, true, null, null, null); } protected InboundHandler createInboundHandler(final String uri, final String name, OperationSelectorModel selectorModel) { - return createInboundHandler(uri, name, selectorModel, null, null); + return createInboundHandler(uri, name, true, selectorModel, null, null); } protected InboundHandler createInboundHandler(final String uri, final String name, MessageComposerModel composerModel) { - return createInboundHandler(uri, name, null, composerModel, null); + return createInboundHandler(uri, name, true, null, composerModel, null); } protected InboundHandler createInboundHandler(final String uri, final String name, ContextMapperModel mapperModel) { - return createInboundHandler(uri, name, null, null, mapperModel); + return createInboundHandler(uri, name, true, null, null, mapperModel); } - protected InboundHandler createInboundHandler(final String uri, final String name, final OperationSelectorModel selectorModel, + protected InboundHandler createInboundHandler(final String uri, final String name, final boolean autoStartup, final OperationSelectorModel selectorModel, final MessageComposerModel composerModel, final ContextMapperModel mapperModel) { V1BaseCamelBindingModel camelBindingModel = new V1BaseCamelBindingModel(_configuration, new Descriptor()) { @Override @@ -103,6 +107,10 @@ public MessageComposerModel getMessageComposer() { public ContextMapperModel getContextMapper() { return mapperModel; } + @Override + public boolean isAutoStartup() { + return autoStartup; + } }; return new InboundHandler(camelBindingModel, _camelContext, new QName("urn:foo", "dummyService"), null); }