github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/microprofile/api_test.mustache (about)

     1  {{>licenseInfo}}
     2  
     3  package {{package}};
     4  
     5  {{#imports}}import {{import}};
     6  {{/imports}}
     7  import org.junit.Test;
     8  import org.junit.Before;
     9  import static org.junit.Assert.*;
    10  
    11  import org.eclipse.microprofile.rest.client.RestClientBuilder;
    12  
    13  import java.net.URL;
    14  import java.net.MalformedURLException;
    15  {{^fullJavaUtil}}
    16  import java.util.ArrayList;
    17  import java.util.HashMap;
    18  import java.util.List;
    19  import java.util.Map;
    20  {{/fullJavaUtil}}
    21  
    22  
    23  
    24  /**
    25   {{#appName}}
    26   * {{{appName}}} Test
    27   *
    28   {{/appName}}
    29   * API tests for {{classname}}
    30   */
    31  {{#generateSpringBootApplication}}
    32  @RunWith(SpringJUnit4ClassRunner.class)
    33  @SpringApplicationConfiguration(classes = SpringBootApplication.class)
    34  @WebAppConfiguration
    35  @IntegrationTest("server.port=0")
    36  {{/generateSpringBootApplication}}
    37  public class {{classname}}Test {
    38  
    39      private {{classname}} client;
    40      private String baseUrl = "http://localhost:9080";
    41  
    42      @Before
    43      public void setup() throws MalformedURLException {
    44          client = RestClientBuilder.newBuilder()
    45                          .baseUrl(new URL(baseUrl))
    46                          .register(ApiException.class)
    47                          .build({{classname}}.class);
    48      }
    49  
    50      {{#operations}}{{#operation}}
    51      /**
    52       {{#summary}}
    53       * {{summary}}
    54       *
    55       {{#notes}}
    56       * {{notes}}
    57       *
    58       {{/notes}}
    59       {{/summary}}
    60       * @throws ApiException
    61       *          if the Api call fails
    62       */
    63      @Test
    64      public void {{operationId}}Test() {
    65      	// TODO: test validations
    66          {{#allParams}}
    67          {{^isFile}}{{{dataType}}} {{paramName}} = null;{{/isFile}}{{#isFile}}org.apache.cxf.jaxrs.ext.multipart.Attachment {{paramName}} = null;{{/isFile}}
    68          {{/allParams}}
    69          //{{#returnType}}{{{returnType}}} response = {{/returnType}}api.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
    70          //{{#returnType}}assertNotNull(response);{{/returnType}}
    71  
    72  
    73      }
    74      {{/operation}}{{/operations}}
    75  }