This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch sandbox/camel-3.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit ad6a796f4c612060f55da2ec337b0b68c23b629c Author: Andrea Cosentino <anco...@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" />