aldettinger commented on a change in pull request #2672: URL: https://github.com/apache/camel-quarkus/pull/2672#discussion_r639568492
########## File path: integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/jackson/json/JacksonJsonResource.java ########## @@ -0,0 +1,692 @@ +/* + * 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.quarkus.component.dataformats.jackson.json; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import org.apache.camel.CamelContext; +import org.apache.camel.ConsumerTemplate; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.jackson.JacksonConstants; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.quarkus.component.dataformats.json.model.DummyObject; +import org.apache.camel.quarkus.component.dataformats.json.model.Order; +import org.apache.camel.quarkus.component.dataformats.json.model.Pojo; +import org.apache.camel.quarkus.component.dataformats.json.model.TestJAXBPojo; +import org.apache.camel.quarkus.component.dataformats.json.model.TestOtherPojo; +import org.apache.camel.quarkus.component.dataformats.json.model.TestPojo; +import org.apache.camel.quarkus.component.dataformats.json.model.TestPojoView; +import org.apache.camel.support.DefaultExchange; +import org.jboss.logging.Logger; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Path("/dataformats-json") +@ApplicationScoped +public class JacksonJsonResource { + + private static final Logger LOG = Logger.getLogger(JacksonJsonResource.class); + private static final String LS = System.lineSeparator(); + @Inject + ProducerTemplate producerTemplate; + @Inject + ConsumerTemplate consumerTemplate; + @Inject + CamelContext context; + + @Path("jackson/unmarshal-typeheader") + @GET + public void jacksonXmlUnmarshalTypeHeader(String body) throws Exception { + + MockEndpoint mock = context.getEndpoint("mock:jackson-unmarshal-type-header-reversePojo", MockEndpoint.class); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(TestPojo.class); + + String json = "{\"name\":\"Camel\"}"; + producerTemplate.sendBodyAndHeader("direct:jackson-unmarshal-type-header-backPojo", json, + JacksonConstants.UNMARSHAL_TYPE, TestPojo.class.getName()); + + mock.assertIsSatisfied(); + + TestPojo pojo = mock.getReceivedExchanges().get(0).getIn().getBody(TestPojo.class); + assertNotNull(pojo); + assertEquals("Camel", pojo.getName()); + } + + @Path("jackson/unmarshal-list") + @GET + public void jacksonUnmarshalList(String body) throws Exception { + + MockEndpoint mock = context.getEndpoint("mock:jackson-unmarshal-reversePojo", MockEndpoint.class); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(List.class); + + String json = "[{\"name\":\"Camel\"}, {\"name\":\"World\"}]"; + producerTemplate.sendBody("direct:jackson-unmarshal-backPojo", json); + + mock.assertIsSatisfied(); + + 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()); + + mock.expectedMessageCount(2); + mock.message(1).body().isInstanceOf(List.class); + + json = "[{\"name\":\"Camel\"}]"; + producerTemplate.sendBody("direct:jackson-unmarshal-backPojo", json); + + mock.assertIsSatisfied(); + + list = mock.getReceivedExchanges().get(1).getIn().getBody(List.class); + assertNotNull(list); + assertEquals(1, list.size()); + + pojo = (TestPojo) list.get(0); + assertEquals("Camel", pojo.getName()); + + } + + @Path("jackson/unmarshal-listsplit") + @GET + public void jacksonUnmarshalListSplit(String body) throws Exception { + + MockEndpoint mock = context.getEndpoint("mock:jackson-unmarshal-listsplit-result", MockEndpoint.class); + mock.expectedMessageCount(2); + mock.expectedMessagesMatches(org.apache.camel.builder.Builder.body().isInstanceOf(DummyObject.class)); + + producerTemplate.sendBody("direct:jackson-unmarshal-listsplit-start", + "[{\"dummyString\": \"value1\"}, {\"dummyString\": \"value2\"}]"); + + mock.assertIsSatisfied(); + + } + + @Path("jackson/marshal-includedefault") + @GET + @Produces(MediaType.APPLICATION_JSON) + public String jacksonMarshalIncludeDefalut() throws Exception { Review comment: small typo here => Default -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
