From 755df816a4a58896cdef912e1f54078e017d5fe6 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Sat, 23 Nov 2019 18:29:48 +0100 Subject: [PATCH] loader-java: add test for compiling routes requiring external classes --- .../camel/k/loader/java/RoutesLoaderTest.java | 21 +++++++++ .../k/loader/java/model/EmployeeDTO.java | 47 +++++++++++++++++++ .../src/test/resources/MyRoutesWithModel.java | 32 +++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/model/EmployeeDTO.java create mode 100644 camel-k-loader-java/src/test/resources/MyRoutesWithModel.java diff --git a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java index d9cc59cd4..6d73eb543 100644 --- a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java +++ b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java @@ -26,6 +26,7 @@ import org.apache.camel.k.Source; import org.apache.camel.k.Sources; import org.apache.camel.k.support.RuntimeSupport; +import org.apache.camel.model.ModelCamelContext; import org.apache.camel.model.ProcessDefinition; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.SetBodyDefinition; @@ -77,6 +78,26 @@ public void testLoadJavaWithRestConfiguration() throws Exception { assertThat(context.getRestConfigurations().iterator().next()).hasFieldOrPropertyWithValue("component", "restlet"); } + @Test + public void testLoadJavaWithModel() throws Exception { + CamelContext context = new DefaultCamelContext(); + + Source source = Sources.fromURI("classpath:MyRoutesWithModel.java"); + RoutesLoader loader = RuntimeSupport.loaderFor(new DefaultCamelContext(), source); + RouteBuilder builder = loader.load(context, source); + + assertThat(loader).isInstanceOf(JavaSourceRoutesLoader.class); + assertThat(builder).isNotNull(); + + context.addRoutes(builder); + + assertThat(context.adapt(ModelCamelContext.class).getRestDefinitions()).first().satisfies(definition -> { + assertThat(definition.getVerbs()).first().satisfies(verb -> { + assertThat(verb).hasFieldOrPropertyWithValue("outType", "org.apache.camel.k.loader.java.model.EmployeeDTO"); + }); + }); + } + @ParameterizedTest @MethodSource("parameters") public void testLoaders(String location, Class type) throws Exception { diff --git a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/model/EmployeeDTO.java b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/model/EmployeeDTO.java new file mode 100644 index 000000000..65c491878 --- /dev/null +++ b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/model/EmployeeDTO.java @@ -0,0 +1,47 @@ +/* + * 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.k.loader.java.model; + +public class EmployeeDTO { + public int id; + public String name; + public String org; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOrg() { + return org; + } + + public void setOrg(String org) { + this.org = org; + } +} diff --git a/camel-k-loader-java/src/test/resources/MyRoutesWithModel.java b/camel-k-loader-java/src/test/resources/MyRoutesWithModel.java new file mode 100644 index 000000000..20e1c9980 --- /dev/null +++ b/camel-k-loader-java/src/test/resources/MyRoutesWithModel.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.builder.RouteBuilder; + +import org.apache.camel.k.loader.java.model.EmployeeDTO; + +public class MyRoutesWithModel extends RouteBuilder { + @Override + public void configure() throws Exception { + rest("/say") + .get("/emp/{id}") + .outType(EmployeeDTO.class) + .to("direct:getEmployee"); + + from("direct:getEmployee") + .to("log:getEmployee"); + } +} \ No newline at end of file