This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 8b27674 CAMEL-12428: Added unit test. 8b27674 is described below commit 8b27674e91c6bb2f11c30e52d43e94f3b605c3c6 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Dec 21 10:51:59 2020 +0100 CAMEL-12428: Added unit test. --- .../cxf/jaxrs/CxfRsResponseWithHeadersTest.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java new file mode 100644 index 0000000..7ccedcd --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java @@ -0,0 +1,71 @@ +/* + * 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.cxf.jaxrs; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.cxf.CXFTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CxfRsResponseWithHeadersTest extends CamelTestSupport { + private static final String PUT_REQUEST = "<Customer><name>Mary</name><id>123</id></Customer>"; + private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsResponseWithHeadersTest"; + private static final String CXF_RS_ENDPOINT_URI + = "cxfrs://http://localhost:" + CXT + + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"; + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from(CXF_RS_ENDPOINT_URI) + .process(e -> { + e.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 404); + e.getMessage().setHeader(Exchange.CONTENT_TYPE, "text/plain"); + e.getMessage().setBody("Cannot find customer"); + }); + } + }; + } + + @Test + public void testPutConsumer() throws Exception { + HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers"); + StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1"); + entity.setContentType("text/xml; charset=ISO-8859-1"); + put.setEntity(entity); + CloseableHttpClient httpclient = HttpClientBuilder.create().build(); + + try { + HttpResponse response = httpclient.execute(put); + assertEquals(404, response.getStatusLine().getStatusCode()); + assertEquals("Cannot find customer", EntityUtils.toString(response.getEntity())); + } finally { + httpclient.close(); + } + } + +}