You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "JiriOndrusek (via GitHub)" <gi...@apache.org> on 2024/01/17 14:33:57 UTC

[PR] Variables - global vs local setVariable test [camel-quarkus]

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

   Partially fixes https://github.com/apache/camel-quarkus/issues/5620
   (the other part of the solution is the example - https://github.com/apache/camel-quarkus-examples/pull/194)
   
   This PR adds basic variables coverage into `integration-test-groups/foundation`.
   
   One test (`customVariablerepository`) is not executed in the native move, because it is not possible to remove a CDI bean for one test. IMO the tested functionality uses functions which were already part of the Camel before, therefore there is no reason to test this in native.
   
   
   <!-- Uncomment and fill this section if your PR is not trivial
   [ ] 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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455842408


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());
+
+        context.getRouteController().startRoute("customGlobalRepository");
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalCustomEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalCustomStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/convert")
+    @POST
+    public String convert(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:convertEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:convertStart", body, String.class);
+        //        fluentProducerTemplate.to("direct:convertStart").withVariable(VariablesRoutes.VARIABLE_NAME, body).send();
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/filter/{city}")
+    @POST
+    public Response filter(String body, @PathParam("city") String city) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:filterEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBodyAndHeader("direct:filterStart", body, "city", city, String.class);
+
+        try {
+            Exchange exhange = end.assertExchangeReceived(0);
+            end.reset();

Review Comment:
   I skipped `reset()`  by rearranging test method differently.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455802136


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());
+
+        context.getRouteController().startRoute("customGlobalRepository");
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalCustomEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalCustomStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/convert")
+    @POST
+    public String convert(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:convertEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:convertStart", body, String.class);
+        //        fluentProducerTemplate.to("direct:convertStart").withVariable(VariablesRoutes.VARIABLE_NAME, body).send();
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/filter/{city}")
+    @POST
+    public Response filter(String body, @PathParam("city") String city) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:filterEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBodyAndHeader("direct:filterStart", body, "city", city, String.class);
+
+        try {
+            Exchange exhange = end.assertExchangeReceived(0);
+            end.reset();

Review Comment:
   If there is a possibility of flakiness, I think that I refactor the test class and ensure that calls to this resource  are synchronized (by joining 2 test methods into 1)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455774650


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());

Review Comment:
   Should we remove this one if useless ?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455790455


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());
+
+        context.getRouteController().startRoute("customGlobalRepository");
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalCustomEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalCustomStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/convert")
+    @POST
+    public String convert(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:convertEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:convertStart", body, String.class);
+        //        fluentProducerTemplate.to("direct:convertStart").withVariable(VariablesRoutes.VARIABLE_NAME, body).send();
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/filter/{city}")
+    @POST
+    public Response filter(String body, @PathParam("city") String city) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:filterEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBodyAndHeader("direct:filterStart", body, "city", city, String.class);
+
+        try {
+            Exchange exhange = end.assertExchangeReceived(0);
+            end.reset();

Review Comment:
   Didn't we have some kind of race condition issue generating flaky tests in the past ? A bit like 2 threads invoking the filter method concurrently and then 1 thread call reset while the other thread had the exchange.
   
   Not sure it applies here anyway, still it would it be good to find another way to test without reset ?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455777040


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());
+
+        context.getRouteController().startRoute("customGlobalRepository");
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalCustomEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalCustomStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/convert")
+    @POST
+    public String convert(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:convertEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:convertStart", body, String.class);
+        //        fluentProducerTemplate.to("direct:convertStart").withVariable(VariablesRoutes.VARIABLE_NAME, body).send();

Review Comment:
   Same here, could we remove that ?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455793618


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());

Review Comment:
   I missed that, will remove, thanks!



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455794129


##########
integration-test-groups/foundation/variables/src/test/java/org/apache/camel/quarkus/variables/it/CustomRepositoryVariablesTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.variables.it;
+
+import java.util.Collections;
+import java.util.Set;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test is executed in JVM mode only because the profile enabling customVariableRepositoty can not be enabled for

Review Comment:
   ```suggestion
    * Test is executed in JVM mode only because the profile enabling customVariableRepository can not be enabled for
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455799125


##########
integration-test-groups/foundation/variables/src/test/java/org/apache/camel/quarkus/variables/it/CustomRepositoryVariablesTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.variables.it;
+
+import java.util.Collections;
+import java.util.Set;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test is executed in JVM mode only because the profile enabling customVariableRepositoty can not be enabled for
+ * this class in the native (and stay disabled for the other test class).
+ * I think that it is not necessary to create a module for this test only, because it uses code tested by other tests

Review Comment:
   A whole module for test only seems overkill to me too at least.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455817968


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());
+
+        context.getRouteController().startRoute("customGlobalRepository");
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalCustomEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalCustomStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/convert")
+    @POST
+    public String convert(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:convertEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:convertStart", body, String.class);
+        //        fluentProducerTemplate.to("direct:convertStart").withVariable(VariablesRoutes.VARIABLE_NAME, body).send();
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/filter/{city}")
+    @POST
+    public Response filter(String body, @PathParam("city") String city) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:filterEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBodyAndHeader("direct:filterStart", body, "city", city, String.class);
+
+        try {
+            Exchange exhange = end.assertExchangeReceived(0);
+            end.reset();

Review Comment:
   Also, I remember a technic where we had one distinct mock per expected message. So that you never call reset... That was far, hard to remember if this applies to the case at hand :)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek merged PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455796003


##########
integration-test-groups/foundation/variables/src/main/java/org/apache/camel/quarkus/variables/it/VariablesResource.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.variables.it;
+
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.core.Response;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/variables")
+@ApplicationScoped
+public class VariablesResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    FluentProducerTemplate fluentProducerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/setLocalVariable")
+    @POST
+    public String setLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:setLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+        end.expectedVariableReceived(VariablesRoutes.VARIABLE_NAME, VariablesRoutes.VARIABLE_VALUE);
+
+        producerTemplate.requestBody("direct:setLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        return exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/setGlobalVariable")
+    @POST
+    public Response setGlobalVariable(String body) throws Exception {
+        if (context.getVariable(VariablesRoutes.VARIABLE_NAME) != null) {
+            return Response.status(500).entity(String.format("Variable '%s' has to be null before sending message to the rout.",
+                    VariablesRoutes.VARIABLE_VALUE)).build();
+        }
+        ;
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/removeLocalVariable")
+    @POST
+    public String removeLocalVariable(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:removeLocalVariableEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        MockEndpoint mid = context.getEndpoint("mock:removeLocalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeLocalVariableStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange endExchange = exchanges.get(0);
+        exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + endExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/removeGlobalVariable")
+    @POST
+    public String removeGlobalVariable(String body) throws Exception {
+        MockEndpoint mid = context.getEndpoint("mock:removeGlobalVariableMid", MockEndpoint.class);
+        mid.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:removeGlobalVariableStart", body, String.class);
+
+        // make sure we got the message
+        mid.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = mid.getExchanges();
+        Exchange midExchange = exchanges.get(0);
+
+        return midExchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+    }
+
+    @Path("/customGlobalRepository")
+    @POST
+    public Response customGlobalRepository(String body) throws Exception {
+        //        context.getRegistry().bind(GLOBAL_VARIABLE_REPOSITORY_ID, new MyGlobalRepo());
+
+        context.getRouteController().startRoute("customGlobalRepository");
+
+        MockEndpoint end = context.getEndpoint("mock:setGlobalCustomEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:setGlobalCustomStart", body, String.class);
+
+        // make sure we got the message
+        end.assertIsSatisfied();
+
+        // lets get the variable value
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+
+        String resp = exchange.getVariable(VariablesRoutes.VARIABLE_NAME, String.class) + ","
+                + context.getVariable(VariablesRoutes.VARIABLE_NAME, String.class);
+        return Response.ok().entity(resp).build();
+    }
+
+    @Path("/convert")
+    @POST
+    public String convert(String body) throws Exception {
+        MockEndpoint end = context.getEndpoint("mock:convertEnd", MockEndpoint.class);
+        end.expectedMessageCount(1);
+
+        producerTemplate.requestBody("direct:convertStart", body, String.class);
+        //        fluentProducerTemplate.to("direct:convertStart").withVariable(VariablesRoutes.VARIABLE_NAME, body).send();

Review Comment:
   It seems, that I reverted more code then anticipated, because I was removing that a while ago



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#discussion_r1455813013


##########
integration-test-groups/foundation/variables/src/test/java/org/apache/camel/quarkus/variables/it/CustomRepositoryVariablesTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.variables.it;
+
+import java.util.Collections;
+import java.util.Set;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test is executed in JVM mode only because the profile enabling customVariableRepositoty can not be enabled for

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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Variables - test coverage [camel-quarkus]

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on PR #5654:
URL: https://github.com/apache/camel-quarkus/pull/5654#issuecomment-1896031304

   > Looks pretty decent @JiriOndrusek
   > 
   > Concerning mock.reset(), I would vote to find another way if possible. If too difficult, maybe we just add a comment to have context in case the test is proven to be flaky on ci one day.
   
   I removed mock.reset by joining 2 rest calls into 1 test method, which ensures order, therefore no `reset()`  is required.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org