[JAXRS-CXF] Improve handling of additional properties in JavaCXFClientCodegen (#7866)

This commit is contained in:
Florian Kamella 2020-11-04 02:32:57 +01:00 committed by GitHub
parent e3121af4b4
commit 2f30960349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 10 deletions

View File

@ -88,33 +88,30 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
cliOptions.add(CliOption.newBoolean(USE_GENERIC_RESPONSE, "Use generic response"));
}
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
this.setUseBeanValidation(useBeanValidationProp);
this.setUseBeanValidation(convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION));
}
if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) {
this.setUseGenericResponse(convertPropertyToBoolean(USE_GENERIC_RESPONSE));
this.setUseGenericResponse(convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE));
}
if (useGenericResponse) {
writePropertyBack(USE_GENERIC_RESPONSE, useGenericResponse);
if (additionalProperties.containsKey(USE_GZIP_FEATURE_FOR_TESTS)) {
this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS));
}
this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS));
this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS));
if (additionalProperties.containsKey(USE_LOGGING_FEATURE_FOR_TESTS)) {
this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS));
}
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")
.doNotOverwrite());
}
@Override
@ -154,20 +151,40 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
return "Generates a Java JAXRS Client based on Apache CXF framework.";
}
@Override
public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}
public boolean isUseBeanValidation() {
return useBeanValidation;
}
@Override
public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests) {
this.useGzipFeatureForTests = useGzipFeatureForTests;
}
public boolean isUseGzipFeatureForTests() {
return useGzipFeatureForTests;
}
@Override
public void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests) {
this.useLoggingFeatureForTests = useLoggingFeatureForTests;
}
public boolean isUseLoggingFeatureForTests() {
return useLoggingFeatureForTests;
}
@Override
public void setUseGenericResponse(boolean useGenericResponse) {
this.useGenericResponse = useGenericResponse;
}
public boolean isUseGenericResponse() {
return useGenericResponse;
}
}

View File

@ -27,6 +27,10 @@ import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenResponse;
import org.openapitools.codegen.TestUtils;
import org.openapitools.codegen.languages.JavaCXFClientCodegen;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
import org.openapitools.codegen.languages.features.GzipTestFeatures;
import org.openapitools.codegen.languages.features.LoggingTestFeatures;
import org.openapitools.codegen.languages.features.UseGenericResponseFeatures;
import org.testng.Assert;
import org.testng.annotations.Test;
@ -118,4 +122,61 @@ public class JavaCXFClientCodegenTest {
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.client.xyz.invoker");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.client.xyz.invoker");
}
@Test
public void testUseBeanValidationAdditionalProperty() throws Exception {
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
codegen.processOpts();
Assert.assertNull(codegen.additionalProperties().get(BeanValidationFeatures.USE_BEANVALIDATION));
Assert.assertFalse(codegen.isUseBeanValidation());
codegen.additionalProperties().put(BeanValidationFeatures.USE_BEANVALIDATION, true);
codegen.processOpts();
Assert.assertEquals(codegen.additionalProperties().get(BeanValidationFeatures.USE_BEANVALIDATION), Boolean.TRUE);
Assert.assertTrue(codegen.isUseBeanValidation());
}
@Test
public void testUseGenericResponseAdditionalProperty() throws Exception {
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
codegen.processOpts();
Assert.assertNull(codegen.additionalProperties().get(UseGenericResponseFeatures.USE_GENERIC_RESPONSE));
Assert.assertFalse(codegen.isUseGenericResponse());
codegen.additionalProperties().put(UseGenericResponseFeatures.USE_GENERIC_RESPONSE, true);
codegen.processOpts();
Assert.assertEquals(codegen.additionalProperties().get(UseGenericResponseFeatures.USE_GENERIC_RESPONSE), Boolean.TRUE);
Assert.assertTrue(codegen.isUseGenericResponse());
}
@Test
public void testUseLoggingFeatureForTestsAdditionalProperty() throws Exception {
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
codegen.processOpts();
Assert.assertNull(codegen.additionalProperties().get(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS));
Assert.assertFalse(codegen.isUseLoggingFeatureForTests());
codegen.additionalProperties().put(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS, true);
codegen.processOpts();
Assert.assertEquals(codegen.additionalProperties().get(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS), Boolean.TRUE);
Assert.assertTrue(codegen.isUseLoggingFeatureForTests());
}
@Test
public void testUseGzipFeatureForTestsAdditionalProperty() throws Exception {
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
codegen.processOpts();
Assert.assertNull(codegen.additionalProperties().get(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS));
Assert.assertFalse(codegen.isUseLoggingFeatureForTests());
codegen.additionalProperties().put(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS, true);
codegen.processOpts();
Assert.assertEquals(codegen.additionalProperties().get(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS), Boolean.TRUE);
Assert.assertTrue(codegen.isUseGzipFeatureForTests());
}
}