
mel.camel-api-component-maven-plugin.2.18.0.source-code.api-route-test.vm Maven / Gradle / Ivy
## ------------------------------------------------------------------------
## 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.
## ------------------------------------------------------------------------
## api-route-test.vm
/*
* Camel Api Route test generated by camel-api-component-maven-plugin
* Generated on: $generatedDate
*/
package $componentPackage;
import java.util.HashMap;
import java.util.Map;
import org.apache.camel.builder.RouteBuilder;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ${packageName}.${componentName}ApiCollection;
import ${packageName}.${enumName};
/**
* Test class for {@link ${proxyType.Name}} APIs.
* TODO Move the file to src/test/java, populate parameter values, and remove @Ignore annotations.
* The class source won't be generated again if the generator MOJO finds it under src/test/java.
*/
public class ${testName} extends Abstract${componentName}TestSupport {
private static final Logger LOG = LoggerFactory.getLogger(${testName}.class);
private static final String PATH_PREFIX = ${componentName}ApiCollection.getCollection().getApiName(${enumName}.class).getName();
#foreach ( $model in $models )
#set ( $testName = $helper.getTestName($model) )
#set ( $args = $model.Arguments )
#set ( $resultType = $model.ResultType )
#set ( $voidResult = $helper.isVoidType($resultType) )
## are parameter values needed
#if ( !$args.isEmpty() )
// TODO provide parameter values for $model.Name
#end
@Ignore
@Test
public void test${testName}() throws Exception {
## single argument, use as body
#if ( $args.size() == 1 )
#set ( $argType = $args.get(0).Type )
// using $helper.getCanonicalName($argType) message body for single parameter "$args.get(0).Name"
## multiple arguments, pass them as headers
#elseif ( $args.size() > 1 )
final Map headers = new HashMap();
#foreach ( $arg in $args )
#if ( !$arg.Type.isPrimitive() )
// parameter type is $helper.getCanonicalName($arg.Type)
headers.put("${helper.getExchangePropertyPrefix()}${arg.Name}", null);
#else
headers.put("${helper.getExchangePropertyPrefix()}${arg.Name}", $helper.getDefaultArgValue($arg.Type));
#end
#end
#end
## method invocation result
#if ( !$voidResult )#set ( $type = $helper.getResultDeclaration($resultType) )final $type result = #end
## actual template call
#if ( $args.isEmpty() )
requestBody("direct://${model.UniqueName}", null);
#elseif ( $args.size() == 1 )
## typecast body to avoid requestBody() conflict
requestBody("direct://${model.UniqueName}", $helper.getDefaultArgValue($argType));
#else
requestBodyAndHeaders("direct://${model.UniqueName}", null, headers);
#end
#if ( !$voidResult )
assertNotNull("${model.Name} result", result);
LOG.debug("${model.Name}: " + result);
#end
}
#end
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
#foreach ( $model in $models )
#set ( $args = $model.Arguments )
// test route for $model.Name
from("direct://${model.UniqueName}")
.to("${scheme}://" + PATH_PREFIX + "/${model.Name}#if ( $args.size() == 1 )?inBody=${args.get(0).Name}#end");
#end
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy