Skip to content

Commit

Permalink
Added some Test Cases (#16994)
Browse files Browse the repository at this point in the history
* New Test Case Added to AndroidClientCodegenTest

* New Test Case Added to GenApiControllerTest

* New Test Case Added to BirdAndCategoryTest

* New Test Case Added to WorkflowSettingsTest

* Modified GenApiControllerTest

* Added Test case in JavascriptClientCodegenTest

* Modified BirdAndCategoryTest

* Modified BirdAndCategoryTest

---------

Co-authored-by: Mann <[email protected]>
  • Loading branch information
MANN3005 and mann0530 authored Nov 7, 2023
1 parent 849cf88 commit a31b38b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,23 @@ public void defaultValuesCanBeChangedBuilder(){
WorkflowSettings defaults = WorkflowSettings.newBuilder().build();
assertOnChangesToDefaults(defaults);
}
@Test
public void customOutputDirIsSet() {
WorkflowSettings settings = WorkflowSettings.newBuilder()
.withOutputDir("custom/output/directory")
.build();

assertEquals(settings.getOutputDir(), Paths.get("custom/output/directory").toAbsolutePath().toString());
}

@Test
public void customGlobalPropertiesAreSet() {
WorkflowSettings settings = WorkflowSettings.newBuilder()
.withGlobalProperty("customKey", "customValue")
.build();

Map<String, String> properties = settings.getGlobalProperties();
assertEquals(properties.size(), 1, "Global Properties map should allow custom entries");
assertEquals(properties.getOrDefault("customKey", ""), "customValue");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,12 @@ public void generateWIthForwardedHeaders() throws Exception {
.andExpect(status().isOk())
.andExpect(header().string(HttpHeaders.CONTENT_LENGTH, not(0)));
}

@Test
public void generateClientWithInvalidOpenAPIUrl() throws Exception {
String invalidOpenAPIUrl = "https://test.com:1234/invalid_openapi.json";
mockMvc.perform(post("http://test.com:1234/api/gen/clients/java")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"openAPIUrl\": \"" + invalidOpenAPIUrl + "\"}"))
.andExpect(status().isBadRequest());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,23 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker");
}
@Test
public void testHideGenerationTimestampDisabled() throws Exception {
final AndroidClientCodegen codegen = new AndroidClientCodegen();
codegen.additionalProperties().put("hideGenerationTimestamp", false);
codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("hideGenerationTimestamp"), Boolean.FALSE);
Assert.assertFalse(codegen.isHideGenerationTimestamp());
}

@Test
public void testHideGenerationTimestampEnabled() throws Exception {
final AndroidClientCodegen codegen = new AndroidClientCodegen();
codegen.additionalProperties().put("hideGenerationTimestamp", true);
codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("hideGenerationTimestamp"), Boolean.TRUE);
Assert.assertTrue(codegen.isHideGenerationTimestamp());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,17 @@ public String getHelp() {
public String getArtifactVersion() {
return this.artifactVersion;
}
@Test
void customExampleForEnumValue() {
final AbstractJavaCodegen fakeJavaCodegen = new P_AbstractJavaCodegen();
final CodegenParameter p = new CodegenParameter();
p.allowableValues = Collections.singletonMap("values", Arrays.asList("first", "second"));
p.dataType = "WrappedEnum";
p.example = "CustomEnumValue";

fakeJavaCodegen.setParameterExampleValue(p);
// Custom example value should not be modified
Assert.assertEquals(p.example, "CustomEnumValue");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,13 @@ public void testIsJsonIsXmlInProduces() throws Exception {
}
}

@Test(description = "test additional properties for code generation")
public void testAdditionalProperties() throws Exception {
final JavascriptClientCodegen codegen = new JavascriptClientCodegen();
codegen.additionalProperties().put("customProperty", "customValue");
codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("customProperty"), "customValue");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public class BirdAndCategoryTest {
*/
@Test
public void testBirdAndCategory() {
// TODO: test BirdAndCategory

}

/**
* Test the property 'size'
*/
@Test
public void sizeTest() {
// TODO: test size

}

/**
Expand Down

0 comments on commit a31b38b

Please sign in to comment.