This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit f5243c6a82dfde937673e80d3e0c5acad5aaf390 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Wed Oct 23 15:03:47 2019 +0200 Add more platform-http tests --- .../http/runtime/QuarkusPlatformHttpConsumer.java | 1 + integration-tests/platform-http/pom.xml | 1 + .../platform/http/it/PlatformHttpRouteBuilder.java | 31 ++++++++++ .../platform/http/it/TestHeaderFilterStrategy.java | 34 +++++++++++ .../component/http/server/it/PlatformHttpTest.java | 71 +++++++++++++++++++++- 5 files changed, 137 insertions(+), 1 deletion(-) diff --git a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java index a852ec1..fa026ab 100644 --- a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java +++ b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java @@ -334,6 +334,7 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer { final Message result = new DefaultMessage(exchange); final HeaderFilterStrategy headerFilterStrategy = getEndpoint().getHeaderFilterStrategy(); + System.out.println("headerFilterStrategy = "+ headerFilterStrategy); populateCamelHeaders(ctx, result.getHeaders(), exchange, headerFilterStrategy ); final String mimeType = ctx.parsedHeaders().contentType().value(); final boolean isMultipartFormData = "multipart/form-data".equals(mimeType); diff --git a/integration-tests/platform-http/pom.xml b/integration-tests/platform-http/pom.xml index 2b72ebd..d3c7f82 100644 --- a/integration-tests/platform-http/pom.xml +++ b/integration-tests/platform-http/pom.xml @@ -130,6 +130,7 @@ <enableJni>true</enableJni> <enableAllSecurityServices>true</enableAllSecurityServices> <disableReports>true</disableReports> + <addAllCharsets>true</addAllCharsets><!-- Required by the encoding() test --> </configuration> </execution> </executions> diff --git a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java index b675563..98b3a0d 100644 --- a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java +++ b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java @@ -17,9 +17,13 @@ package org.apache.camel.quarkus.component.platform.http.it; import java.io.ByteArrayOutputStream; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; import javax.activation.DataHandler; +import org.apache.camel.Exchange; import org.apache.camel.attachment.AttachmentMessage; import org.apache.camel.builder.RouteBuilder; @@ -32,12 +36,14 @@ public class PlatformHttpRouteBuilder extends RouteBuilder { .setBody(constant("GET: /rest-get")) .endRest() .post("/platform-http/rest-post") + .consumes("text/plain").produces("text/plain") .route() .setBody(constant("POST: /rest-post")) .endRest(); from("platform-http:/platform-http/hello?httpMethodRestrict=GET").setBody(simple("Hello ${header.name}")); from("platform-http:/platform-http/get-post?httpMethodRestrict=GET,POST").setBody(simple("Hello ${body}")); + from("platform-http:/platform-http/multipart?httpMethodRestrict=POST") .to("log:multipart") .process(e -> { @@ -48,5 +54,30 @@ public class PlatformHttpRouteBuilder extends RouteBuilder { e.getMessage().setBody(out.toByteArray()); } }); + + from("platform-http:/platform-http/form-urlencoded?httpMethodRestrict=POST") + .to("log:form-urlencoded") + .setBody(e -> + ((Map<String, Object>)e.getMessage().getBody(Map.class)).entrySet().stream() + .map(en -> en.getKey() + "=" + en.getValue().toString().toUpperCase(Locale.US)) + .collect(Collectors.joining("\n"))); + + from("platform-http:/platform-http/header-filter-strategy?httpMethodRestrict=GET&headerFilterStrategy=#TestHeaderFilterStrategy") + .to("log:header-filter-strategy") + .setBody(simple("k1=${header.k1}\nk2=${header.k2}")); + + from("platform-http:/platform-http/multi-value-params?httpMethodRestrict=GET") + .to("log:multi-value-params") + .setBody(simple("k1=${header.k1}")); + + from("platform-http:/platform-http/encoding?httpMethodRestrict=POST") + .to("log:encoding") + .setBody(e -> e.getMessage().getBody(String.class)) + .setHeader("Content-Type").constant("text/plain ; charset=UTF-8"); + + from("platform-http:/platform-http/response-code-299?httpMethodRestrict=GET") + .to("log:response-code") + .setHeader(Exchange.HTTP_RESPONSE_CODE).constant(299); + } } diff --git a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/TestHeaderFilterStrategy.java b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/TestHeaderFilterStrategy.java new file mode 100644 index 0000000..2d77171 --- /dev/null +++ b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/TestHeaderFilterStrategy.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.quarkus.component.platform.http.it; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + +import org.apache.camel.component.platform.http.PlatformHttpHeaderFilterStrategy; + +@ApplicationScoped +@Named("TestHeaderFilterStrategy") +public class TestHeaderFilterStrategy extends PlatformHttpHeaderFilterStrategy { + + @Override + protected void initialize() { + super.initialize(); + getInFilter().add("k1"); + } + +} diff --git a/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java b/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java index 51aa218..6b19606 100644 --- a/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java +++ b/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java @@ -20,10 +20,14 @@ import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.equalTo; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; + @QuarkusTest class PlatformHttpTest { @Test @@ -53,10 +57,21 @@ class PlatformHttpTest { public void rest() throws Throwable { RestAssured.get("/platform-http/rest-get") .then().body(equalTo("GET: /rest-get")); - RestAssured.post("/platform-http/rest-post") + RestAssured.given() + .contentType("text/plain") + .post("/platform-http/rest-post") .then().body(equalTo("POST: /rest-post")); } + @Disabled("See https://github.com/apache/camel-quarkus/issues/326") + @Test + public void restConsumes() throws Throwable { + RestAssured.given() + .contentType("application/json") + .post("/platform-http/rest-post") + .then().statusCode(415); + } + @Test public void invalidMethod() { RestAssured.post("/platform-http/hello") @@ -81,4 +96,58 @@ class PlatformHttpTest { Assertions.assertArrayEquals(bytes, returnedBytes); } + @Test + public void formUrlEncoded() { + RestAssured.given().contentType("application/x-www-form-urlencoded") + .formParam("k1", "v1") + .formParam("k2", "v2") + .post("/platform-http/form-urlencoded") + .then() + .statusCode(200) + .body(equalTo("k1=V1\nk2=V2")); + } + + @Test + public void customHeaderFilterStrategy() { + RestAssured.given() + .queryParam("k1", "v1") + .queryParam("k2", "v2") + .get("/platform-http/header-filter-strategy") + .then() + .statusCode(200) + .body(equalTo("k1=\nk2=v2")); // k1 filtered out by TestHeaderFilterStrategy + } + + @Test + public void multiValueParams() { + RestAssured.given() + .queryParam("k1", "v1") + .queryParam("k1", "v2") + .get("/platform-http/multi-value-params") + .then() + .statusCode(200) + .body(equalTo("k1=[v1, v2]")); + } + + @Test + public void encoding() throws UnsupportedEncodingException { + final String outgoingEncoding = "ISO-8859-2"; + final String bodyText = "Ťava dvojhrbá"; // Camelus bactrianus in Slovak + final byte[] returnedBytes = RestAssured.given() + .contentType("text/plain; charset="+ outgoingEncoding) + .body(bodyText.getBytes(outgoingEncoding)) + .post("/platform-http/encoding") + .then() + .statusCode(200) + .extract().body().asByteArray(); + Assertions.assertArrayEquals(bodyText.getBytes(StandardCharsets.UTF_8), returnedBytes); + } + + @Test + public void responseCodeViaHeader() throws UnsupportedEncodingException { + RestAssured.given() + .get("/platform-http/response-code-299") + .then() + .statusCode(299); + } }