Skip to content

Comments

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

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

Add api_test.mustache template for auto-generated test classes#1674
agrja-rastogi-okta wants to merge 3 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.

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.

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.

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