You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by io...@apache.org on 2011/12/02 18:17:16 UTC

svn commit: r1209592 - in /camel/trunk/tests/camel-itest-osgi/src/test: java/org/apache/camel/itest/osgi/xstream/ resources/org/apache/camel/itest/osgi/xstream/

Author: iocanel
Date: Fri Dec  2 17:17:15 2011
New Revision: 1209592

URL: http://svn.apache.org/viewvc?rev=1209592&view=rev
Log:
[CAMEL-4736] Added camel-xstream osgi itest that uses the blueprint.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/SampleObject.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamBlueprintRouteTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamRouteBuilder.java
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/xstream/
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/xstream/blueprintCamelContext.xml

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/SampleObject.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/SampleObject.java?rev=1209592&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/SampleObject.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/SampleObject.java Fri Dec  2 17:17:15 2011
@@ -0,0 +1,70 @@
+/**
+ * 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.osgi.xstream;
+
+public class SampleObject {
+
+    String id;
+    String value;
+
+    public SampleObject() {
+    }
+
+    public SampleObject(String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SampleObject that = (SampleObject) o;
+
+        if (!id.equals(that.id)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return id.hashCode();
+    }
+}

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamBlueprintRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamBlueprintRouteTest.java?rev=1209592&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamBlueprintRouteTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamBlueprintRouteTest.java Fri Dec  2 17:17:15 2011
@@ -0,0 +1,90 @@
+/**
+ * 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.osgi.xstream;
+
+import java.io.InputStream;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.itest.osgi.blueprint.OSGiBlueprintTestSupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Constants;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+
+@RunWith(JUnit4TestRunner.class)
+public class XstreamBlueprintRouteTest extends OSGiBlueprintTestSupport {
+
+    @Test
+    public void testUnmarshal() throws Exception {
+        getInstalledBundle("CamelBlueprintXstreamTestBundle").start();
+        BlueprintContainer ctn = getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=CamelBlueprintXstreamTestBundle)", 10000);
+        CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.symbolicname=CamelBlueprintXstreamTestBundle)", 10000);
+
+        MockEndpoint mock = (MockEndpoint) ctx.getEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        String body = "<org.apache.camel.itest.osgi.xstream.SampleObject>\n"
+                + "    <id>1</id>\n"
+                + "    <value>test</value>\n"
+                + "</org.apache.camel.itest.osgi.xstream.SampleObject>";
+
+        ProducerTemplate template = ctx.createProducerTemplate();
+        template.sendBody("direct:start", body);
+        mock.assertIsSatisfied();
+        Object result = mock.getReceivedExchanges().get(0).getIn().getBody();
+        assertEquals(new SampleObject("1"), result);
+    }
+
+    @Configuration
+    public static Option[] configure() throws Exception {
+
+        Option[] options = combine(
+                getDefaultCamelKarafOptions(),
+                new Customizer() {
+                    @Override
+                    public InputStream customizeTestProbe(InputStream testProbe) {
+                        return modifyBundle(testProbe)
+                                .add(SampleObject.class)
+                                .add(XstreamRouteBuilder.class)
+                                .add("OSGI-INF/blueprint/test.xml", XstreamBlueprintRouteTest.class.getResource("blueprintCamelContext.xml"))
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "CamelBlueprintXstreamTestBundle")
+                                .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+                                .build();
+                    }
+                },
+                // using the features to install the camel components
+                scanFeatures(getCamelKarafFeatureUrl(), "xml-specs-api", "camel-blueprint", "camel-xstream"),
+                //vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+                felix(), equinox());
+
+        return options;
+    }
+
+}

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamRouteBuilder.java?rev=1209592&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamRouteBuilder.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/xstream/XstreamRouteBuilder.java Fri Dec  2 17:17:15 2011
@@ -0,0 +1,31 @@
+/**
+ * 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.osgi.xstream;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class XstreamRouteBuilder extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+
+
+        from("direct:start").unmarshal().xstream()
+                .to("mock:result");
+    }
+}
\ No newline at end of file

Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/xstream/blueprintCamelContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/xstream/blueprintCamelContext.xml?rev=1209592&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/xstream/blueprintCamelContext.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/xstream/blueprintCamelContext.xml Fri Dec  2 17:17:15 2011
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed 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" default-activation="lazy">
+
+
+    <bean id="routeBuilder" class="org.apache.camel.itest.osgi.xstream.XstreamRouteBuilder" />
+
+    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+        <routeBuilder ref="routeBuilder" />
+    </camelContext>
+
+</blueprint>