Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Refactoring (With new test cases) #16994

Merged
merged 9 commits into from
Nov 7, 2023
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,19 @@ public class BirdAndCategoryTest {
*/
@Test
public void testBirdAndCategory() {
// TODO: test BirdAndCategory
birdAndCategory.setSize("Small");
assertEquals("Small", birdAndCategory.getSize());

birdAndCategory.setSize("Large");
Copy link
Member

@wing328 wing328 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be model instead of birdAndCategory ?

same for line 37

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let me change and push it.

assertEquals("Large", birdAndCategory.getSize());
}

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

}

/**
Expand Down
Loading