apupier commented on code in PR #21103:
URL: https://github.com/apache/camel/pull/21103#discussion_r2735518869


##########
core/camel-console/src/test/java/org/apache/camel/impl/console/BeanDevConsoleTest.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.impl.console;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.console.DevConsole;
+import org.apache.camel.support.PluginHelper;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class BeanDevConsoleTest extends ContextTestSupport {
+
+    @Override
+    protected void doPostSetup() {
+        context.getRegistry().bind("myBean", new TestBean("Hello", 42));
+        context.getRegistry().bind("anotherBean", new TestBean("World", null));
+    }
+
+    @Test
+    public void testBeanConsoleText() {
+        DevConsole console = 
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("bean");
+        Assertions.assertNotNull(console);
+        Assertions.assertEquals("camel", console.getGroup());
+        Assertions.assertEquals("bean", console.getId());
+
+        String out = (String) console.call(DevConsole.MediaType.TEXT);
+        Assertions.assertNotNull(out);
+        log.info(out);
+        Assertions.assertTrue(out.contains("myBean"));
+        Assertions.assertTrue(out.contains("anotherBean"));
+        Assertions.assertTrue(out.contains("TestBean"));
+    }
+
+    @Test
+    public void testBeanConsoleJson() {
+        DevConsole console = 
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("bean");
+        Assertions.assertNotNull(console);
+
+        JsonObject out = (JsonObject) console.call(DevConsole.MediaType.JSON);
+        Assertions.assertNotNull(out);
+        log.info(out.toJson());
+
+        JsonObject beans = out.getMap("beans");
+        Assertions.assertNotNull(beans);
+        Assertions.assertTrue(beans.containsKey("myBean"));

Review Comment:
   it would be better to provide a an error message to have a direct 
explanation in the test failure which key is missing.
   
   another alternative for a better error message is to use Assertj and jsonunit



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to