Add api_test.mustache template for auto-generated test classes#1674
Add api_test.mustache template for auto-generated test classes#1674agrja-rastogi-okta wants to merge 5 commits intomasterfrom
Conversation
This template generates comprehensive unit tests for all API operations. Each test: - Loads prerequisite data created by Terraform - Extracts method parameters from the prerequisite data - Executes the actual API method - Validates HTTP response codes (200, 201, 202, 204) The template includes: - Smart parameter extraction that handles field name variations - Support for file uploads via file_path parameter - Automatic model deserialization with fallback to alternative class names - Comprehensive error handling and validation - Javadoc comments explaining test behavior This enables automated testing of all Okta SDK operations against live APIs while maintaining code consistency and reducing manual test maintenance.
The toSnakeCase method was not being called anywhere in the template. The camelCase to snake_case conversion is already handled by TerraformHelper.getPrerequisiteDataForTest() on the backend.
|
|
||
| // Extract parameters from prerequisite data | ||
| Map<String, Object> payload = (Map<String, Object>) prerequisiteData.getOrDefault("payload", new HashMap<>()); | ||
| Map<String, Object> prerequisiteObject = (Map<String, Object>) prerequisiteData.getOrDefault("prerequisite_object", new HashMap<>()); |
There was a problem hiding this comment.
prerequisiteObject is extracted but never referenced anywhere in the test body.
There was a problem hiding this comment.
removed all unused variables.
| byte[] fileContent = null; | ||
| if (payload.containsKey("file_path")) { | ||
| String filePath = payload.get("file_path").toString(); | ||
| fileContent = Files.readAllBytes(Paths.get(filePath)); |
There was a problem hiding this comment.
fileContent is declared, conditionally populated by reading from disk, but never passed to any API method call.
There was a problem hiding this comment.
removed all unused variables, this will be handled in a helper now.
| import {{import}}; | ||
| {{/imports}} | ||
|
|
||
| import java.io.File; |
There was a problem hiding this comment.
java.io.File is imported but never used anywhere in the template. This will produce an unused import warning in every generated class.
There was a problem hiding this comment.
removed all unused imports.
… support - Remove unused java.nio.file imports (Files, Paths) - Remove unused prerequisiteObject variable extraction - Remove unused fileContent variable and related logic - Remove unused payload variable declaration - Add file parameter handling in TerraformHelper.extractParameter() to support File type parameters like uploadApplicationLogo() This addresses all three review comments from PR #1674 while maintaining file upload capability for APIs that need it.
- Remove unused java.io.File import - Remove unused java.nio.file imports (Files, Paths) - Remove unused prerequisiteObject variable extraction - Remove unused fileContent variable and related logic - Remove unused payload variable declaration This addresses all three review comments from PR #1674.
| /** | ||
| * Convert camelCase to snake_case | ||
| */ | ||
| private String toSnakeCase(String camelCase) { |
There was a problem hiding this comment.
this is also not being called anywhere but it is defined.
The toSnakeCase method was defined but never called anywhere in the template or generated test files.
This template generates comprehensive unit tests for all API operations. Each test:
The template includes:
This enables automated testing of all Okta SDK operations against live APIs while maintaining code consistency and reducing manual test maintenance.