You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "jamesnetherton (via GitHub)" <gi...@apache.org> on 2023/03/16 09:46:22 UTC

[GitHub] [camel-quarkus] jamesnetherton commented on a diff in pull request #4663: camel-quarkus-management: Added tests for managed beans

jamesnetherton commented on code in PR #4663:
URL: https://github.com/apache/camel-quarkus/pull/4663#discussion_r1138380738


##########
integration-tests-jvm/management/src/test/java/org/apache/camel/quarkus/component/management/it/ManagementTest.java:
##########
@@ -24,23 +24,69 @@
 import javax.management.ObjectName;
 
 import io.quarkus.test.junit.QuarkusTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @QuarkusTest
 class ManagementTest {
 
+    private MBeanServer server;
+
+    @Inject
+    ProducerTemplate template;
+
+    @Inject
+    CamelContext camelContext;
+
+    @BeforeEach
+    public void setUp() {
+        server = ManagementFactory.getPlatformMBeanServer();
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = { "components", "consumers", "context", "dataformats", "endpoints", "processors", "routes",
+            "services" })
+    public void testManagementObjects(String type) throws Exception {
+        // Look up an object instance by type
+        ObjectName objectName = new ObjectName("org.apache.camel:type=" + type + ",*");
+        Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
+        assertTrue(mbeans.size() > 0);
+
+        // The CamelId attribute is common to all managed Camel objects,
+        // and should match the name of the CamelContext.
+        ObjectInstance mbean = mbeans.iterator().next();
+        String camelId = (String) server.getAttribute(mbean.getObjectName(), "CamelId");
+        assertEquals(camelContext.getName(), camelId);
+    }
+
     @Test
-    public void testCamelManagement() throws Exception {
-        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-        ObjectName objectName = new ObjectName("org.apache.camel:type=context,*");
+    public void testManagedBean() throws Exception {
+        ObjectName objectName = new ObjectName("org.apache.camel:type=processors,name=\"counter\",*");
         Set<ObjectInstance> mbeans = server.queryMBeans(objectName, null);
         assertEquals(1, mbeans.size());
-
         ObjectInstance instance = mbeans.iterator().next();
-        String routeXML = (String) server.invoke(instance.getObjectName(), "dumpRoutesAsXml", new Object[] {}, new String[] {});

Review Comment:
   I think we should still verify that `dumpRoutesAsXml` works ok as it's used by external tools like HawtIO 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.

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

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