From 4b70ef673dc9c9e165a2232e20c43a4815342770 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Wed, 25 Mar 2020 16:38:19 +0100 Subject: [PATCH 1/2] Fix joor after switching to Java 11 --- camel-k-loader-java/pom.xml | 2 +- .../src/test/resources/MyRoutesWithBeans.java | 32 ++++++++++ camel-k-loader-kotlin/pom.xml | 3 +- camel-k-main/camel-k-runtime-main/pom.xml | 5 ++ .../org/apache/camel/k/main/RuntimeTest.java | 36 ++++++++++- .../src/test/resources/MyRoutesWithBeans.java | 1 + .../main/java/org/apache/camel/k/Runtime.java | 5 ++ camel-k-runtime-knative/pom.xml | 8 +-- .../KnativeSourceRoutesLoaderTest.java | 61 +++---------------- 9 files changed, 92 insertions(+), 61 deletions(-) create mode 100644 camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java diff --git a/camel-k-loader-java/pom.xml b/camel-k-loader-java/pom.xml index a5d1db88d..4ecdc5b2a 100644 --- a/camel-k-loader-java/pom.xml +++ b/camel-k-loader-java/pom.xml @@ -42,7 +42,7 @@ org.jooq - joor-java-8 + joor ${joor.version} diff --git a/camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java b/camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java new file mode 100644 index 000000000..746b8e659 --- /dev/null +++ b/camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java @@ -0,0 +1,32 @@ +/* + * 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. + */ +import org.apache.camel.BindToRegistry; +import org.apache.camel.builder.RouteBuilder; + +public class MyRoutesWithBeans extends RouteBuilder { + @Override + public void configure() throws Exception { + from("direct:start") + .setBody().simple("${header[MyHeader]}") + .to("log:knative"); + } + + @BindToRegistry("my-bean") + public static String myBean() { + return "my-bean-string"; + } +} \ No newline at end of file diff --git a/camel-k-loader-kotlin/pom.xml b/camel-k-loader-kotlin/pom.xml index 2063906f2..1d27cfd2b 100644 --- a/camel-k-loader-kotlin/pom.xml +++ b/camel-k-loader-kotlin/pom.xml @@ -193,7 +193,8 @@ org.apache.maven.plugins maven-surefire-plugin - 0 + 1 + false diff --git a/camel-k-main/camel-k-runtime-main/pom.xml b/camel-k-main/camel-k-runtime-main/pom.xml index c82659416..c73beb381 100644 --- a/camel-k-main/camel-k-runtime-main/pom.xml +++ b/camel-k-main/camel-k-runtime-main/pom.xml @@ -148,6 +148,11 @@ camel-k-loader-kotlin test + + org.apache.camel.k + camel-k-runtime-knative + test + diff --git a/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java index b5256e56c..59681e641 100644 --- a/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java +++ b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java @@ -20,16 +20,22 @@ import org.apache.camel.CamelContext; import org.apache.camel.Route; +import org.apache.camel.component.knative.KnativeComponent; +import org.apache.camel.component.knative.spi.Knative; +import org.apache.camel.component.knative.spi.KnativeEnvironment; import org.apache.camel.k.Runtime; +import org.apache.camel.k.http.PlatformHttpServiceContextCustomizer; import org.apache.camel.k.listener.ContextConfigurer; import org.apache.camel.k.listener.RoutesConfigurer; +import org.apache.camel.k.test.AvailablePortFinder; import org.apache.camel.model.ModelCamelContext; -import org.apache.camel.util.CollectionHelper; +import org.apache.camel.model.ToDefinition; import org.apache.camel.util.ObjectHelper; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.camel.util.CollectionHelper.mapOf; import static org.assertj.core.api.Assertions.assertThat; public class RuntimeTest { @@ -82,7 +88,7 @@ void testLoadRouteAndRest() throws Exception { @Test void testLoadRouteWithExpression() throws Exception { - runtime.setProperties(CollectionHelper.mapOf( + runtime.setProperties(mapOf( "the.body", "10" )); @@ -105,4 +111,30 @@ public void testLoadJavaSource() throws Exception { }); } + @Test + public void testLoadJavaSourceWrap() throws Exception { + KnativeComponent component = new KnativeComponent(); + component.setEnvironment(KnativeEnvironment.on( + KnativeEnvironment.endpoint(Knative.EndpointKind.sink, "sink", "localhost", AvailablePortFinder.getNextAvailable()) + )); + + PlatformHttpServiceContextCustomizer phsc = new PlatformHttpServiceContextCustomizer(); + phsc.setBindPort(AvailablePortFinder.getNextAvailable()); + phsc.apply(runtime.getCamelContext()); + + runtime.getCamelContext().addComponent("knative", component); + runtime.addListener(RoutesConfigurer.forRoutes("classpath:MyRoutesWithBeans.java?interceptors=knative-source")); + runtime.addListener(Runtime.Phase.Started, r -> runtime.stop()); + runtime.run(); + + assertThat(runtime.getRegistry().lookupByName("my-bean")).isInstanceOfSatisfying(MyBean.class, b -> { + assertThat(b).hasFieldOrPropertyWithValue("name", "my-bean-name"); + }); + assertThat(runtime.getCamelContext(ModelCamelContext.class).getRouteDefinition("my-route")).satisfies(definition -> { + assertThat(definition.getOutputs()).last().isInstanceOfSatisfying(ToDefinition.class, to -> { + assertThat(to.getEndpointUri()).isEqualTo("knative://endpoint/sink"); + }); + }); + } + } diff --git a/camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java b/camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java index 530fe17b1..0659a75a2 100644 --- a/camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java +++ b/camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java @@ -22,6 +22,7 @@ public class MyRoutesWithBeans extends RouteBuilder { @Override public void configure() throws Exception { from("direct:start") + .routeId("my-route") .bean("my-bean", "getName") .to("log:info"); } diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java index 3a6a65bb0..517d1bd59 100644 --- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java +++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java @@ -32,6 +32,11 @@ import static org.apache.camel.util.CollectionHelper.mapOf; public interface Runtime extends HasCamelContext { + + default T getCamelContext(Class type) { + return getCamelContext().adapt(type); + } + /** * Returns the registry associated to this runtime. */ diff --git a/camel-k-runtime-knative/pom.xml b/camel-k-runtime-knative/pom.xml index 520c0a93c..ac49471b9 100644 --- a/camel-k-runtime-knative/pom.xml +++ b/camel-k-runtime-knative/pom.xml @@ -107,11 +107,6 @@ camel-mock test - - org.apache.camel - camel-undertow - test - org.apache.camel camel-cloud @@ -138,7 +133,8 @@ maven-surefire-plugin false - 0 + 1 + false diff --git a/camel-k-runtime-knative/src/test/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoaderTest.java b/camel-k-runtime-knative/src/test/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoaderTest.java index 6039a0955..e03629919 100644 --- a/camel-k-runtime-knative/src/test/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoaderTest.java +++ b/camel-k-runtime-knative/src/test/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoaderTest.java @@ -23,7 +23,6 @@ import java.util.stream.Stream; import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.knative.KnativeComponent; @@ -37,11 +36,9 @@ import org.apache.camel.k.Sources; import org.apache.camel.k.http.PlatformHttpServiceContextCustomizer; import org.apache.camel.k.listener.RoutesConfigurer; -import org.apache.camel.k.loader.java.JavaSourceLoader; import org.apache.camel.k.test.AvailablePortFinder; import org.apache.camel.model.ModelCamelContext; import org.apache.camel.model.RouteDefinition; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -69,15 +66,14 @@ static Stream parameters() { public void testWrapLoader(String uri) throws Exception { LOGGER.info("uri: {}", uri); - final int port = AvailablePortFinder.getNextAvailable(); final String data = UUID.randomUUID().toString(); + final TestRuntime runtime = new TestRuntime(); KnativeComponent component = new KnativeComponent(); component.setEnvironment(KnativeEnvironment.on( - KnativeEnvironment.endpoint(Knative.EndpointKind.sink, "sink", "localhost", port) + KnativeEnvironment.endpoint(Knative.EndpointKind.sink, "sink", "localhost", runtime.port) )); - TestRuntime runtime = new TestRuntime(); CamelContext context = runtime.getCamelContext(); context.disableJMX(); @@ -95,7 +91,7 @@ public void testWrapLoader(String uri) throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { - fromF("undertow:http://localhost:%d", port) + fromF("platform-http:/") .routeId("http") .to("mock:result"); } @@ -128,62 +124,25 @@ public void configure() throws Exception { } } - @Test - public void testWrapLoaderWithBeanRegistration() throws Exception { - final int port = AvailablePortFinder.getNextAvailable(); - - KnativeComponent component = new KnativeComponent(); - component.setEnvironment(KnativeEnvironment.on( - KnativeEnvironment.endpoint(Knative.EndpointKind.sink, "sink", "localhost", port) - )); - - TestRuntime runtime = new TestRuntime(); - - CamelContext context = runtime.getCamelContext(); - context.disableJMX(); - context.setStreamCaching(true); - context.addComponent("knative", component); - - Source source = Sources.fromURI("classpath:sources/routes.java?name=MyRoutes.java&interceptors=knative-source"); - SourceLoader loader = RoutesConfigurer.load(runtime, source); - - assertThat(loader.getSupportedLanguages()).contains(source.getLanguage()); - assertThat(loader).isInstanceOf(JavaSourceLoader.class); - assertThat(runtime.builders).hasSize(1); - - try { - RoutesBuilder builder = runtime.builders.get(0); - - context.addRoutes(builder); - - context.adapt(ExtendedCamelContext.class) - .getBeanPostProcessor() - .postProcessBeforeInitialization(builder, builder.getClass().getName()); - context.adapt(ExtendedCamelContext.class) - .getBeanPostProcessor() - .postProcessAfterInitialization(builder, builder.getClass().getName()); - - context.start(); - - assertThat(context.getRegistry().lookupByName("my-bean")).isInstanceOfSatisfying(String.class, "my-bean-string"::equals); - } finally { - context.stop(); - } - } - static class TestRuntime implements Runtime { private final CamelContext camelContext; private final List builders; + private final int port; public TestRuntime() { this.camelContext = new DefaultCamelContext(); this.builders = new ArrayList<>(); + this.port = AvailablePortFinder.getNextAvailable(); PlatformHttpServiceContextCustomizer httpService = new PlatformHttpServiceContextCustomizer(); - httpService.setBindPort(AvailablePortFinder.getNextAvailable()); + httpService.setBindPort(this.port); httpService.apply(this.camelContext); } + public int getPort() { + return port; + } + @Override public CamelContext getCamelContext() { return this.camelContext; From 287f04609d4124f0a066e2c18bf8088741a532e1 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Thu, 26 Mar 2020 08:38:44 +0100 Subject: [PATCH 2/2] Enforce plugin versions --- pom.xml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pom.xml b/pom.xml index 59c5a28ca..10c661a14 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,10 @@ 3.1.0 3.2.0 3.2.1 + 3.1.0 + 1.4.1 + 3.1.0 + 3.9.0 @@ -115,6 +119,26 @@ + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-site-plugin + ${maven-site-plugin.version} + org.apache.maven.plugins maven-compiler-plugin @@ -135,6 +159,15 @@ + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + false + + + + org.apache.maven.plugins maven-remote-resources-plugin ${maven-remote-resources-plugin.version}