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 2022/11/09 15:06:22 UTC

[GitHub] [camel-quarkus] ppalaga commented on a diff in pull request #4266: controlbus: Added language tests (fixes #4008)

ppalaga commented on code in PR #4266:
URL: https://github.com/apache/camel-quarkus/pull/4266#discussion_r1018055005


##########
integration-test-groups/foundation/controlbus/src/main/resources/reflection-config.json:
##########
@@ -0,0 +1,6 @@
+[
+    {
+        "name": "org.apache.camel.spi.RouteController",
+        "allPublicMethods" : true
+    }
+]

Review Comment:
   This should go away using `@registerForReflection` as @jamesnetherton mentioned



##########
integration-test-groups/foundation/controlbus/src/main/resources/application.properties:
##########
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json

Review Comment:
   This should go away using `@registerForReflection` as @jamesnetherton mentioned



##########
integration-test-groups/foundation/controlbus/src/main/java/org/apache/camel/quarkus/component/controlbus/it/ControlbusBean.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.controlbus.it;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Header;
+
+@ApplicationScoped
+@Named("controlbus-bean")
+@RegisterForReflection

Review Comment:
   Is `@RegisterForReflection` really required here? 
   Maybe methods reflection would not be there without `@RegisterForReflection` but only cosntructor reflection?
   Anyway, we do not need fields, so `@RegisterForReflection(fields = false)` should be enough.



##########
integration-test-groups/foundation/controlbus/src/test/java/org/apache/camel/quarkus/component/controlbus/it/ControlbusLanguageTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.controlbus.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+
+@QuarkusTest
+class ControlbusLanguageTest {
+
+    @BeforeEach
+    public void startRoute() {
+        String status = RestAssured.get("/controlbus/language/status").asString();
+        if ("Stopped".equals(status)) {
+            RestAssured.post("/controlbus/language/start");
+        }
+    }
+
+    @Test
+    public void testSimple() {
+        testLanguage("simple");
+    }
+
+    @Test
+    public void testBean() {
+        testLanguage("bean");
+    }
+
+    @Test
+    public void testHeader() {
+        testLanguage("header");
+    }
+
+    @Test
+    public void testExchangeProperty() {
+        testLanguage("exchangeProperty");
+    }
+
+    private void testLanguage(String language) {
+        RestAssured.given()
+                .contentType(ContentType.TEXT).get("/controlbus/language/status")
+                .then().body(equalTo("Started"));
+
+        RestAssured.given()
+                .contentType(ContentType.TEXT).post("/controlbus/language/" + language)
+                .then().statusCode(204);
+
+        RestAssured.given()
+                .contentType(ContentType.TEXT).get("/controlbus/language/status")
+                .then().body(equalTo("Stopped"));
+    }

Review Comment:
   This could perhaps be a single parametrized test? Like we do elsewhere: https://github.com/apache/camel-quarkus/blob/main/integration-test-groups/foundation/ref/src/test/java/org/apache/camel/quarkus/component/ref/it/RefTest.java#L29-L31



##########
docs/modules/ROOT/pages/reference/extensions/controlbus.adoc:
##########
@@ -61,6 +64,61 @@ When using the `stats` command endpoint, the `camel-quarkus-management` extensio
 ----
 
 
+[id="extensions-controlbus-usage-languages"]
+=== Languages
+
+[id="extensions-controlbus-usage-bean"]
+==== Bean
+
+The Bean language can be used to invoke a method on a Bean to control the state of routes. The `org.apache.camel.quarkus:camel-quarkus-bean` extension must be added to the classpath. Maven users must add the following dependency to the POM:
+
+[source,xml]
+----
+<dependency>
+    <groupId>org.apache.camel.quarkus</groupId>
+    <artifactId>camel-quarkus-bean</artifactId>
+</dependency>
+----
+
+In native mode, the Bean class must be annotated with `@RegisterForReflection`.
+
+[id="extensions-controlbus-usage-simple"]
+==== Simple
+
+The Simple language can be used to control the state of routes. The following example uses a `ProducerTemplate` to stop a route with the id `foo`:
+
+[source,java]
+----
+template.sendBody(
+    "controlbus:language:simple", 
+    "${camelContext.getRouteController().stopRoute('foo')}"
+);
+----
+
+To use the OGNL notation, the `org.apache.camel.quarkus:camel-quarkus-bean` extension must be added as a dependency.
+
+In native mode, the classes used in the OGNL notation must be registered for reflection. In the above code snippet, the `org.apache.camel.spi.RouteController` class returned from `camelContext.getRouteController()` must be registered. As this is a third-party class, it cannot be annotated with `@RegisterForReflection` - instead you can the following config file to `src/main/resources/reflection-config.json`:

Review Comment:
   Is `RouteController` something users would want to use 80+% of times? If so, let's auto-register it, otherwise let them do it when they need 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.

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

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