Skip to content

Add api_test.mustache template for auto-generated test classes#1674

Open
agrja-rastogi-okta wants to merge 5 commits intomasterfrom
api-test-template-pr
Open

Add api_test.mustache template for auto-generated test classes#1674
agrja-rastogi-okta wants to merge 5 commits intomasterfrom
api-test-template-pr

Conversation

@agrja-rastogi-okta
Copy link
Contributor

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.

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<>());
Copy link
Contributor

Choose a reason for hiding this comment

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

prerequisiteObject is extracted but never referenced anywhere in the test body.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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));
Copy link
Contributor

Choose a reason for hiding this comment

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

fileContent is declared, conditionally populated by reading from disk, but never passed to any API method call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed all unused variables, this will be handled in a helper now.

import {{import}};
{{/imports}}

import java.io.File;
Copy link
Contributor

Choose a reason for hiding this comment

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

java.io.File is imported but never used anywhere in the template. This will produce an unused import warning in every generated class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed all unused imports.

agrja-rastogi-okta added a commit that referenced this pull request Feb 25, 2026
… 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is also not being called anywhere but it is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

The toSnakeCase method was defined but never called anywhere
in the template or generated test files.
Copy link
Contributor

@prachi-okta prachi-okta left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants