All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java-camel-server.test.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package {{apiPackage}};

import org.junit.jupiter.api.Test;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.springframework.boot.test.context.SpringBootTest;
import com.mashape.unirest.request.HttpRequest;
import com.mashape.unirest.request.HttpRequestWithBody;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.HttpResponse;
import java.io.InputStream;
import org.junit.jupiter.api.Assertions;

@CamelSpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class {{classname}}Test {
    private static final String API_URL = "http://127.0.0.1:8080/api/v1";
{{#operations}}{{#operation}}{{#examples}}{{#-first}}{{#vendorExtensions}}{{^camelRestBindingMode}}
    @Test
    public void {{operationId}}TestJson() throws Exception {
        String contentType = "application/json";
        String accept = "application/json";
        String url = API_URL + "{{path}}";
        HttpRequest httpRequest = Unirest.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(url);{{#hasConsumes}}
        httpRequest = httpRequest.header("Content-Type", contentType);{{/hasConsumes}}{{#hasProduces}}
        httpRequest = httpRequest.header("Accept", accept);{{/hasProduces}}{{#pathParams}}
        httpRequest = httpRequest.routeParam("{{paramName}}", "1");{{/pathParams}}{{#queryParams}}
        httpRequest = httpRequest.queryString("{{paramName}}", "1");{{/queryParams}}
        {{#hasConsumes}}{{#examples}}{{#-first}}
        String requestBody = {{>exampleString}};
        httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest();
        {{/-first}}{{/examples}}{{/hasConsumes}}
        {{#hasProduces}}{{#produces}}{{#isJson}}
        HttpResponse httpResponse = httpRequest.asJson();{{/isJson}}{{/produces}}{{/hasProduces}}{{^hasProduces}}
        HttpResponse httpResponse = httpRequest.asBinary();{{/hasProduces}}
        Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415);
    }
    {{#examples}}{{#-last}}{{^isArray}}
    @Test
    public void {{operationId}}TestXml() throws Exception {
        String contentType = "application/xml";
        String accept = "application/xml";
        String url = API_URL + "{{path}}";
        HttpRequest httpRequest = Unirest.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(url);{{#hasConsumes}}
        httpRequest = httpRequest.header("Content-Type", contentType);{{/hasConsumes}}{{#hasProduces}}
        httpRequest = httpRequest.header("Accept", accept);{{/hasProduces}}{{#pathParams}}
        httpRequest = httpRequest.routeParam("{{paramName}}", "1");{{/pathParams}}{{#queryParams}}
        httpRequest = httpRequest.queryString("{{paramName}}", "1");{{/queryParams}}
        {{#hasConsumes}}{{#examples}}{{^-first}}
        String requestBody = {{>exampleString}};
        httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest();
        {{/-first}}{{/examples}}{{/hasConsumes}}
        {{#hasProduces}}{{#produces}}{{#isXml}}
        HttpResponse httpResponse = httpRequest.asString();{{/isXml}}{{/produces}}{{/hasProduces}}{{^hasProduces}}
        HttpResponse httpResponse = httpRequest.asBinary();{{/hasProduces}}
        Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415);
    }{{/isArray}}{{/-last}}{{/examples}}{{/camelRestBindingMode}}{{/vendorExtensions}}{{/-first}}{{/examples}}{{/operation}}{{/operations}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy