This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8d8aabdb549ff63d77c0401a6b6d72d768998ca0 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Dec 9 18:22:20 2021 +0100 CAMEL-17295: Added unit test --- .../servlet/rest/RestServletQueryParamTest.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletQueryParamTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletQueryParamTest.java new file mode 100644 index 0000000..68f7d29 --- /dev/null +++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletQueryParamTest.java @@ -0,0 +1,67 @@ +/* + * 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.servlet.rest; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.servlet.ServletCamelRouterTestSupport; +import org.apache.camel.component.servlet.ServletRestHttpBinding; +import org.apache.camel.model.rest.RestParamType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class RestServletQueryParamTest extends ServletCamelRouterTestSupport { + + @BindToRegistry("myBinding") + private ServletRestHttpBinding restHttpBinding = new ServletRestHttpBinding(); + + @Test + public void testServletProducerGet() throws Exception { + WebRequest req = new GetMethodWebRequest(contextUrl + "/services/users/"); + req.setParameter("auth", "secret"); + WebResponse response = query(req, false); + + assertEquals(200, response.getResponseCode()); + + assertEquals("secret;Donald Duck", response.getText()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use servlet on localhost + restConfiguration().component("servlet").host("localhost").endpointProperty("httpBinding", "#myBinding"); + + // use the rest DSL to define the rest services + rest() + .get("/users/?auth={myToken}") + .param() + .name("auth") + .type(RestParamType.query) + .endParam() + .route().to("mock:input").process(exchange -> { + String auth = exchange.getIn().getHeader("auth", String.class); + exchange.getMessage().setBody(auth + ";Donald Duck"); + }); + } + }; + } + +}