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 0fa70d314675a79b3dd24bd98ce7ba1ae0fab63d Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Dec 27 12:01:13 2021 +0100 CAMEL-17384: Developer Console SPI --- .../camel/impl/engine/AbstractCamelContext.java | 2 +- .../impl/engine/DefaultDevConsoleResolver.java | 5 +-- core/camel-console/pom.xml | 29 ++++++++++++++-- .../camel/impl/console/ContextDevConsoleTest.java | 39 ++++++++++++++++++++++ .../src/test/resources/log4j2.properties | 33 ++++++++++++++++++ 5 files changed, 103 insertions(+), 5 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index 63ad43d..1d9ff77 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -4380,7 +4380,7 @@ public abstract class AbstractCamelContext extends BaseService } public void setDevConsoleResolver(DevConsoleResolver devConsoleResolver) { - this.devConsoleResolver = devConsoleResolver; + this.devConsoleResolver = doAddService(devConsoleResolver); } @Override diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDevConsoleResolver.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDevConsoleResolver.java index 6efc9ab..16f15bd 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDevConsoleResolver.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultDevConsoleResolver.java @@ -67,7 +67,8 @@ public class DefaultDevConsoleResolver implements DevConsoleResolver, CamelConte if (type != null) { if (DevConsole.class.isAssignableFrom(type)) { - return (DevConsole) camelContext.getInjector().newInstance(type, false); + answer = (DevConsole) camelContext.getInjector().newInstance(type, false); + CamelContextAware.trySetCamelContext(answer, camelContext); } else { throw new IllegalArgumentException( "Resolving dev-console: " + id + " detected type conflict: Not a DevConsole implementation. Found: " @@ -75,7 +76,7 @@ public class DefaultDevConsoleResolver implements DevConsoleResolver, CamelConte } } - return null; + return answer; } protected Class<?> findDevConsole(String name, CamelContext context) throws Exception { diff --git a/core/camel-console/pom.xml b/core/camel-console/pom.xml index 17d7611..1247615 100644 --- a/core/camel-console/pom.xml +++ b/core/camel-console/pom.xml @@ -45,9 +45,34 @@ <artifactId>camel-core-engine</artifactId> </dependency> + <!-- testing --> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> </dependency> </dependencies> diff --git a/core/camel-console/src/test/java/org/apache/camel/impl/console/ContextDevConsoleTest.java b/core/camel-console/src/test/java/org/apache/camel/impl/console/ContextDevConsoleTest.java new file mode 100644 index 0000000..ff0d9e2 --- /dev/null +++ b/core/camel-console/src/test/java/org/apache/camel/impl/console/ContextDevConsoleTest.java @@ -0,0 +1,39 @@ +/* + * 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 org.apache.camel.ContextTestSupport; +import org.apache.camel.ExtendedCamelContext; +import org.apache.camel.console.DevConsole; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ContextDevConsoleTest extends ContextTestSupport { + + @Test + public void testContext() throws Exception { + DevConsole con = context.adapt(ExtendedCamelContext.class).getDevConsoleResolver().resolveDevConsole("context"); + 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())); + } +} diff --git a/core/camel-console/src/test/resources/log4j2.properties b/core/camel-console/src/test/resources/log4j2.properties new file mode 100644 index 0000000..5642469 --- /dev/null +++ b/core/camel-console/src/test/resources/log4j2.properties @@ -0,0 +1,33 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +appender.console.type = Console +appender.console.name = console +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-console-test.log +appender.file.append = true +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n + +rootLogger.level = INFO + +rootLogger.appenderRef.file.ref = file +#rootLogger.appenderRef.console.ref = console +