JavaJaxRS.cxf.api_test.mustache Maven / Gradle / Ivy
{{>licenseInfo}}
package {{package}};
{{#imports}}import {{import}};
{{/imports}}
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.WebClient;
{{#useGzipFeature}}
import org.apache.cxf.transport.common.gzip.GZIPInInterceptor;
import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
{{/useGzipFeature}}
{{#useLoggingFeature}}
import org.apache.cxf.interceptor.LoggingOutInterceptor;
{{/useLoggingFeature}}
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
{{^fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{#generateSpringBootApplication}}
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
{{/generateSpringBootApplication}}
/**
{{#appName}}
* {{{appName}}}
*
{{/appName}}
{{#appDescription}}
* {{{appDescription}}}
*
{{/appDescription}}
* API tests for {{classname}}
*/
{{#generateSpringBootApplication}}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SpringBootApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port=0")
{{/generateSpringBootApplication}}
public class {{classname}}Test {
{{#generateSpringBootApplication}}
@Value("${local.server.port}")
private int serverPort;
{{/generateSpringBootApplication}}
private {{classname}} api;
@Before
public void setup() {
JacksonJsonProvider provider = new JacksonJsonProvider();
List providers = new ArrayList();
providers.add(provider);
{{#generateSpringBootApplication}}
api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services", {{classname}}.class, providers);
{{/generateSpringBootApplication}}
{{^generateSpringBootApplication}}
api = JAXRSClientFactory.create("{{{basePath}}}", {{classname}}.class, providers);
{{/generateSpringBootApplication}}
org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
ClientConfiguration config = WebClient.getConfig(client);
{{#useGzipFeatureForTests}}
// Example for using Gzipping
GZIPOutInterceptor gzipOutInterceptor = new GZIPOutInterceptor();
// use Gzipping for first request sent to server
//gzipOutInterceptor.setForce(true);
config.getOutInterceptors().add(gzipOutInterceptor);
config.getInInterceptors().add(new GZIPInInterceptor());
{{/useGzipFeatureForTests}}
{{#useLoggingFeatureForTests}}
LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();
config.getOutInterceptors().add(loggingOutInterceptor);
{{/useLoggingFeatureForTests}}
}
{{#operations}}{{#operation}}
/**
{{#summary}}
* {{summary}}
*
{{#notes}}
* {{notes}}
*
{{/notes}}
{{/summary}}
* @throws ApiException
* if the Api call fails
*/
@Test
public void {{operationId}}Test() {
{{#allParams}}
{{^isFile}}{{{dataType}}} {{paramName}} = null;{{/isFile}}{{#isFile}}org.apache.cxf.jaxrs.ext.multipart.Attachment {{paramName}} = null;{{/isFile}}
{{/allParams}}
//{{^vendorExtensions.x-java-is-response-void}}{{>returnTypes}} response = {{/vendorExtensions.x-java-is-response-void}}api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{^vendorExtensions.x-java-is-response-void}}//assertNotNull(response);{{/vendorExtensions.x-java-is-response-void}}
// TODO: test validations
}
{{/operation}}{{/operations}}
}