Skip to content

Commit

Permalink
loader-java: add test for compiling routes requiring external classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Nov 23, 2019
1 parent b3189c0 commit 755df81
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<? extends RoutesLoader> type) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions camel-k-loader-java/src/test/resources/MyRoutesWithModel.java
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit 755df81

Please sign in to comment.