This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch console in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5cb894419ec4a734422a5c075d94748581df9ddc Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Dec 29 12:59:56 2021 +0100 CAMEL-17384: Developer Console SPI --- .../org/apache/camel/dev-console/properties | 2 + .../camel/impl/console/PropertiesDevConsole.java | 49 ++++++++++++++++++++++ .../impl/console/DefaultDevConsolesLoaderTest.java | 12 +----- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/properties b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/properties new file mode 100644 index 0000000..9135a88 --- /dev/null +++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/properties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.impl.console.PropertiesDevConsole diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/PropertiesDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/PropertiesDevConsole.java new file mode 100644 index 0000000..7a4bde0 --- /dev/null +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/PropertiesDevConsole.java @@ -0,0 +1,49 @@ +/* + * 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.Map; + +import org.apache.camel.spi.PropertiesComponent; +import org.apache.camel.spi.annotations.DevConsole; + +@DevConsole("properties") +public class PropertiesDevConsole extends AbstractDevConsole { + + public PropertiesDevConsole() { + super("camel", "properties", "Properties", "Displays the properties loaded by Camel"); + } + + @Override + protected Object doCall(MediaType mediaType, Map<String, Object> options) { + // only text is supported + StringBuilder sb = new StringBuilder(); + + PropertiesComponent pc = getCamelContext().getPropertiesComponent(); + String loc = String.join(", ", pc.getLocations()); + sb.append(String.format("Properties loaded from locations: %s", loc)); + sb.append("\n"); + for (Map.Entry<Object, Object> entry : pc.loadProperties().entrySet()) { + Object k = entry.getKey(); + Object v = entry.getValue(); + sb.append(String.format("\n %s = %s", k, v)); + } + sb.append("\n"); + + return sb.toString(); + } +} diff --git a/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java b/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java index 42d5205..5264141 100644 --- a/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java +++ b/core/camel-console/src/test/java/org/apache/camel/impl/console/DefaultDevConsolesLoaderTest.java @@ -29,16 +29,6 @@ public class DefaultDevConsolesLoaderTest extends ContextTestSupport { public void testLoader() throws Exception { DefaultDevConsolesLoader loader = new DefaultDevConsolesLoader(context); Collection<DevConsole> col = loader.loadDevConsoles(); - Assertions.assertEquals(2, col.size()); - - DevConsole con = col.iterator().next(); - Assertions.assertNotNull(con); - Assertions.assertEquals("camel", con.getGroup()); - Assertions.assertEquals("context", con.getId()); - - String out = (String) con.call(DevConsole.MediaType.TEXT); - Assertions.assertNotNull(out); - log.info(out); - Assertions.assertTrue(out.contains(context.getName())); + Assertions.assertEquals(3, col.size()); } }