You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/07 11:28:56 UTC

[camel] branch master updated (05bb44b -> 75f7199)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 05bb44b  Upgrade Cglib and related bundle to version 3.2.9
     new 7a39095  CAMEL-12978 - Add support to configure CamelContext created by KIE-Server extension
     new 75f7199  CAMEL-12978 - Fixed CS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/component/jbpm/JBPMConstants.java |   2 +
 .../component/jbpm/config/CamelContextBuilder.java |  17 +-
 .../jbpm/server/CamelKieServerExtension.java       |  69 +++++++-
 .../jbpm/server/CamelKieServerExtensionTest.java   | 197 +++++++++++++++++++++
 .../camel-jbpm/src/test/resources/camel-routes.xml |  10 +-
 .../src/test/resources/global-camel-routes.xml     |  10 +-
 6 files changed, 285 insertions(+), 20 deletions(-)
 copy camel-core/src/main/java/org/apache/camel/spi/HasCamelContext.java => components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java (64%)
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
 copy camel-core/src/test/resources/org/apache/camel/model/convertBody.xml => components/camel-jbpm/src/test/resources/camel-routes.xml (77%)
 copy camel-core/src/test/resources/org/apache/camel/model/convertBody.xml => components/camel-jbpm/src/test/resources/global-camel-routes.xml (77%)


[camel] 02/02: CAMEL-12978 - Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 75f71990c21f4112e0ffa3035427347b6acfec53
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Dec 7 12:28:21 2018 +0100

    CAMEL-12978 - Fixed CS
---
 .../jbpm/server/CamelKieServerExtension.java       | 46 +++++------
 .../jbpm/server/CamelKieServerExtensionTest.java   | 96 +++++++++++-----------
 .../camel-jbpm/src/test/resources/camel-routes.xml | 18 ++++
 .../src/test/resources/global-camel-routes.xml     | 18 ++++
 4 files changed, 107 insertions(+), 71 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
