You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/12/13 09:41:34 UTC

[4/4] camel git commit: Moved test from karaf to osgi. This fixes #1336.

Moved test from karaf to osgi. This fixes #1336.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dac56906
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dac56906
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dac56906

Branch: refs/heads/camel-2.18.x
Commit: dac569062759958b8a4c9de7ec2c872502fc6f11
Parents: 05ba679
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 13 10:40:41 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Dec 13 10:41:22 2016 +0100

----------------------------------------------------------------------
 tests/camel-itest-karaf/pom.xml                 |  5 --
 .../org/apache/camel/itest/karaf/bean/Pojo.java | 72 --------------------
 .../CamelJacksonFallbackConverterTest.java      | 60 ----------------
 tests/camel-itest-osgi/pom.xml                  |  5 ++
 .../CamelJacksonFallbackConverterTest.java      | 66 ++++++++++++++++++
 .../test/java/org/apache/camel/itest/Pojo.java  | 72 ++++++++++++++++++++
 .../itest/CamelJacksonFallbackConverterTest.xml | 26 +++++++
 7 files changed, 169 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/pom.xml b/tests/camel-itest-karaf/pom.xml
index f8941e3..e6d1dbe 100644
--- a/tests/camel-itest-karaf/pom.xml
+++ b/tests/camel-itest-karaf/pom.xml
@@ -121,11 +121,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-jackson</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.apache.camel.karaf</groupId>
       <artifactId>apache-camel</artifactId>
       <version>${project.version}</version>

http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java
deleted file mode 100644
index 4468913..0000000
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.itest.karaf.bean;
-
-public class Pojo {
-    private int id;
-    private String name;
-
-    public Pojo(int id, String name) {
-        this.id = id;
-        this.name = name;
-    }
-
-    public Pojo() {
-    }
-    
-    public int getId() {
-        return id;
-    }
-
-    public void setId(int id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (!(o instanceof Pojo)) {
-            return false;
-        }
-
-
-        Pojo pojo = (Pojo) o;
-
-        if (id != pojo.getId()) {
-            return false;
-        }
-        return name != null ? name.equals(pojo.getName()) : pojo.getName() == null;
-
-    }
-
-    @Override
-    public int hashCode() {
-        int result = id;
-        result = 31 * result + (name != null ? name.hashCode() : 0);
-        return result;
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java
deleted file mode 100644
index 136da20..0000000
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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.itest.karaf.converters;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.component.jackson.JacksonConstants;
-import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.itest.karaf.BaseKarafTest;
-import org.apache.camel.itest.karaf.bean.Pojo;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-
-import static org.junit.Assert.assertNotNull;
-
-@RunWith(PaxExam.class)
-public class CamelJacksonFallbackConverterTest extends BaseKarafTest {
-
-    @Configuration
-    public static Option[] configure() {
-        return BaseKarafTest.configure("camel-jackson");
-    }
-
-    @Test
-    public void test() throws Exception {
-        CamelContext context = getOsgiService(bundleContext, CamelContext.class, "(camel.context.name=myCamel)", SERVICE_TIMEOUT);
-        assertNotNull("Cannot find CamelContext with name myCamel", context);
-
-        // enable Jackson json type converter
-        context.getProperties().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true");
-        // allow Jackson json to convert to pojo types also (by default jackson only converts to String and other simple types)
-        context.getProperties().put(JacksonConstants.TYPE_CONVERTER_TO_POJO, "true");
-
-        // test type conversion
-        final Pojo pojo = new Pojo(1337, "Constantine");
-        final DefaultExchange exchange = new DefaultExchange(context);
-        final String string = context.getTypeConverter().mandatoryConvertTo(String.class, exchange, pojo);
-        final Pojo copy = context.getTypeConverter().mandatoryConvertTo(Pojo.class, exchange, string);
-        Assert.assertEquals(pojo, copy);
-    }
-
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-osgi/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/pom.xml b/tests/camel-itest-osgi/pom.xml
index 7ce17ec..f5f93d1 100644
--- a/tests/camel-itest-osgi/pom.xml
+++ b/tests/camel-itest-osgi/pom.xml
@@ -36,6 +36,11 @@
       <artifactId>camel-test-karaf</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jackson</artifactId>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 

http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelJacksonFallbackConverterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelJacksonFallbackConverterTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelJacksonFallbackConverterTest.java
new file mode 100644
index 0000000..84ad9f8
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelJacksonFallbackConverterTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.itest;
+
+import java.net.URL;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.jackson.JacksonConstants;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.karaf.AbstractFeatureTest;
+import org.apache.camel.test.karaf.CamelKarafTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelJacksonFallbackConverterTest extends AbstractFeatureTest {
+
+    @Test
+    public void test() throws Exception {
+        // install the camel blueprint xml file we use in this test
+        URL url = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml", CamelJacksonFallbackConverterTest.class.getClassLoader());
+        installBlueprintAsBundle("CamelJacksonFallbackConverterTest", url, true);
+
+        // lookup Camel from OSGi
+        CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
+
+        // enable Jackson json type converter
+        camel.getProperties().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true");
+        // allow Jackson json to convert to pojo types also (by default jackson only converts to String and other simple types)
+        camel.getProperties().put(JacksonConstants.TYPE_CONVERTER_TO_POJO, "true");
+
+        final Pojo pojo = new Pojo(1337, "Constantine");
+
+        final DefaultExchange exchange = new DefaultExchange(camel);
+        final String string = camel.getTypeConverter().mandatoryConvertTo(String.class, exchange, pojo);
+        LOG.info("POJO -> String: {}", string);
+        final Pojo copy = camel.getTypeConverter().mandatoryConvertTo(Pojo.class, exchange, string);
+        LOG.info("String -> POJO: {}", copy);
+        Assert.assertEquals(pojo, copy);
+    }
+
+    @Configuration
+    public Option[] configure() {
+        return CamelKarafTestSupport.configure("camel-test-karaf", "camel-jackson");
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
new file mode 100644
index 0000000..258774c
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
@@ -0,0 +1,72 @@
+/**
+ * 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.itest;
+
+public class Pojo {
+    private int id;
+    private String name;
+
+    public Pojo(int id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Pojo() {
+    }
+    
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof Pojo)) {
+            return false;
+        }
+
+
+        Pojo pojo = (Pojo) o;
+
+        if (id != pojo.getId()) {
+            return false;
+        }
+        return name != null ? name.equals(pojo.getName()) : pojo.getName() == null;
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id;
+        result = 31 * result + (name != null ? name.hashCode() : 0);
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/dac56906/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml
new file mode 100644
index 0000000..bf8202b
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml
@@ -0,0 +1,26 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint">
+  </camelContext>
+
+</blueprint>