You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2015/02/18 22:46:43 UTC
camel git commit: Created Camel Kura component.
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 <he...@gmail.com>
Authored: Wed Feb 18 22:46:35 2015 +0100
Committer: Henryk Konsek <he...@gmail.com>
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 @@
+<?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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.15-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-kura</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Kura</name>
+ <description>Camel Kura support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.kura</camel.osgi.export.pkg>
+
+ <kura-slf4j.version>1.6.4</kura-slf4j.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-osgi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.birt.runtime</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>3.8.1.v20120830-144521</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${kura-slf4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
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> T service(Class<T> 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 @@
<module>camel-kafka</module>
<module>camel-kestrel</module>
<module>camel-krati</module>
+ <module>camel-kura</module>
<module>camel-ldap</module>
<module>camel-leveldb</module>
<module>camel-linkedin</module>