index f338aed..607867e 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
@@ -54,14 +54,14 @@ public class CamelKieServerExtension implements KieServerExtension {
     protected boolean managedCamel;
 
     protected Map<String, DefaultCamelContext> camelContexts = new HashMap<>();
-    
+
     protected CamelContextBuilder camelContextBuilder;
 
     public CamelKieServerExtension() {
         this.managedCamel = true;
         this.camelContextBuilder = discoverCamelContextBuilder();
     }
-    
+
     public CamelKieServerExtension(CamelContextBuilder camelContextBuilder) {
         this.managedCamel = true;
         this.camelContextBuilder = camelContextBuilder;
@@ -92,7 +92,7 @@ public class CamelKieServerExtension implements KieServerExtension {
     @Override
     public void init(KieServerImpl kieServer, KieServerRegistry registry) {
         if (this.managedCamel && this.camelContext == null) {
-            this.camelContext = (DefaultCamelContext) buildGlobalContext();
+            this.camelContext = (DefaultCamelContext)buildGlobalContext();
             this.camelContext.setName("KIE Server Camel context");
 
             try (InputStream is = this.getClass().getResourceAsStream("/global-camel-routes.xml")) {
@@ -129,7 +129,7 @@ public class CamelKieServerExtension implements KieServerExtension {
         try (InputStream is = classloader.getResourceAsStream("camel-routes.xml")) {
             if (is != null) {
 
-                DefaultCamelContext context = (DefaultCamelContext) buildDeploymentContext(id);
+                DefaultCamelContext context = (DefaultCamelContext)buildDeploymentContext(id);
                 context.setName("KIE Server Camel context for container " + kieContainerInstance.getContainerId());
 
                 RoutesDefinition routes = context.loadRoutesDefinition(is);
@@ -217,11 +217,11 @@ public class CamelKieServerExtension implements KieServerExtension {
     public String toString() {
         return EXTENSION_NAME + " KIE Server extension";
     }
-    
+
     public DefaultCamelContext getCamelContext() {
         return camelContext;
     }
-    
+
     public CamelContextBuilder getCamelContextBuilder() {
         return camelContextBuilder;
     }
@@ -244,44 +244,44 @@ public class CamelKieServerExtension implements KieServerExtension {
                     }
                     uri.append("deploymentId=").append(deploymentId);
                     from.setUri(uri.toString());
-                }                
+                }
             }
         }
     }
-    
+
     protected CamelContext buildGlobalContext() {
         if (camelContextBuilder != null) {
             return camelContextBuilder.buildCamelContext();
         }
-        
-        return new CamelContextBuilder(){}.buildCamelContext();
+
+        return new CamelContextBuilder() {
+        }.buildCamelContext();
     }
-    
+
     protected CamelContext buildDeploymentContext(String identifier) {
-        
-        InternalRuntimeManager runtimeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(identifier);
-        
+
+        InternalRuntimeManager runtimeManager = (InternalRuntimeManager)RuntimeManagerRegistry.get().getManager(identifier);
+
         if (runtimeManager != null) {
-            
-            CamelContextBuilder deploymentContextBuilder = (CamelContextBuilder) runtimeManager.getEnvironment()
-                                                                                        .getEnvironment()
-                                                                                        .get(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY);
+
+            CamelContextBuilder deploymentContextBuilder = (CamelContextBuilder)runtimeManager.getEnvironment().getEnvironment().get(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY);
             if (deploymentContextBuilder != null) {
                 return deploymentContextBuilder.buildCamelContext();
             }
         }
-        
-        return new CamelContextBuilder(){}.buildCamelContext();
+
+        return new CamelContextBuilder() {
+        }.buildCamelContext();
     }
-    
+
     protected CamelContextBuilder discoverCamelContextBuilder() {
-        
+
         ServiceLoader<CamelContextBuilder> builders = ServiceLoader.load(CamelContextBuilder.class);
         Iterator<CamelContextBuilder> it = builders.iterator();
         if (it.hasNext()) {
             return it.next();
         }
-        
+
         return null;
     }
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
index fbbb7ed..596f05e 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
@@ -16,12 +16,6 @@
  */
 package org.apache.camel.component.jbpm.server;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.when;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-
 import java.util.HashMap;
 import java.util.List;
 
@@ -43,67 +37,73 @@ import org.kie.server.services.api.KieContainerInstance;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
 @RunWith(MockitoJUnitRunner.class)
 public class CamelKieServerExtensionTest {
-    
-    private String identifier = "test";
-    
     @Mock
     InternalRuntimeManager runtimeManager;
-    
+
     @Mock
     RuntimeEnvironment runtimeEnvironment;
 
     @Mock
     private KieContainerInstance kieContainerInstance;
-    
+
     @Mock
     private KieContainer kieContainer;
+    
+    private String identifier = "test";
 
     @After
     public void cleanup() {
         RuntimeManagerRegistry.get().remove(identifier);
     }
-    
-    
+
     @Test
     public void testInit() {
         CamelKieServerExtension extension = new CamelKieServerExtension();
         extension.init(null, null);
-        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        CamelContext globalCamelContext = (CamelContext)ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
         List<RouteDefinition> globalRestDefinitions = globalCamelContext.getRouteDefinitions();
         assertThat(globalRestDefinitions.size(), equalTo(1));
         assertThat(globalCamelContext.getRouteDefinition("unitTestRoute"), is(notNullValue()));
     }
-    
+
     @Test
     public void testCreateContainer() {
         CamelKieServerExtension extension = new CamelKieServerExtension();
         final String containerId = "testContainer";
-        
+
         when(kieContainerInstance.getKieContainer()).thenReturn(kieContainer);
         when(kieContainer.getClassLoader()).thenReturn(this.getClass().getClassLoader());
-        
+
         extension.createContainer(containerId, kieContainerInstance, new HashMap<String, Object>());
-        
-        CamelContext camelContext = (CamelContext) ServiceRegistry.get().service("testContainer" + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
+
+        CamelContext camelContext = (CamelContext)ServiceRegistry.get().service("testContainer" + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
         List<RouteDefinition> restDefinitions = camelContext.getRouteDefinitions();
         assertThat(restDefinitions.size(), equalTo(1));
-        
+
         assertThat(camelContext.getRoute("unitTestRoute"), is(notNullValue()));
     }
-    
+
     @Test
     public void testDefaultSetup() {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
-        
+
         assertNull(extension.getCamelContextBuilder());
     }
-    
+
     @Test
     public void testDefaultSetupCustomDiscovery() {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension() {
 
             @Override
@@ -115,29 +115,29 @@ public class CamelKieServerExtensionTest {
                         // for test purpose return simply null as camel context
                         return null;
                     }
-                    
+
                 };
             }
-            
+
         };
-        
+
         assertNotNull(extension.getCamelContextBuilder());
         assertNull(extension.getCamelContextBuilder().buildCamelContext());
     }
-    
+
     @Test
     public void testBuildGlobalCamelContext() throws Exception {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
         CamelContext context = extension.buildGlobalContext();
         assertNotNull(context);
-        
+
         context.stop();
     }
-    
+
     @Test
     public void testBuildGlobalCamelContextCustomBuilder() throws Exception {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension(new CamelContextBuilder() {
 
             @Override
@@ -145,36 +145,36 @@ public class CamelKieServerExtensionTest {
                 // for test purpose return simply null as camel context
                 return null;
             }
-            
+
         });
         CamelContext context = extension.buildGlobalContext();
-        assertNull(context);        
+        assertNull(context);
     }
-    
+
     @Test
     public void testBuildDeploymentCamelContext() throws Exception {
-        
+
         when(runtimeManager.getIdentifier()).thenReturn(identifier);
         when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
-        
+
         Environment environment = KieServices.get().newEnvironment();
         when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
-        
+
         RuntimeManagerRegistry.get().register(runtimeManager);
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
         CamelContext context = extension.buildDeploymentContext(identifier);
         assertNotNull(context);
-        
+
         context.stop();
     }
-    
+
     @Test
     public void testBuildDeploymentCamelContextCustomBuilder() throws Exception {
-        
+
         when(runtimeManager.getIdentifier()).thenReturn(identifier);
         when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
-        
+
         Environment environment = KieServices.get().newEnvironment();
         environment.set(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY, new CamelContextBuilder() {
 
@@ -183,15 +183,15 @@ public class CamelKieServerExtensionTest {
                 // for test purpose return simply null as camel context
                 return null;
             }
-            
+
         });
         when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
-        
+
         RuntimeManagerRegistry.get().register(runtimeManager);
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
         CamelContext context = extension.buildDeploymentContext(identifier);
         assertNull(context);
-        
+
     }
 }
diff --git a/components/camel-jbpm/src/test/resources/camel-routes.xml b/components/camel-jbpm/src/test/resources/camel-routes.xml
index 710d40a..d4ff17d 100644
--- a/components/camel-jbpm/src/test/resources/camel-routes.xml
+++ b/components/camel-jbpm/src/test/resources/camel-routes.xml
@@ -1,4 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+
+-->
 <routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
   <route id="unitTestRoute">
     <from id="direct-unitTestRoute" uri="direct:unitTest" />
diff --git a/components/camel-jbpm/src/test/resources/global-camel-routes.xml b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
index 710d40a..d4ff17d 100644
--- a/components/camel-jbpm/src/test/resources/global-camel-routes.xml
+++ b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
@@ -1,4 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+
+-->
 <routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
   <route id="unitTestRoute">
     <from id="direct-unitTestRoute" uri="direct:unitTest" />


[camel] 01/02: CAMEL-12978 - Add support to configure CamelContext created by KIE-Server extension

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7a39095a368e76271c0696312ae614d77e37b5ca
Author: Maciej Swiderski <sw...@gmail.com>
AuthorDate: Wed Dec 5 12:41:59 2018 +0100

    CAMEL-12978 - Add support to configure CamelContext created by KIE-Server extension
---
 .../apache/camel/component/jbpm/JBPMConstants.java |   2 +
 .../component/jbpm/config/CamelContextBuilder.java |  35 ++++
 .../jbpm/server/CamelKieServerExtension.java       |  73 +++++++-
 .../jbpm/server/CamelKieServerExtensionTest.java   | 197 +++++++++++++++++++++
 .../camel-jbpm/src/test/resources/camel-routes.xml |   7 +
 .../src/test/resources/global-camel-routes.xml     |   7 +
 6 files changed, 316 insertions(+), 5 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
index 94ff0ca..b984ebf 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
@@ -49,6 +49,8 @@ public interface JBPMConstants {
     String CAMEL_ENDPOINT_ID_WI_PARAM = "CamelEndpointId";
     String RESPONSE_WI_PARAM = "Response";
     String MESSAGE_WI_PARAM = "Message";
+    
+    String CAMEL_CONTEXT_BUILDER_KEY = "CamelContextBuilder";
 
     
 }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java
new file mode 100644
index 0000000..badac07
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.jbpm.config;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * Allows to specify alternative configuration for CamelContext
+ */
+public interface CamelContextBuilder {
+
+    /**
+     * Default implementation that allows to simply return <code>DefaultCamelContext</code> instance
+     * @return returns <code>DefaultCamelContext</code> instance
+     */
+    default CamelContext buildCamelContext() {
+        
+        return new DefaultCamelContext();
+    }
+}
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
index 1783b04..f338aed 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
@@ -19,15 +19,21 @@ package org.apache.camel.component.jbpm.server;
 import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.component.jbpm.JBPMConstants;
+import org.apache.camel.component.jbpm.config.CamelContextBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.internal.runtime.manager.InternalRuntimeManager;
+import org.kie.internal.runtime.manager.RuntimeManagerRegistry;
 import org.kie.server.services.api.KieContainerInstance;
 import org.kie.server.services.api.KieServerExtension;
 import org.kie.server.services.api.KieServerRegistry;
@@ -48,14 +54,29 @@ public class CamelKieServerExtension implements KieServerExtension {
     protected boolean managedCamel;
 
     protected Map<String, DefaultCamelContext> camelContexts = new HashMap<>();
+    
+    protected CamelContextBuilder camelContextBuilder;
 
     public CamelKieServerExtension() {
         this.managedCamel = true;
+        this.camelContextBuilder = discoverCamelContextBuilder();
+    }
+    
+    public CamelKieServerExtension(CamelContextBuilder camelContextBuilder) {
+        this.managedCamel = true;
+        this.camelContextBuilder = camelContextBuilder;
     }
 
     public CamelKieServerExtension(DefaultCamelContext camelContext) {
         this.camelContext = camelContext;
         this.managedCamel = false;
+        this.camelContextBuilder = discoverCamelContextBuilder();
+    }
+
+    public CamelKieServerExtension(DefaultCamelContext camelContext, CamelContextBuilder camelContextBuilder) {
+        this.camelContext = camelContext;
+        this.managedCamel = false;
+        this.camelContextBuilder = camelContextBuilder;
     }
 
     @Override
@@ -71,7 +92,7 @@ public class CamelKieServerExtension implements KieServerExtension {
     @Override
     public void init(KieServerImpl kieServer, KieServerRegistry registry) {
         if (this.managedCamel && this.camelContext == null) {
-            this.camelContext = new DefaultCamelContext();
+            this.camelContext = (DefaultCamelContext) buildGlobalContext();
             this.camelContext.setName("KIE Server Camel context");
 
             try (InputStream is = this.getClass().getResourceAsStream("/global-camel-routes.xml")) {
@@ -108,7 +129,7 @@ public class CamelKieServerExtension implements KieServerExtension {
         try (InputStream is = classloader.getResourceAsStream("camel-routes.xml")) {
             if (is != null) {
 
-                DefaultCamelContext context = new DefaultCamelContext();
+                DefaultCamelContext context = (DefaultCamelContext) buildDeploymentContext(id);
                 context.setName("KIE Server Camel context for container " + kieContainerInstance.getContainerId());
 
                 RoutesDefinition routes = context.loadRoutesDefinition(is);
@@ -196,6 +217,14 @@ public class CamelKieServerExtension implements KieServerExtension {
     public String toString() {
         return EXTENSION_NAME + " KIE Server extension";
     }
+    
+    public DefaultCamelContext getCamelContext() {
+        return camelContext;
+    }
+    
+    public CamelContextBuilder getCamelContextBuilder() {
+        return camelContextBuilder;
+    }
 
     protected void annotateKJarRoutes(RoutesDefinition routes, String deploymentId) {
         for (RouteDefinition route : routes.getRoutes()) {
@@ -215,10 +244,44 @@ public class CamelKieServerExtension implements KieServerExtension {
                     }
                     uri.append("deploymentId=").append(deploymentId);
                     from.setUri(uri.toString());
-                }
-
-                System.out.println(from.getUri());
+                }                
             }
         }
     }
+    
+    protected CamelContext buildGlobalContext() {
+        if (camelContextBuilder != null) {
+            return camelContextBuilder.buildCamelContext();
+        }
+        
+        return new CamelContextBuilder(){}.buildCamelContext();
+    }
+    
+    protected CamelContext buildDeploymentContext(String identifier) {
+        
+        InternalRuntimeManager runtimeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(identifier);
+        
+        if (runtimeManager != null) {
+            
+            CamelContextBuilder deploymentContextBuilder = (CamelContextBuilder) runtimeManager.getEnvironment()
+                                                                                        .getEnvironment()
+                                                                                        .get(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY);
+            if (deploymentContextBuilder != null) {
+                return deploymentContextBuilder.buildCamelContext();
+            }
+        }
+        
+        return new CamelContextBuilder(){}.buildCamelContext();
+    }
+    
+    protected CamelContextBuilder discoverCamelContextBuilder() {
+        
+        ServiceLoader<CamelContextBuilder> builders = ServiceLoader.load(CamelContextBuilder.class);
+        Iterator<CamelContextBuilder> it = builders.iterator();
+        if (it.hasNext()) {
+            return it.next();
+        }
+        
+        return null;
+    }
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
new file mode 100644
index 0000000..fbbb7ed
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
@@ -0,0 +1,197 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.jbpm.server;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.when;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.jbpm.JBPMConstants;
+import org.apache.camel.component.jbpm.config.CamelContextBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.KieServices;
+import org.kie.api.runtime.Environment;
+import org.kie.api.runtime.KieContainer;
+import org.kie.internal.runtime.manager.InternalRuntimeManager;
+import org.kie.internal.runtime.manager.RuntimeEnvironment;
+import org.kie.internal.runtime.manager.RuntimeManagerRegistry;
+import org.kie.server.services.api.KieContainerInstance;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CamelKieServerExtensionTest {
+    
+    private String identifier = "test";
+    
+    @Mock
+    InternalRuntimeManager runtimeManager;
+    
+    @Mock
+    RuntimeEnvironment runtimeEnvironment;
+
+    @Mock
+    private KieContainerInstance kieContainerInstance;
+    
+    @Mock
+    private KieContainer kieContainer;
+
+    @After
+    public void cleanup() {
+        RuntimeManagerRegistry.get().remove(identifier);
+    }
+    
+    
+    @Test
+    public void testInit() {
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        extension.init(null, null);
+        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        List<RouteDefinition> globalRestDefinitions = globalCamelContext.getRouteDefinitions();
+        assertThat(globalRestDefinitions.size(), equalTo(1));
+        assertThat(globalCamelContext.getRouteDefinition("unitTestRoute"), is(notNullValue()));
+    }
+    
+    @Test
+    public void testCreateContainer() {
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        final String containerId = "testContainer";
+        
+        when(kieContainerInstance.getKieContainer()).thenReturn(kieContainer);
+        when(kieContainer.getClassLoader()).thenReturn(this.getClass().getClassLoader());
+        
+        extension.createContainer(containerId, kieContainerInstance, new HashMap<String, Object>());
+        
+        CamelContext camelContext = (CamelContext) ServiceRegistry.get().service("testContainer" + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
+        List<RouteDefinition> restDefinitions = camelContext.getRouteDefinitions();
+        assertThat(restDefinitions.size(), equalTo(1));
+        
+        assertThat(camelContext.getRoute("unitTestRoute"), is(notNullValue()));
+    }
+    
+    @Test
+    public void testDefaultSetup() {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        
+        assertNull(extension.getCamelContextBuilder());
+    }
+    
+    @Test
+    public void testDefaultSetupCustomDiscovery() {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension() {
+
+            @Override
+            protected CamelContextBuilder discoverCamelContextBuilder() {
+                return new CamelContextBuilder() {
+
+                    @Override
+                    public CamelContext buildCamelContext() {
+                        // for test purpose return simply null as camel context
+                        return null;
+                    }
+                    
+                };
+            }
+            
+        };
+        
+        assertNotNull(extension.getCamelContextBuilder());
+        assertNull(extension.getCamelContextBuilder().buildCamelContext());
+    }
+    
+    @Test
+    public void testBuildGlobalCamelContext() throws Exception {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        CamelContext context = extension.buildGlobalContext();
+        assertNotNull(context);
+        
+        context.stop();
+    }
+    
+    @Test
+    public void testBuildGlobalCamelContextCustomBuilder() throws Exception {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension(new CamelContextBuilder() {
+
+            @Override
+            public CamelContext buildCamelContext() {
+                // for test purpose return simply null as camel context
+                return null;
+            }
+            
+        });
+        CamelContext context = extension.buildGlobalContext();
+        assertNull(context);        
+    }
+    
+    @Test
+    public void testBuildDeploymentCamelContext() throws Exception {
+        
+        when(runtimeManager.getIdentifier()).thenReturn(identifier);
+        when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
+        
+        Environment environment = KieServices.get().newEnvironment();
+        when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
+        
+        RuntimeManagerRegistry.get().register(runtimeManager);
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        CamelContext context = extension.buildDeploymentContext(identifier);
+        assertNotNull(context);
+        
+        context.stop();
+    }
+    
+    @Test
+    public void testBuildDeploymentCamelContextCustomBuilder() throws Exception {
+        
+        when(runtimeManager.getIdentifier()).thenReturn(identifier);
+        when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
+        
+        Environment environment = KieServices.get().newEnvironment();
+        environment.set(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY, new CamelContextBuilder() {
+
+            @Override
+            public CamelContext buildCamelContext() {
+                // for test purpose return simply null as camel context
+                return null;
+            }
+            
+        });
+        when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
+        
+        RuntimeManagerRegistry.get().register(runtimeManager);
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        CamelContext context = extension.buildDeploymentContext(identifier);
+        assertNull(context);
+        
+    }
+}
diff --git a/components/camel-jbpm/src/test/resources/camel-routes.xml b/components/camel-jbpm/src/test/resources/camel-routes.xml
new file mode 100644
index 0000000..710d40a
--- /dev/null
+++ b/components/camel-jbpm/src/test/resources/camel-routes.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
+  <route id="unitTestRoute">
+    <from id="direct-unitTestRoute" uri="direct:unitTest" />
+    <to uri="log:org.apache.camel.com?level=WARN" />
+  </route>
+</routes>
\ No newline at end of file
diff --git a/components/camel-jbpm/src/test/resources/global-camel-routes.xml b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
new file mode 100644
index 0000000..710d40a
--- /dev/null
+++ b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
+  <route id="unitTestRoute">
+    <from id="direct-unitTestRoute" uri="direct:unitTest" />
+    <to uri="log:org.apache.camel.com?level=WARN" />
+  </route>
+</routes>
\ No newline at end of file