Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2BEFF10CE1 for ; Wed, 18 Feb 2015 21:46:50 +0000 (UTC) Received: (qmail 61623 invoked by uid 500); 18 Feb 2015 21:46:43 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 61569 invoked by uid 500); 18 Feb 2015 21:46:43 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 61560 invoked by uid 99); 18 Feb 2015 21:46:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Feb 2015 21:46:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 79198E0524; Wed, 18 Feb 2015 21:46:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hekonsek@apache.org To: commits@camel.apache.org Message-Id: <747156438251415cb88a5280800e6c0b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: Created Camel Kura component. Date: Wed, 18 Feb 2015 21:46:43 +0000 (UTC) Repository: camel Updated Branches: refs/heads/master db04b50fd -> 471163a66 Created Camel Kura component. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/471163a6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/471163a6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/471163a6 Branch: refs/heads/master Commit: 471163a660459e40869c83b5161c1e7e72d962cc Parents: db04b50 Author: Henryk Konsek Authored: Wed Feb 18 22:46:35 2015 +0100 Committer: Henryk Konsek Committed: Wed Feb 18 22:46:35 2015 +0100 ---------------------------------------------------------------------- components/camel-kura/pom.xml | 70 ++++++++++++++++ .../apache/camel/component/kura/KuraRouter.java | 75 +++++++++++++++++ .../camel/component/kura/KuraRouterTest.java | 88 ++++++++++++++++++++ components/pom.xml | 1 + 4 files changed, 234 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/471163a6/components/camel-kura/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-kura/pom.xml b/components/camel-kura/pom.xml new file mode 100644 index 0000000..3dfd066 --- /dev/null +++ b/components/camel-kura/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + + org.apache.camel + components + 2.15-SNAPSHOT + + + camel-kura + bundle + Camel :: Kura + Camel Kura support + + + org.apache.camel.component.kura + + 1.6.4 + + + + + org.apache.camel + camel-core-osgi + + + org.eclipse.birt.runtime + org.eclipse.osgi + 3.8.1.v20120830-144521 + + + org.slf4j + slf4j-api + ${kura-slf4j.version} + + + + junit + junit + test + + + org.mockito + mockito-core + test + + + + http://git-wip-us.apache.org/repos/asf/camel/blob/471163a6/components/camel-kura/src/main/java/org/apache/camel/component/kura/KuraRouter.java ---------------------------------------------------------------------- diff --git a/components/camel-kura/src/main/java/org/apache/camel/component/kura/KuraRouter.java b/components/camel-kura/src/main/java/org/apache/camel/component/kura/KuraRouter.java new file mode 100644 index 0000000..2a3bc34 --- /dev/null +++ b/components/camel-kura/src/main/java/org/apache/camel/component/kura/KuraRouter.java @@ -0,0 +1,75 @@ +/** + * 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.kura; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.core.osgi.OsgiDefaultCamelContext; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class KuraRouter extends RouteBuilder implements BundleActivator { + + protected final Logger log = LoggerFactory.getLogger(getClass()); + + protected BundleContext bundleContext; + + protected CamelContext camelContext; + + protected ProducerTemplate producerTemplate; + + @Override + public void start(BundleContext bundleContext) throws Exception { + this.bundleContext = bundleContext; + log.debug("Initializing bundle {}.", bundleContext.getBundle().getBundleId()); + camelContext = createCamelContext(); + camelContext.addRoutes(this); + beforeStart(camelContext); + camelContext.start(); + producerTemplate = camelContext.createProducerTemplate(); + log.debug("Bundle {} started.", bundleContext.getBundle().getBundleId()); + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + log.debug("Stopping bundle {}.", bundleContext.getBundle().getBundleId()); + camelContext.stop(); + log.debug("Bundle {} stopped.", bundleContext.getBundle().getBundleId()); + } + + // Callbacks + + protected CamelContext createCamelContext() { + return new OsgiDefaultCamelContext(bundleContext); + } + + protected void beforeStart(CamelContext camelContext) { + log.debug("Empty KuraRouter CamelContext before start configuration - skipping."); + } + + // API Helpers + + protected T service(Class serviceType) { + ServiceReference reference = bundleContext.getServiceReference(serviceType); + return (T) bundleContext.getService(reference); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/471163a6/components/camel-kura/src/test/java/org/apache/camel/component/kura/KuraRouterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-kura/src/test/java/org/apache/camel/component/kura/KuraRouterTest.java b/components/camel-kura/src/test/java/org/apache/camel/component/kura/KuraRouterTest.java new file mode 100644 index 0000000..ba03eef --- /dev/null +++ b/components/camel-kura/src/test/java/org/apache/camel/component/kura/KuraRouterTest.java @@ -0,0 +1,88 @@ +/** + * 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.kura; + +import org.apache.camel.CamelContext; +import org.apache.camel.ServiceStatus; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.BundleContext; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; + +public class KuraRouterTest extends Assert { + + TestKuraRouter router = new TestKuraRouter(); + + BundleContext bundleContext = mock(BundleContext.class, RETURNS_DEEP_STUBS); + + @Before + public void before() throws Exception { + given(bundleContext.getBundle().getVersion().toString()).willReturn("version"); + + router.start(bundleContext); + } + + @After + public void after() throws Exception { + router.start(bundleContext); + } + + @Test + public void shouldCloseCamelContext() throws Exception { + // When + router.stop(bundleContext); + + // Then + Assert.assertEquals(ServiceStatus.Stopped, router.camelContext.getStatus()); + } + + @Test + public void shouldStartCamelContext() throws Exception { + // Given + String message = "foo"; + MockEndpoint mockEndpoint = router.camelContext.getEndpoint("mock:test", MockEndpoint.class); + mockEndpoint.expectedBodiesReceived(message); + + // When + router.producerTemplate.sendBody("direct:start", message); + + // Then + mockEndpoint.assertIsSatisfied(); + } + +} + +class TestKuraRouter extends KuraRouter { + + @Override + public void configure() throws Exception { + from("direct:start").to("mock:test"); + } + + @Override + protected CamelContext createCamelContext() { + return new DefaultCamelContext(); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/471163a6/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index fd299a3..29a54ea 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -143,6 +143,7 @@ camel-kafka camel-kestrel camel-krati + camel-kura camel-ldap camel-leveldb camel-linkedin