You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/11/23 18:05:04 UTC
[camel-k-runtime] branch master updated: loader-java: add test for
compiling routes requiring external classes
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push:
new 755df81 loader-java: add test for compiling routes requiring external classes
755df81 is described below
commit 755df816a4a58896cdef912e1f54078e017d5fe6
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sat Nov 23 18:29:48 2019 +0100
loader-java: add test for compiling routes requiring external classes
---
.../camel/k/loader/java/RoutesLoaderTest.java | 21 ++++++++++
.../camel/k/loader/java/model/EmployeeDTO.java | 47 ++++++++++++++++++++++
.../src/test/resources/MyRoutesWithModel.java | 32 +++++++++++++++
3 files changed, 100 insertions(+)
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 d9cc59c..6d73eb5 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.RoutesLoader;
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 class RoutesLoaderTest {
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<? extends RoutesLoader> 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 0000000..65c4918
--- /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 0000000..20e1c99
--- /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