This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit f999ea58e3225e5890ea8ab200a6aca26ac3d2aa Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed May 29 10:13:48 2019 +0200 CAMEL-10324 - Camel-CBOR added to kit and Spring tests --- .../component/cbor/SpringCBORDataFormatTest.java | 73 ++++++++++++++++++++++ .../component/cbor/SpringCBORDataFormatTest.xml | 61 ++++++++++++++++++ .../org/apache/camel/builder/DataFormatClause.java | 20 ++++++ .../org/apache/camel/model/MarshalDefinition.java | 2 + .../apache/camel/model/UnmarshalDefinition.java | 2 + .../model/dataformat/DataFormatsDefinition.java | 1 + 6 files changed, 159 insertions(+) diff --git a/components/camel-cbor/src/test/java/org/apache/camel/component/cbor/SpringCBORDataFormatTest.java b/components/camel-cbor/src/test/java/org/apache/camel/component/cbor/SpringCBORDataFormatTest.java new file mode 100644 index 0000000..6816b18 --- /dev/null +++ b/components/camel-cbor/src/test/java/org/apache/camel/component/cbor/SpringCBORDataFormatTest.java @@ -0,0 +1,73 @@ +/* + * 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.cbor; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SpringCBORDataFormatTest extends CamelSpringTestSupport { + + @Test + public void testMarshalAndUnmarshalMap() throws Exception { + Map<String, Object> in = new HashMap<>(); + in.put("name", "Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reverse"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(Map.class); + mock.message(0).body().isEqualTo(in); + + Object marshalled = template.requestBody("direct:in", in); + + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalAuthor() throws Exception { + Author auth = new Author(); + auth.setName("Don"); + auth.setSurname("Winslow"); + + MockEndpoint mock = getMockEndpoint("mock:reverse-auth"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(Author.class); + + Object marshalled = template.requestBody("direct:in-auth", auth); + + template.sendBody("direct:back-auth", marshalled); + + Author authReturned = mock.getExchanges().get(0).getIn().getBody(Author.class); + assertEquals("Don", authReturned.getName()); + assertEquals("Winslow", authReturned.getSurname()); + + mock.assertIsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/cbor/SpringCBORDataFormatTest.xml"); + } + +} diff --git a/components/camel-cbor/src/test/resources/org/apache/camel/component/cbor/SpringCBORDataFormatTest.xml b/components/camel-cbor/src/test/resources/org/apache/camel/component/cbor/SpringCBORDataFormatTest.xml new file mode 100644 index 0000000..90fb146 --- /dev/null +++ b/components/camel-cbor/src/test/resources/org/apache/camel/component/cbor/SpringCBORDataFormatTest.xml @@ -0,0 +1,61 @@ +<?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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: e1 --> + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + + <!-- we define the json jackson data formats to be used --> + <dataFormats> + <cbor id="test" unmarshalTypeName="java.util.Map"></cbor> + <cbor id="auth" unmarshalTypeName="org.apache.camel.component.cbor.Author"></cbor> + </dataFormats> + + <route> + <from uri="direct:in"/> + <marshal><custom ref="test"/></marshal> + </route> + + <route> + <from uri="direct:back"/> + <unmarshal><custom ref="test"/></unmarshal> + <to uri="mock:reverse"/> + </route> + + <route> + <from uri="direct:in-auth"/> + <marshal><custom ref="auth"/></marshal> + </route> + + <route> + <from uri="direct:back-auth"/> + <unmarshal><custom ref="auth"/></unmarshal> + <to uri="mock:reverse-auth"/> + </route> + + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java b/core/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java index 1a81db7..aa403b8 100644 --- a/core/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java +++ b/core/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java @@ -31,6 +31,7 @@ import org.apache.camel.model.dataformat.BeanioDataFormat; import org.apache.camel.model.dataformat.BindyDataFormat; import org.apache.camel.model.dataformat.BindyType; import org.apache.camel.model.dataformat.BoonDataFormat; +import org.apache.camel.model.dataformat.CBORDataFormat; import org.apache.camel.model.dataformat.CsvDataFormat; import org.apache.camel.model.dataformat.CustomDataFormat; import org.apache.camel.model.dataformat.FhirJsonDataFormat; @@ -204,6 +205,25 @@ public class DataFormatClause<T extends ProcessorDefinition<?>> { boon.setUnmarshalType(classType); return dataFormat(boon); } + + /** + * Uses the CBOR data format + */ + public T cbor() { + return dataFormat(new CBORDataFormat()); + } + + /** + * Uses the CBOR data format + * + * @param unmarshalType + * unmarshal type for cbor type + */ + public T cbor(Class<?> unmarshalType) { + CBORDataFormat cborDataFormat = new CBORDataFormat(); + cborDataFormat.setUnmarshalType(unmarshalType); + return dataFormat(cborDataFormat); + } /** * Uses the CSV data format diff --git a/core/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java index db6e473..36a3ae4 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java @@ -29,6 +29,7 @@ import org.apache.camel.model.dataformat.Base64DataFormat; import org.apache.camel.model.dataformat.BeanioDataFormat; import org.apache.camel.model.dataformat.BindyDataFormat; import org.apache.camel.model.dataformat.BoonDataFormat; +import org.apache.camel.model.dataformat.CBORDataFormat; import org.apache.camel.model.dataformat.CryptoDataFormat; import org.apache.camel.model.dataformat.CsvDataFormat; import org.apache.camel.model.dataformat.CustomDataFormat; @@ -79,6 +80,7 @@ public class MarshalDefinition extends NoOutputDefinition<MarshalDefinition> { @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class), @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class), @XmlElement(required = false, name = "boon", type = BoonDataFormat.class), + @XmlElement(required = false, name = "cbor", type = CBORDataFormat.class), @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class), @XmlElement(required = false, name = "csv", type = CsvDataFormat.class), @XmlElement(required = false, name = "custom", type = CustomDataFormat.class), diff --git a/core/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java index 2dfd2e2..6c90046 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java @@ -29,6 +29,7 @@ import org.apache.camel.model.dataformat.Base64DataFormat; import org.apache.camel.model.dataformat.BeanioDataFormat; import org.apache.camel.model.dataformat.BindyDataFormat; import org.apache.camel.model.dataformat.BoonDataFormat; +import org.apache.camel.model.dataformat.CBORDataFormat; import org.apache.camel.model.dataformat.CryptoDataFormat; import org.apache.camel.model.dataformat.CsvDataFormat; import org.apache.camel.model.dataformat.CustomDataFormat; @@ -79,6 +80,7 @@ public class UnmarshalDefinition extends NoOutputDefinition<UnmarshalDefinition> @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class), @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class), @XmlElement(required = false, name = "boon", type = BoonDataFormat.class), + @XmlElement(required = false, name = "cbor", type = CBORDataFormat.class), @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class), @XmlElement(required = false, name = "csv", type = CsvDataFormat.class), @XmlElement(required = false, name = "custom", type = CustomDataFormat.class), diff --git a/core/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java index 19d2672..139173c 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java @@ -46,6 +46,7 @@ public class DataFormatsDefinition { @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class), @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class), @XmlElement(required = false, name = "boon", type = BoonDataFormat.class), + @XmlElement(required = false, name = "cbor", type = CBORDataFormat.class), @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class), @XmlElement(required = false, name = "csv", type = CsvDataFormat.class), @XmlElement(required = false, name = "custom", type = CustomDataFormat.class),