Skip to content

Add test coverage for JsonErrorReportValve#965

Open
onkar717 wants to merge 2 commits intoapache:mainfrom
onkar717:add-json-error-report-valve-tests
Open

Add test coverage for JsonErrorReportValve#965
onkar717 wants to merge 2 commits intoapache:mainfrom
onkar717:add-json-error-report-valve-tests

Conversation

@onkar717
Copy link
Copy Markdown

Description

Add dedicated test coverage for JsonErrorReportValve.

JsonErrorReportValve currently lacks specific tests compared to ErrorReportValve. This PR introduces TestJsonErrorReportValve to verify JSON error reporting behavior.

Motivation

JsonErrorReportValve does not currently have dedicated tests. Adding coverage helps ensure correctness and stability of JSON error reporting functionality.

Tests added

• JSON response for HTTP 500 errors
• JSON response for HTTP 404 errors
• Throwable information when exceptions occur
• JSON escaping of special characters
• Custom status code handling
• Chained exception handling

Implementation notes

Tests follow existing patterns from TestErrorReportValve and use TomcatBaseTest utilities. No new dependencies were introduced.

Impact

Improves test coverage and helps prevent regressions.

No production code changes were made.
This is a test-only change.

@dsoumis
Copy link
Copy Markdown
Member

dsoumis commented Mar 23, 2026

You can utilize org.apache.tomcat.util.json.JSONParser to parse the response instead of using the body.contains() method.

Assert.assertNotNull(body);
// Verify JSON structure
Assert.assertTrue("Response should contain type field",
body.contains("\"type\":"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It needs a space after the ':'

Assert.assertNotNull(body);
// Verify JSON structure
Assert.assertTrue("Response should contain type field",
body.contains("\"type\":"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can also verify that type contains a value of "errorReportValve.exceptionReport" or "errorReportValve.statusReport" equivalently for each test scenario


// Characters that require JSON escaping: quotes and backslashes
String specialMessage =
"Error with \"quotes\" and \\backslash\\ and <angle>";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

angle brackets are not escaped

@rmaucher
Copy link
Copy Markdown
Contributor

@onkar717 onkar717 force-pushed the add-json-error-report-valve-tests branch from 5cb0b42 to 6f9926e Compare March 24, 2026 13:50
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.

3 participants