You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/09/17 14:13:56 UTC

[GitHub] [camel-quarkus] JiriOndrusek opened a new pull request #1804: Velocity Support #837

JiriOndrusek opened a new pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804


   Issue: https://github.com/apache/camel-quarkus/issues/837
   
   Replaces: https://github.com/apache/camel-quarkus/pull/1634
   
   [ ] An issue should be filed for the change unless this is a trivial change (fixing a typo or similar). One issue should ideally be fixed by not more than one commit and the other way round, each commit should fix just one issue, without pulling in other changes.
   [ ] Each commit in the pull request should have a meaningful and properly spelled subject line and body. Copying the title of the associated issue is typically enough. Please include the issue number in the commit message prefixed by #.
   [ ] The pull request description should explain what the pull request does, how, and why. If the info is available in the associated issue or some other external document, a link is enough.
   [ ] Phrases like Fix #<issueNumber> or Fixes #<issueNumber> will auto-close the named issue upon merging the pull request. Using them is typically a good idea.
   [ ] Please run mvn process-resources -Pformat (and amend the changes if necessary) before sending the pull request.
   [ ] Contributor guide is your good friend: https://camel.apache.org/camel-quarkus/latest/contributor-guide.html


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r493433826



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")

Review comment:
       done

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye ${body}".getBytes());
+
+        RestAssured.given() //
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+
+                .statusCode(201)
+                .body(equalTo(useContentCache ? "Hi Sheldon" : "Bye Sheldon"));
+    }
+
+    private File createFile(String fileName, String body) throws IOException {
+        File tmpFile = File.createTempFile(fileName, ".vm");
+        FileWriter writer = new FileWriter(tmpFile);
+        writer.write(body);
+        writer.close();

Review comment:
       done




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#issuecomment-697233965


   Changes are ready for review


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r495002948



##########
File path: integration-tests/velocity/src/main/java/org/apache/camel/quarkus/component/velocity/it/VelocityResource.java
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.velocity.it;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.velocity.VelocityConstants;
+import org.jboss.logging.Logger;
+
+@Path("/velocity")
+@ApplicationScoped
+public class VelocityResource {
+
+    private static final Logger LOG = Logger.getLogger(VelocityResource.class);
+
+    @Inject
+    ProducerTemplate producerTemplate;
+    private String endpointUri;
+
+    @Path("/template")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response template(String message, @QueryParam("item") String item,
+            @QueryParam("name") String name, @QueryParam("template") String template,
+            @QueryParam("propertiesFile") String propertiesFile,
+            @QueryParam("contentCache") String contentCache,
+            @QueryParam("expectFailure") String exectFaiure) throws Exception {
+        LOG.infof("Sending to velocity: %s", message);
+        Map<String, Object> headers = new HashMap() {
+            {
+                if (item != null) {
+                    put("item", item);
+                }
+                if (name != null) {
+                    put("name", name);
+                }
+                put(VelocityConstants.VELOCITY_TEMPLATE, message);
+            }
+        };
+        String endpointUrl = "velocity:" + template;
+        if (propertiesFile != null) {
+            endpointUrl = endpointUrl + "?propertiesFile=" + propertiesFile;
+        }
+        if (contentCache != null) {
+            endpointUrl = endpointUrl + "?contentCache=" + contentCache;
+        }
+        try {
+            final String response = producerTemplate.requestBodyAndHeaders(endpointUrl, message,
+                    headers,
+                    String.class);
+            LOG.infof("Got response from velocity: %s", response);
+            return Response
+                    .created(new URI("https://camel.apache.org/"))
+                    .entity(response)
+                    .build();
+        } catch (Exception e) {
+            if (exectFaiure != null && Boolean.parseBoolean(exectFaiure)) {
+                return Response
+                        .created(new URI("https://camel.apache.org/"))
+                        .entity(e.toString())
+                        .status(500)
+                        .build();
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    @Path("/bodyAsDomainObject")
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response bodyAsDomainObject(Person person, @QueryParam("givenName") String givenName,
+            @QueryParam("familyName") String familyName) throws Exception {
+        LOG.infof("Sending to velocity: %s", person);
+        final String response = producerTemplate.requestBody("velocity://template/BodyAsDomainObject.vm", person,
+                String.class);
+        LOG.infof("Got response from velocity: %s", response);
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response)
+                .build();
+    }
+
+    @Path("/templateViaHeader")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response templateViaHeader(String message, @QueryParam("body") String body, @QueryParam("item") String item,
+            @QueryParam("name") String name) throws Exception {
+        LOG.infof("Sending to velocity: %s", body);
+        Map<String, Object> headers = new HashMap() {
+            {
+                put("item", item);
+                put("name", name);
+                put(VelocityConstants.VELOCITY_TEMPLATE, message);
+            }
+        };
+        final String response = producerTemplate.requestBodyAndHeaders("velocity::dummy?allowTemplateFromHeader=true", body,
+                headers,
+                String.class);
+        LOG.infof("Got response from velocity: %s", response);
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response)
+                .build();
+    }
+
+    @Path("/withProperties")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response withProperties(String message, @QueryParam("item") String item,
+            @QueryParam("name") String name) throws Exception {
+        LOG.infof("Sending to velocity: %s", message);

Review comment:
       I've left logging here because it was generated by the command `fmvn cq:create -N -Dcq.artifactIdBase=foo-abc`. But in future I won't keep it

##########
File path: integration-tests/velocity/src/main/java/org/apache/camel/quarkus/component/velocity/it/VelocityResource.java
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.velocity.it;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.velocity.VelocityConstants;
+import org.jboss.logging.Logger;
+
+@Path("/velocity")
+@ApplicationScoped
+public class VelocityResource {
+
+    private static final Logger LOG = Logger.getLogger(VelocityResource.class);
+
+    @Inject
+    ProducerTemplate producerTemplate;
+    private String endpointUri;
+
+    @Path("/template")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response template(String message, @QueryParam("item") String item,
+            @QueryParam("name") String name, @QueryParam("template") String template,
+            @QueryParam("propertiesFile") String propertiesFile,
+            @QueryParam("contentCache") String contentCache,
+            @QueryParam("expectFailure") String exectFaiure) throws Exception {
+        LOG.infof("Sending to velocity: %s", message);
+        Map<String, Object> headers = new HashMap() {
+            {
+                if (item != null) {
+                    put("item", item);
+                }
+                if (name != null) {
+                    put("name", name);
+                }
+                put(VelocityConstants.VELOCITY_TEMPLATE, message);
+            }
+        };
+        String endpointUrl = "velocity:" + template;
+        if (propertiesFile != null) {
+            endpointUrl = endpointUrl + "?propertiesFile=" + propertiesFile;
+        }
+        if (contentCache != null) {
+            endpointUrl = endpointUrl + "?contentCache=" + contentCache;
+        }
+        try {
+            final String response = producerTemplate.requestBodyAndHeaders(endpointUrl, message,
+                    headers,
+                    String.class);
+            LOG.infof("Got response from velocity: %s", response);
+            return Response
+                    .created(new URI("https://camel.apache.org/"))
+                    .entity(response)
+                    .build();
+        } catch (Exception e) {
+            if (exectFaiure != null && Boolean.parseBoolean(exectFaiure)) {
+                return Response
+                        .created(new URI("https://camel.apache.org/"))
+                        .entity(e.toString())
+                        .status(500)
+                        .build();
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    @Path("/bodyAsDomainObject")
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response bodyAsDomainObject(Person person, @QueryParam("givenName") String givenName,
+            @QueryParam("familyName") String familyName) throws Exception {
+        LOG.infof("Sending to velocity: %s", person);
+        final String response = producerTemplate.requestBody("velocity://template/BodyAsDomainObject.vm", person,
+                String.class);
+        LOG.infof("Got response from velocity: %s", response);
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response)
+                .build();
+    }
+
+    @Path("/templateViaHeader")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response templateViaHeader(String message, @QueryParam("body") String body, @QueryParam("item") String item,
+            @QueryParam("name") String name) throws Exception {
+        LOG.infof("Sending to velocity: %s", body);
+        Map<String, Object> headers = new HashMap() {
+            {
+                put("item", item);
+                put("name", name);
+                put(VelocityConstants.VELOCITY_TEMPLATE, message);
+            }
+        };
+        final String response = producerTemplate.requestBodyAndHeaders("velocity::dummy?allowTemplateFromHeader=true", body,
+                headers,
+                String.class);
+        LOG.infof("Got response from velocity: %s", response);
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response)
+                .build();
+    }
+
+    @Path("/withProperties")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response withProperties(String message, @QueryParam("item") String item,
+            @QueryParam("name") String name) throws Exception {
+        LOG.infof("Sending to velocity: %s", message);

Review comment:
       I've left logging here because it was generated by the command `mvn cq:create -N -Dcq.artifactIdBase=foo-abc`. But in the future I won't keep it




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#issuecomment-698896121


   I've applied restrictions described here: https://github.com/apache/camel-quarkus/issues/1807
   (by adding limitations.adoc, removing unnecessary build items for reflections and by changing tests to current state)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r493419776



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye ${body}".getBytes());
+
+        RestAssured.given() //
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+
+                .statusCode(201)
+                .body(equalTo(useContentCache ? "Hi Sheldon" : "Bye Sheldon"));
+    }
+
+    private File createFile(String fileName, String body) throws IOException {
+        File tmpFile = File.createTempFile(fileName, ".vm");
+        FileWriter writer = new FileWriter(tmpFile);
+        writer.write(body);
+        writer.close();

Review comment:
       I missed that one (copy paste), I'll fix it




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r490312134



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.velocity.it;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "Dear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaHeader() throws Exception {

Review comment:
       Actually I thought that use case with template via header, could contain more problems. 
   But you are right, I'll add also basic use case with template from classpath.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
ppalaga commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r493414845



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //

Review comment:
       Couldn't we remove the trailing empty commets?

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")

Review comment:
       Can we remove this line?

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye ${body}".getBytes());
+
+        RestAssured.given() //
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+
+                .statusCode(201)
+                .body(equalTo(useContentCache ? "Hi Sheldon" : "Bye Sheldon"));
+    }
+
+    private File createFile(String fileName, String body) throws IOException {
+        File tmpFile = File.createTempFile(fileName, ".vm");
+        FileWriter writer = new FileWriter(tmpFile);
+        writer.write(body);
+        writer.close();

Review comment:
       If you use a writer, it needs to be enclosed in a try-with. You also implicitly use the current machines default encoding, which can be just anything - the test might fail on machines with exotic default encodings. Shorter & solving all named problems: 
   ```suggestion
           Files.write(tmpFile.toPath(), body.getBytes(StandardCharsets.UTF_8);
   ```

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye ${body}".getBytes());
+
+        RestAssured.given() //
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")

Review comment:
       Can we remove this line?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#issuecomment-698896121


   I've applied restrictions described here: https://github.com/apache/camel-quarkus/issues/1807
   (by adding limitations.adoc, removing unnecessary build items for reflections and by changing tests to current state)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r490289502



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.velocity.it;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "Dear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaHeader() throws Exception {

Review comment:
       Unless I missed something, I don't see any testing for what is likely to be the most common use case - reading a template from the classpath. 
   
   Also, for the other templating components, we have some extra documentation which we should replicate for this extension.
   
   https://camel.apache.org/camel-quarkus/latest/reference/extensions/mustache.html#_additional_camel_quarkus_configuration

##########
File path: extensions/velocity/deployment/src/main/java/org/apache/camel/quarkus/component/velocity/deployment/VelocityProcessor.java
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.velocity.deployment;
+
+import java.util.ArrayList;
+import java.util.TreeMap;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.camel.component.velocity.CamelVelocityClasspathResourceLoader;
+import org.apache.camel.support.MessageSupport;
+import org.jboss.jandex.IndexView;
+
+import static java.util.stream.Collectors.toCollection;
+
+class VelocityProcessor {
+
+    private static final String FEATURE = "camel-velocity";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    NativeImageResourceBuildItem initResources() {
+        return new NativeImageResourceBuildItem(
+                "org/apache/velocity/runtime/defaults/velocity.properties",
+                "org/apache/velocity/runtime/defaults/directive.properties");
+    }
+
+    @BuildStep
+    ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
+        IndexView index = combinedIndex.getIndex();
+
+        ArrayList<String> dtos = index.getKnownClasses().stream().map(ci -> ci.name().toString())
+                .filter(n -> n.startsWith("org.apache.velocity.runtime") ||
+                        n.startsWith("org.apache.velocity.util.introspection"))
+                .sorted()
+                .collect(toCollection(ArrayList::new));
+
+        dtos.add(CamelVelocityClasspathResourceLoader.class.getName());
+
+        return new ReflectiveClassBuildItem(false, false, dtos.toArray(new String[dtos.size()]));
+    }
+
+    @BuildStep
+    ReflectiveClassBuildItem registerForReflectionWithMethods() {
+        return new ReflectiveClassBuildItem(true, false,
+                TreeMap.class.getName(),
+                MessageSupport.class.getName());

Review comment:
       Just a question, why do we register `MessageSupport` for reflection? Is it needed for the template engine to get access to exchange headers etc? 




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r493433625



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //

Review comment:
       done

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye ${body}".getBytes());
+
+        RestAssured.given() //
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")

Review comment:
       done




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] ppalaga commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
ppalaga commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r494977020



##########
File path: integration-tests/velocity/src/main/resources/template/BodyAsDomainObject.vm
##########
@@ -0,0 +1,33 @@
+#*
+ * 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.
+ *#
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------

Review comment:
       We have two license headers for some reason here and elsewhere.

##########
File path: integration-tests/velocity/src/main/java/org/apache/camel/quarkus/component/velocity/it/VelocityResource.java
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.velocity.it;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.velocity.VelocityConstants;
+import org.jboss.logging.Logger;
+
+@Path("/velocity")
+@ApplicationScoped
+public class VelocityResource {
+
+    private static final Logger LOG = Logger.getLogger(VelocityResource.class);
+
+    @Inject
+    ProducerTemplate producerTemplate;
+    private String endpointUri;
+
+    @Path("/template")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response template(String message, @QueryParam("item") String item,
+            @QueryParam("name") String name, @QueryParam("template") String template,
+            @QueryParam("propertiesFile") String propertiesFile,
+            @QueryParam("contentCache") String contentCache,
+            @QueryParam("expectFailure") String exectFaiure) throws Exception {
+        LOG.infof("Sending to velocity: %s", message);
+        Map<String, Object> headers = new HashMap() {
+            {
+                if (item != null) {
+                    put("item", item);
+                }
+                if (name != null) {
+                    put("name", name);
+                }
+                put(VelocityConstants.VELOCITY_TEMPLATE, message);
+            }
+        };
+        String endpointUrl = "velocity:" + template;
+        if (propertiesFile != null) {
+            endpointUrl = endpointUrl + "?propertiesFile=" + propertiesFile;
+        }
+        if (contentCache != null) {
+            endpointUrl = endpointUrl + "?contentCache=" + contentCache;
+        }
+        try {
+            final String response = producerTemplate.requestBodyAndHeaders(endpointUrl, message,
+                    headers,
+                    String.class);
+            LOG.infof("Got response from velocity: %s", response);
+            return Response
+                    .created(new URI("https://camel.apache.org/"))
+                    .entity(response)
+                    .build();
+        } catch (Exception e) {
+            if (exectFaiure != null && Boolean.parseBoolean(exectFaiure)) {
+                return Response
+                        .created(new URI("https://camel.apache.org/"))
+                        .entity(e.toString())
+                        .status(500)
+                        .build();
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    @Path("/bodyAsDomainObject")
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response bodyAsDomainObject(Person person, @QueryParam("givenName") String givenName,
+            @QueryParam("familyName") String familyName) throws Exception {
+        LOG.infof("Sending to velocity: %s", person);
+        final String response = producerTemplate.requestBody("velocity://template/BodyAsDomainObject.vm", person,
+                String.class);
+        LOG.infof("Got response from velocity: %s", response);
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response)
+                .build();
+    }
+
+    @Path("/templateViaHeader")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response templateViaHeader(String message, @QueryParam("body") String body, @QueryParam("item") String item,
+            @QueryParam("name") String name) throws Exception {
+        LOG.infof("Sending to velocity: %s", body);
+        Map<String, Object> headers = new HashMap() {
+            {
+                put("item", item);
+                put("name", name);
+                put(VelocityConstants.VELOCITY_TEMPLATE, message);
+            }
+        };
+        final String response = producerTemplate.requestBodyAndHeaders("velocity::dummy?allowTemplateFromHeader=true", body,
+                headers,
+                String.class);
+        LOG.infof("Got response from velocity: %s", response);
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response)
+                .build();
+    }
+
+    @Path("/withProperties")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response withProperties(String message, @QueryParam("item") String item,
+            @QueryParam("name") String name) throws Exception {
+        LOG.infof("Sending to velocity: %s", message);

Review comment:
       Extensive logging slows down the test execution on machines with slow IO (which CI machines typically are). I think we should prefer debug level in situations like this. I should perhaps change the template that generates these messages. This is just a tip for the future. 

##########
File path: integration-tests/velocity/src/main/resources/template/BodyAsDomainObject.vm
##########
@@ -0,0 +1,33 @@
+#*
+ * 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.
+ *#
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------

Review comment:
       Merged and filed a followup: https://github.com/apache/camel-quarkus/issues/1843




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r493420135



##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //

Review comment:
       I'll remove unnecessary comments

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")

Review comment:
       I'll remove unnecessary comments

##########
File path: integration-tests/velocity/src/test/java/org/apache/camel/quarkus/component/velocity/it/VelocityTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.velocity.it;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusTest
+class VelocityTest {
+
+    public static final String OLD_BODY = "old_body";
+    public static final String BODY = "bar";
+    public static final String NEW_BODY = "new_body";
+    public static final String MSG = "\nDear Sheldon\n" +
+            "\n" +
+            "Thanks for the order of Camel in Action.\n" +
+            "\n" +
+            "Regards Apache Camel Riders Bookstore\n" +
+            "PS: Next beer is on me";
+
+    @Test
+    public void testTemplateViaFile() throws IOException {
+        File template = createFile("velocity_test", "Hi ${headers.name}. You have got ${headers.item}. ${body}");
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "file:/" + template.getPath())
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. You have got Camel in Action. PS: Next beer is on me"));
+    }
+
+    @Test
+    public void testTemplateViaClasspath() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/letter.vm")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo(MSG));
+    }
+
+    @Test
+    public void testTemplateViaClasspathWithProperties() {
+        //class loader is forbidden by properties, response should fail
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .queryParam("template", "//template/template.vm")
+                .queryParam("propertiesFile", "/template/velocity.properties")
+                .queryParam("expectFailure", "true")
+                .contentType(ContentType.TEXT)
+                .body("PS: Next beer is on me")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(500)
+                .body(containsString("Exception"));
+    }
+
+    @Test
+    public void testTemplateViaHeader() {
+        RestAssured.given() //
+                .queryParam("body", "PS: Next beer is on me.")
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "Camel in Action")
+                .contentType(ContentType.TEXT)
+                .body("Hi ${headers.name}. Thanks for ${headers.item}. ${body}")
+                .post("/velocity/templateViaHeader") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon. Thanks for Camel in Action. PS: Next beer is on me."));
+    }
+
+    @Test
+    public void testSupplementalContext() {
+        final String template = "#set( $headers.body = ${body} )\n#set( $headers['in.body'] = $in.body )\n" + BODY;
+        Map result = RestAssured.given() //
+                .queryParam("body", OLD_BODY)
+                .queryParam("supplementalBody", NEW_BODY)
+                .contentType(ContentType.TEXT)
+                .body(template)
+                .post("/velocity/supplementalContext") //
+                .then()
+                .statusCode(200)
+                .extract().as(Map.class);
+
+        assertTrue(result.containsKey("in.body"));
+        assertEquals(OLD_BODY, result.get("in.body"));
+        assertTrue(result.containsKey("result_value"));
+        assertEquals(BODY, result.get("result_value"));
+        assertTrue(result.containsKey("body"));
+        assertEquals(NEW_BODY, result.get("body"));
+    }
+
+    @Test
+    public void testBodyAsDomainObject() {
+        RestAssured.given()
+                .queryParam("name", "Sheldon")
+                .queryParam("country", "Earth 1")
+                .contentType(ContentType.JSON)
+                .body(new Person("Sheldon", "Earth 2"))
+                .post("/velocity/bodyAsDomainObject") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("\nHi Sheldon from Earth 2"));
+    }
+
+    @Test
+    public void testValuesInProperties() {
+        RestAssured.given() //
+                .queryParam("name", "Sheldon")
+                .queryParam("item", "1")
+                .contentType(ContentType.TEXT)
+                .body("Dear ${exchange.properties.name}. You ordered item ${exchange.properties.item}.")
+                .post("/velocity/withProperties") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Dear Sheldon. You ordered item 1."));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("velocity_test", "Hi ${body}");
+
+        RestAssured.given()
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")
+                .queryParam("contentCache", useContentCache)
+                .contentType(ContentType.TEXT)
+                .body("Sheldon")
+                .post("/velocity/template") //
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye ${body}".getBytes());
+
+        RestAssured.given() //
+                .queryParam("template", "file:/" + template.getPath())
+                //                .queryParam("loaderCache", "false")

Review comment:
       I'll remove unnecessary comments




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#issuecomment-694289055


   Switching into a draft, because at least one basic scenario (with template from classpath) has to be added into test suite.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] JiriOndrusek commented on a change in pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on a change in pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#discussion_r490314030



##########
File path: extensions/velocity/deployment/src/main/java/org/apache/camel/quarkus/component/velocity/deployment/VelocityProcessor.java
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.velocity.deployment;
+
+import java.util.ArrayList;
+import java.util.TreeMap;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.camel.component.velocity.CamelVelocityClasspathResourceLoader;
+import org.apache.camel.support.MessageSupport;
+import org.jboss.jandex.IndexView;
+
+import static java.util.stream.Collectors.toCollection;
+
+class VelocityProcessor {
+
+    private static final String FEATURE = "camel-velocity";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    NativeImageResourceBuildItem initResources() {
+        return new NativeImageResourceBuildItem(
+                "org/apache/velocity/runtime/defaults/velocity.properties",
+                "org/apache/velocity/runtime/defaults/directive.properties");
+    }
+
+    @BuildStep
+    ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
+        IndexView index = combinedIndex.getIndex();
+
+        ArrayList<String> dtos = index.getKnownClasses().stream().map(ci -> ci.name().toString())
+                .filter(n -> n.startsWith("org.apache.velocity.runtime") ||
+                        n.startsWith("org.apache.velocity.util.introspection"))
+                .sorted()
+                .collect(toCollection(ArrayList::new));
+
+        dtos.add(CamelVelocityClasspathResourceLoader.class.getName());
+
+        return new ReflectiveClassBuildItem(false, false, dtos.toArray(new String[dtos.size()]));
+    }
+
+    @BuildStep
+    ReflectiveClassBuildItem registerForReflectionWithMethods() {
+        return new ReflectiveClassBuildItem(true, false,
+                TreeMap.class.getName(),
+                MessageSupport.class.getName());

Review comment:
       This is needed in scenario with "SupplementalContext". Velocity engine uses reflection to access output message to put some values among headers




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] dc2tom commented on pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
dc2tom commented on pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804#issuecomment-694295393


   looks reasonable to me - I'd just suggest porting more of the original camel velocity tests-  feel free to lift them from my PR, I did a fair few of them before drawing a line under it


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [camel-quarkus] ppalaga merged pull request #1804: Velocity Support #837

Posted by GitBox <gi...@apache.org>.
ppalaga merged pull request #1804:
URL: https://github.com/apache/camel-quarkus/pull/1804


   


----------------------------------------------------------------
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:
users@infra.apache.org