Skip to content

Commit

Permalink
add test templates for CXF swagger-api#2017
Browse files Browse the repository at this point in the history
  • Loading branch information
jfiala committed Jul 2, 2016
1 parent 4766b9b commit 412dcd1
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public JavaCXFServerCodegen()
supportsInheritance = true;
sourceFolder = "gen" + File.separator + "java";
outputFolder = "generated-code/JavaJaxRS-CXF";
apiTestTemplateFiles.clear(); // TODO: add test template


// clear model and api doc template as this codegen
// does not support auto-generated markdown doc at the moment
//TODO: add doc templates
Expand All @@ -34,6 +33,8 @@ public JavaCXFServerCodegen()
importMapping.put("LocalDate", "org.joda.time.LocalDate");

embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";

setSkipOverwrite(false);

}

Expand All @@ -43,6 +44,10 @@ public void processOpts()
{
super.processOpts();





supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package {{package}};
import java.util.Objects;
{{#imports}}
import {{import}};
import javax.validation.constraints.*;
{{/imports}}
import javax.validation.constraints.*;

{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
{{#models}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{>licenseInfo}}

package {{package}};

{{#imports}}import {{import}};
{{/imports}}
import org.junit.Test;
import org.junit.Before;

import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
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}}

/**
* API tests for {{classname}}
*/
public class {{classname}}Test {
private {{classname}} api;

@Before
public void setup() {
JacksonJsonProvider provider = new JacksonJsonProvider();
List providers = new ArrayList();
providers.add(provider);
api = JAXRSClientFactory.create("{{basePath}}", {{classname}}.class, providers);
}

{{#operations}}{{#operation}}
/**
* {{summary}}
*
* {{notes}}
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void {{operationId}}Test() {
{{#allParams}}
{{{dataType}}} {{paramName}} = new {{{dataType}}}();
{{/allParams}}
Response response = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});

{{#returnType}}{{{returnType}}} responseModel = response.readEntity({{{returnType}}}.class);{{/returnType}}

// TODO: test validations
}
{{/operation}}{{/operations}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* {{{appName}}}
* {{{appDescription}}}
*
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*
* Licensed 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.
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package {{package}};

{{#imports}}import {{import}};
{{/imports}}
import javax.validation.constraints.*;

{{#models}}
{{#model}}{{#description}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
* maximum: {{maximum}}{{/maximum}}
**/
{{#required}}
@NotNull{{/required}}{{!
}}{{#pattern}}
@Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}}
@Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}}
@Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
@Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minimum}}
//@Min({{minimum}}){{/minimum}}{{#maximum}}
//@Max({{maximum}}){{/maximum}}
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,20 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<!-- CXF Client -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.1.6</version>
<scope>test</scope>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down

0 comments on commit 412dcd1

Please sign in to comment.