Repository: camel Updated Branches: refs/heads/master 5fc96ef45 -> a69028d0e
http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonIncludeNotNulllTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonIncludeNotNulllTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonIncludeNotNulllTest.java new file mode 100644 index 0000000..9ba76d2 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonIncludeNotNulllTest.java @@ -0,0 +1,54 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonIncludeNotNulllTest extends CamelTestSupport { + + @Test + public void testMmarshalPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:marshal"); + mock.expectedMessageCount(1); + mock.message(0).body(String.class).isEqualTo("<TestOtherPojo><name>Camel</name></TestOtherPojo>"); + + TestOtherPojo pojo = new TestOtherPojo(); + pojo.setName("Camel"); + + template.sendBody("direct:marshal", pojo); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + format.setInclude("NON_NULL"); + + from("direct:marshal").marshal(format).to("mock:marshal"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJAXBAnnotationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJAXBAnnotationTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJAXBAnnotationTest.java new file mode 100644 index 0000000..f5c0ac5 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJAXBAnnotationTest.java @@ -0,0 +1,65 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonJAXBAnnotationTest extends CamelTestSupport { + + @Test + public void testMarshalJAXBObject() throws Exception { + TestJAXBPojo in = new TestJAXBPojo(); + in.setName("Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestJAXBPojo.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPojo", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<XMLPojo><PojoName>Camel</PojoName></XMLPojo>", marshalledAsString); + + template.sendBody("direct:backPojo", marshalled); + + mock.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + + from("direct:in").marshal(format); + from("direct:back").unmarshal(format).to("mock:reverse"); + + JacksonXMLDataFormat formatPojo = new JacksonXMLDataFormat(TestJAXBPojo.class); + + from("direct:inPojo").marshal(formatPojo); + from("direct:backPojo").unmarshal(formatPojo).to("mock:reversePojo"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJsonDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJsonDataFormatTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJsonDataFormatTest.java new file mode 100644 index 0000000..45e3ba9 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonJsonDataFormatTest.java @@ -0,0 +1,41 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.JsonLibrary; + +public class JacksonJsonDataFormatTest extends JacksonMarshalTest { + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:in").marshal().jacksonxml(); + from("direct:back").unmarshal().jacksonxml().to("mock:reverse"); + + from("direct:inPretty").marshal().jacksonxml(true); + from("direct:backPretty").unmarshal().jacksonxml().to("mock:reverse"); + + from("direct:inPojo").marshal().jacksonxml(); + from("direct:backPojo").unmarshal().jacksonxml(TestPojo.class).to("mock:reversePojo"); + } + }; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalAllowJMSTypeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalAllowJMSTypeTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalAllowJMSTypeTest.java new file mode 100644 index 0000000..2422265 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalAllowJMSTypeTest.java @@ -0,0 +1,56 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonMarshalAllowJMSTypeTest extends CamelTestSupport { + + @Test + public void testUnmarshalPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojo.class); + + String json = "<pojo name=\"Camel\"/>"; + template.sendBodyAndHeader("direct:backPojo", json, "JMSType", TestPojo.class.getName()); + + assertMockEndpointsSatisfied(); + + TestPojo pojo = mock.getReceivedExchanges().get(0).getIn().getBody(TestPojo.class); + assertNotNull(pojo); + assertEquals("Camel", pojo.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + format.setAllowJmsType(true); + + from("direct:backPojo").unmarshal(format).to("mock:reversePojo"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalTest.java new file mode 100644 index 0000000..998a2e0 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalTest.java @@ -0,0 +1,112 @@ +/** + * 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.jacksonxml; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonMarshalTest extends CamelTestSupport { + + @Test + public void testMarshalAndUnmarshalMap() throws Exception { + Map<String, Object> in = new HashMap<String, Object>(); + in.put("name", "Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reverse"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(Map.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:in", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<HashMap><name>Camel</name></HashMap>", marshalledAsString); + + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalMapWithPrettyPrint() throws Exception { + Map<String, Object> in = new HashMap<String, Object>(); + in.put("name", "Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reverse"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(Map.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPretty", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + String expected = "<HashMap>\n <name>Camel</name>\n</HashMap>"; + assertEquals(expected, marshalledAsString); + + template.sendBody("direct:backPretty", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalPojo() throws Exception { + TestPojo in = new TestPojo(); + in.setName("Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojo.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPojo", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<TestPojo><name>Camel</name></TestPojo>", marshalledAsString); + + template.sendBody("direct:backPojo", marshalled); + + mock.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + + from("direct:in").marshal(format); + from("direct:back").unmarshal(format).to("mock:reverse"); + + JacksonXMLDataFormat prettyPrintDataFormat = new JacksonXMLDataFormat(); + prettyPrintDataFormat.setPrettyPrint(true); + + from("direct:inPretty").marshal(prettyPrintDataFormat); + from("direct:backPretty").unmarshal(prettyPrintDataFormat).to("mock:reverse"); + + JacksonXMLDataFormat formatPojo = new JacksonXMLDataFormat(TestPojo.class); + + from("direct:inPojo").marshal(formatPojo); + from("direct:backPojo").unmarshal(formatPojo).to("mock:reversePojo"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalListTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalListTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalListTest.java new file mode 100644 index 0000000..9c418b5 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalListTest.java @@ -0,0 +1,83 @@ +/** + * 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.jacksonxml; + +import java.util.List; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonMarshalUnmarshalListTest extends CamelTestSupport { + + @Test + public void testUnmarshalListPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(List.class); + + String json = "<list><pojo name=\"Camel\"/><pojo name=\"World\"/></list>"; + template.sendBody("direct:backPojo", json); + + assertMockEndpointsSatisfied(); + + List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertNotNull(list); + assertEquals(2, list.size()); + + TestPojo pojo = (TestPojo) list.get(0); + assertEquals("Camel", pojo.getName()); + pojo = (TestPojo) list.get(1); + assertEquals("World", pojo.getName()); + } + + @Test + public void testUnmarshalListPojoOneElement() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(List.class); + + String json = "<list><pojo name=\"Camel\"/></list>"; + template.sendBody("direct:backPojo", json); + + assertMockEndpointsSatisfied(); + + List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertNotNull(list); + assertEquals(1, list.size()); + + TestPojo pojo = (TestPojo) list.get(0); + assertEquals("Camel", pojo.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(TestPojo.class); + format.useList(); + + from("direct:backPojo").unmarshal(format).to("mock:reversePojo"); + + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java new file mode 100644 index 0000000..61436e3 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalUnmarshalTypeHeaderTest.java @@ -0,0 +1,57 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jacksonxml.JacksonXMLConstants; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonMarshalUnmarshalTypeHeaderTest extends CamelTestSupport { + + @Test + public void testUnmarshalPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojo.class); + + String json = "<pojo name=\"Camel\"/>"; + template.sendBodyAndHeader("direct:backPojo", json, JacksonXMLConstants.UNMARSHAL_TYPE, TestPojo.class.getName()); + + assertMockEndpointsSatisfied(); + + TestPojo pojo = mock.getReceivedExchanges().get(0).getIn().getBody(TestPojo.class); + assertNotNull(pojo); + assertEquals("Camel", pojo.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + + from("direct:backPojo").unmarshal(format).to("mock:reversePojo"); + + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalViewTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalViewTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalViewTest.java new file mode 100644 index 0000000..40bf4ca --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalViewTest.java @@ -0,0 +1,83 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.dataformat.JsonLibrary; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonMarshalViewTest extends CamelTestSupport { + + @Test + public void testMarshalAndUnmarshalPojoWithView() throws Exception { + + TestPojoView in = new TestPojoView(); + + MockEndpoint mock = getMockEndpoint("mock:reversePojoAgeView"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojoView.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPojoAgeView", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<TestPojoView><age>30</age><height>190</height></TestPojoView>", marshalledAsString); + + template.sendBody("direct:backPojoAgeView", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalPojoWithAnotherView() throws Exception { + + TestPojoView in = new TestPojoView(); + + MockEndpoint mock = getMockEndpoint("mock:reversePojoWeightView"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojoView.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPojoWeightView", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<TestPojoView><height>190</height><weight>70</weight></TestPojoView>", marshalledAsString); + + template.sendBody("direct:backPojoWeightView", marshalled); + + mock.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + + // START SNIPPET: format + from("direct:inPojoAgeView").marshal().jacksonxml(TestPojoView.class, Views.Age.class); + // END SNIPPET: format + from("direct:backPojoAgeView").unmarshal().jacksonxml(TestPojoView.class).to("mock:reversePojoAgeView"); + + from("direct:inPojoWeightView").marshal().jacksonxml(TestPojoView.class, Views.Weight.class); + from("direct:backPojoWeightView").unmarshal().jacksonxml(TestPojoView.class).to("mock:reversePojoWeightView"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleRefTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleRefTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleRefTest.java new file mode 100644 index 0000000..30e3f77 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleRefTest.java @@ -0,0 +1,46 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; + +public class JacksonModuleRefTest extends JacksonModuleTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("myJacksonModule", new MyModule()); + return jndi; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + format.setInclude("NON_NULL"); + format.setModuleRefs("myJacksonModule"); + + from("direct:marshal").marshal(format).to("mock:marshal"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleTest.java new file mode 100644 index 0000000..af3dd4f --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonModuleTest.java @@ -0,0 +1,56 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonModuleTest extends CamelTestSupport { + + @Test + public void testCustomModule() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:marshal"); + mock.expectedMessageCount(1); + mock.message(0).body(String.class).isEqualTo("<TestOtherPojo><my-name>Camel</my-name><my-country>Denmark</my-country></TestOtherPojo>"); + + TestOtherPojo pojo = new TestOtherPojo(); + pojo.setName("Camel"); + pojo.setCountry("Denmark"); + + template.sendBody("direct:marshal", pojo); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + JacksonXMLDataFormat format = new JacksonXMLDataFormat(); + format.setInclude("NON_NULL"); + format.setModuleClassNames("org.apache.camel.component.jacksonxml.MyModule"); + + from("direct:marshal").marshal(format).to("mock:marshal"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonNameBindingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonNameBindingTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonNameBindingTest.java new file mode 100644 index 0000000..e5fefdc --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonNameBindingTest.java @@ -0,0 +1,69 @@ +/** + * 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.jacksonxml; + +import javax.naming.Context; + +import org.apache.camel.Endpoint; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.processor.binding.DataFormatBinding; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonNameBindingTest extends CamelTestSupport { + protected Endpoint boundEndpoint; + protected MockEndpoint results; + + @Test + public void testMarshalAndUnmarshalPojo() throws Exception { + TestPojo in = new TestPojo(); + in.setName("Camel"); + + results.expectedMessageCount(1); + results.message(0).body().isInstanceOf(TestPojo.class); + results.message(0).body().equals(in); + + template.sendBody("direct:start", in); + results.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + results = getMockEndpoint("mock:results"); + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + // lets use the URI to associate the binding + // though it would be cleaner to use a DSL... + boundEndpoint = endpoint("binding:jackson:file:target/queue"); + + from("direct:start").to(boundEndpoint).to("file:target/copyOfMessages"); + from(boundEndpoint).to(results); + } + }; + } + + @Override + protected Context createJndiContext() throws Exception { + Context context = super.createJndiContext(); + JacksonXMLDataFormat format = new JacksonXMLDataFormat(TestPojo.class); + context.bind("jackson", new DataFormatBinding(format)); + return context; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonObjectListSplitTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonObjectListSplitTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonObjectListSplitTest.java new file mode 100644 index 0000000..fc53e7b --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonObjectListSplitTest.java @@ -0,0 +1,63 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class JacksonObjectListSplitTest extends CamelTestSupport { + @Test + public void testJackson() throws InterruptedException { + getMockEndpoint("mock:result").expectedMessageCount(2); + getMockEndpoint("mock:result").expectedMessagesMatches(body().isInstanceOf(DummyObject.class)); + + template.sendBody("direct:start", "<list><pojo dummy=\"value1\"/><pojo dummy=\"value2\"/></list>"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // you can specify the pojo class type for unmarshal the jason file + JacksonXMLDataFormat format = new JacksonXMLDataFormat(DummyObject.class); + format.useList(); + from("direct:start").unmarshal(format).split(body()).to("mock:result"); + } + }; + } + + public static class DummyObject { + + private String dummy; + + public DummyObject() { + } + + public String getDummy() { + return dummy; + } + + public void setDummy(String dummy) { + this.dummy = dummy; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/ListJacksonUnmarshalDTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/ListJacksonUnmarshalDTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/ListJacksonUnmarshalDTest.java new file mode 100644 index 0000000..d535aa2 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/ListJacksonUnmarshalDTest.java @@ -0,0 +1,34 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.builder.RouteBuilder; + +public class ListJacksonUnmarshalDTest extends JacksonMarshalUnmarshalListTest { + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + from("direct:backPojo").unmarshal(new ListJacksonXMLDataFormat(TestPojo.class)).to("mock:reversePojo"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/MyModule.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/MyModule.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/MyModule.java new file mode 100644 index 0000000..02d999b --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/MyModule.java @@ -0,0 +1,45 @@ +/** + * 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.jacksonxml; + +import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; + +public class MyModule extends Module { + + @Override + public String getModuleName() { + return "MyModule"; + } + + @Override + public Version version() { + return Version.unknownVersion(); + } + + @Override + public void setupModule(SetupContext context) { + context.setNamingStrategy(new PropertyNamingStrategy.PropertyNamingStrategyBase() { + @Override + public String translate(String propertyName) { + return "my-" + propertyName; + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonEnableFeatureTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonEnableFeatureTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonEnableFeatureTest.java new file mode 100644 index 0000000..dec3f0b --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonEnableFeatureTest.java @@ -0,0 +1,44 @@ +/** + * 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.jacksonxml; + +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version + */ +public class SpringJacksonEnableFeatureTest extends CamelSpringTestSupport { + + @Test + public void testMarshal() throws Exception { + TestPojoView in = new TestPojoView(); + + Object marshalled = template.requestBody("direct:in", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + // we enable the wrap root type feature so we should have TestPojoView + assertEquals("<TestPojoView><age>30</age><height>190</height><weight>70</weight></TestPojoView>", marshalledAsString); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/jackson/SpringJacksonEnableFeatureTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.java new file mode 100644 index 0000000..a33c10d --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.java @@ -0,0 +1,114 @@ +/** + * 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.jacksonxml; + +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; + +/** + * @version + */ +public class SpringJacksonJsonDataFormatTest extends CamelSpringTestSupport { + + @Test + public void testMarshalAndUnmarshalMap() throws Exception { + Map<String, Object> in = new HashMap<String, Object>(); + in.put("name", "Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reverse"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(Map.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:in", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<HashMap><name>Camel</name></HashMap>", marshalledAsString); + + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalMapWithPrettyPrint() throws Exception { + Map<String, Object> in = new HashMap<String, Object>(); + in.put("name", "Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reverse"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(Map.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPretty", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + String expected = "<HashMap>\n <name>Camel</name>\n</HashMap>"; + assertEquals(expected, marshalledAsString); + + template.sendBody("direct:back", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalPojo() throws Exception { + TestPojo in = new TestPojo(); + in.setName("Camel"); + + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojo.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inPojo", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<TestPojo><name>Camel</name></TestPojo>", marshalledAsString); + + template.sendBody("direct:backPojo", marshalled); + + mock.assertIsSatisfied(); + } + + @Test + public void testMarshalAndUnmarshalAgeView() throws Exception { + TestPojoView in = new TestPojoView(); + + MockEndpoint mock = getMockEndpoint("mock:reverseAgeView"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojoView.class); + mock.message(0).body().equals(in); + + Object marshalled = template.requestBody("direct:inAgeView", in); + String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); + assertEquals("<TestPojoView><age>30</age><height>190</height><weight>70</weight></TestPojoView>", marshalledAsString); + + template.sendBody("direct:backAgeView", marshalled); + + mock.assertIsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonMarshalUnmarshalListTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonMarshalUnmarshalListTest.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonMarshalUnmarshalListTest.java new file mode 100644 index 0000000..01750a9 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/SpringJacksonMarshalUnmarshalListTest.java @@ -0,0 +1,77 @@ +/** + * 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.jacksonxml; + +import java.util.List; + +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; + +/** + * @version + */ +public class SpringJacksonMarshalUnmarshalListTest extends CamelSpringTestSupport { + + @Test + public void testUnmarshalListPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(List.class); + + String json = "<list><pojo name=\"Camel\"/><pojo name=\"World\"/></list>"; + template.sendBody("direct:backPojo", json); + + assertMockEndpointsSatisfied(); + + List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertNotNull(list); + assertEquals(2, list.size()); + + TestPojo pojo = (TestPojo) list.get(0); + assertEquals("Camel", pojo.getName()); + pojo = (TestPojo) list.get(1); + assertEquals("World", pojo.getName()); + } + + @Test + public void testUnmarshalListPojoOneElement() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:reversePojo"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(List.class); + + String json = "<list><pojo name=\"Camel\"/></list>"; + template.sendBody("direct:backPojo", json); + + assertMockEndpointsSatisfied(); + + List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertNotNull(list); + assertEquals(1, list.size()); + + TestPojo pojo = (TestPojo) list.get(0); + assertEquals("Camel", pojo.getName()); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestJAXBPojo.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestJAXBPojo.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestJAXBPojo.java new file mode 100644 index 0000000..2291d55 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestJAXBPojo.java @@ -0,0 +1,50 @@ +/** + * 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.jacksonxml; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "XMLPojo") +public class TestJAXBPojo { + + @XmlElement(name = "PojoName") + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object obj) { + return this.name.equals(((TestPojo) obj).getName()); + } + + @Override + public int hashCode() { + return name != null ? name.hashCode() : 0; + } + + @Override + public String toString() { + return "TestJAXBPojo[" + name + "]"; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestOtherPojo.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestOtherPojo.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestOtherPojo.java new file mode 100644 index 0000000..3daeebc --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestOtherPojo.java @@ -0,0 +1,40 @@ +/** + * 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.jacksonxml; + +public class TestOtherPojo { + + private String name; + private String country; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojo.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojo.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojo.java new file mode 100644 index 0000000..4ca66c0 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojo.java @@ -0,0 +1,45 @@ +/** + * 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.jacksonxml; + +public class TestPojo { + + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object obj) { + return this.name.equals(((TestPojo) obj).getName()); + } + + @Override + public int hashCode() { + return name != null ? name.hashCode() : 0; + } + + @Override + public String toString() { + return "TestPojo[" + name + "]"; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojoView.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojoView.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojoView.java new file mode 100644 index 0000000..8535dae --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojoView.java @@ -0,0 +1,56 @@ +/** + * 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.jacksonxml; + +import com.fasterxml.jackson.annotation.JsonView; + +public class TestPojoView { + + //START SNIPPET: jsonview + @JsonView(Views.Age.class) + private int age = 30; + + private int height = 190; + + @JsonView(Views.Weight.class) + private int weight = 70; + //END SNIPPET: jsonview + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/Views.java ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/Views.java b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/Views.java new file mode 100644 index 0000000..ccbcc12 --- /dev/null +++ b/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/Views.java @@ -0,0 +1,25 @@ +/** + * 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.jacksonxml; + +//START SNIPPET: marker +public class Views { + + static class Age { } + static class Weight { } +} +//END SNIPPET: marker http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/resources/log4j.properties b/components/camel-jacksonxml/src/test/resources/log4j.properties new file mode 100644 index 0000000..52125b6 --- /dev/null +++ b/components/camel-jacksonxml/src/test/resources/log4j.properties @@ -0,0 +1,36 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# +# The logging properties used during tests.. +# +log4j.rootLogger=INFO, file + +# uncomment this to turn on debug of camel +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.file.file=target/camel-jackson-test.log +log4j.appender.file.append=true http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonEnableFeatureTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonEnableFeatureTest.xml b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonEnableFeatureTest.xml new file mode 100644 index 0000000..ff8cab8 --- /dev/null +++ b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonEnableFeatureTest.xml @@ -0,0 +1,39 @@ +<?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 + "> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + + <dataFormats> + <jacksonxml id="jack" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojo" + enableFeatures="WRAP_ROOT_VALUE"/> + </dataFormats> + + <route> + <from uri="direct:in"/> + <marshal ref="jack"/> + </route> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml new file mode 100644 index 0000000..3d38860 --- /dev/null +++ b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml @@ -0,0 +1,80 @@ +<?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> + <!-- this uses the default unmarshal type that is a Map based --> + <jacksonxml id="jack" /> + <jacksonxml id="pretty" prettyPrint="true"/> + <!-- and this one uses our own TestPojo class as unmarshal type --> + <jacksonxml id="pojo" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojo"/> + <!-- in addition to our own TestPojoView class we make use of the jsonView attribute here as filter --> + <jacksonxml id="view" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojoView" jsonView="org.apache.camel.component.jackson.Views$Age"/> + </dataFormats> + + <route> + <from uri="direct:in"/> + <marshal ref="jack"/> + </route> + + <route> + <from uri="direct:inPretty"/> + <marshal ref="pretty"/> + </route> + + <route> + <from uri="direct:back"/> + <unmarshal ref="jack"/> + <to uri="mock:reverse"/> + </route> + + <route> + <from uri="direct:inPojo"/> + <marshal ref="pojo"/> + </route> + + <route> + <from uri="direct:backPojo"/> + <unmarshal ref="pojo"/> + <to uri="mock:reversePojo"/> + </route> + + <route> + <from uri="direct:inAgeView"/> + <marshal ref="view"/> + </route> + + <route> + <from uri="direct:backAgeView"/> + <unmarshal ref="view"/> + <to uri="mock:reverseAgeView"/> + </route> + + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml new file mode 100644 index 0000000..ee54e28 --- /dev/null +++ b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml @@ -0,0 +1,43 @@ +<?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> + <!-- and this one uses our own TestPojo class as unmarshal type --> + <jacksonxml id="pojo" useList="true" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojo"/> + </dataFormats> + + <route> + <from uri="direct:backPojo"/> + <unmarshal ref="pojo"/> + <to uri="mock:reversePojo"/> + </route> + + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index f6d8ed9..fae282a 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -126,6 +126,7 @@ <module>camel-infinispan</module> <module>camel-irc</module> <module>camel-jackson</module> + <module>camel-jacksonxml</module> <module>camel-javaspace</module> <module>camel-jaxb</module> <module>camel-jasypt</module> http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index c3a30f8..40d87bc 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1019,6 +1019,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-jacksonxml</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-jasypt</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0936806d/platforms/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index 083a478..645923c 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -796,6 +796,14 @@ <feature version='${project.version}'>camel-core</feature> <bundle>mvn:org.apache.camel/camel-jackson/${project.version}</bundle> </feature> + <feature name='camel-jacksonxml' version='${project.version}' resolver='(obr)' start-level='50'> + <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${jackson2-version}</bundle> + <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson2-version}</bundle> + <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson2-version}</bundle> + <bundle dependency='true'>mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/${jackson2-version}</bundle> + <feature version='${project.version}'>camel-core</feature> + <bundle>mvn:org.apache.camel/camel-jacksonxml/${project.version}</bundle> + </feature> <feature name='camel-jasypt' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${project.version}'>camel-core</feature> <bundle>mvn:org.apache.camel/camel-jasypt/${project.version}</bundle>