Skip to content

Commit

Permalink
[JAXRS-CXF] Improve handling of additional properties in JavaCXFClien…
Browse files Browse the repository at this point in the history
…tCodegen (#7866)
  • Loading branch information
cowclaw authored Nov 4, 2020
1 parent e3121af commit 2f30960
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,30 @@ public JavaCXFClientCodegen() {
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
Expand Down Expand Up @@ -154,20 +151,40 @@ public String getHelp() {
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
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;

Expand Down Expand Up @@ -118,4 +122,61 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
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());
}

}

0 comments on commit 2f30960

Please sign in to comment.