Skip to content

Add integration test for text/plain registry resource via synapse expressions (#4436)#4790

Open
SasinduDilshara wants to merge 1 commit intowso2:masterfrom
SasinduDilshara:fix-4436
Open

Add integration test for text/plain registry resource via synapse expressions (#4436)#4790
SasinduDilshara wants to merge 1 commit intowso2:masterfrom
SasinduDilshara:fix-4436

Conversation

@SasinduDilshara
Copy link
Copy Markdown

@SasinduDilshara SasinduDilshara commented Apr 6, 2026

Summary

  • Adds a regression integration test for issue Accessing text-type registry resource through synapse expressions fails #4436: accessing a text/plain registry resource through the registry() synapse expression function.
  • The test deploys a CApp containing a text/plain registry resource and an API that reads it via a synapse expression, then verifies the plain text value is returned correctly and no Base64 decoding error appears in the logs.

Test Plan

  • SynapseExpressionTextPlainRegistryTestCase (integration test):
    • Deploys SynapseExpressionTextPlainTestCase_1.0.0.car containing a text/plain registry resource with content "Hello from registry text resource" and a test API.
    • Invokes the API and asserts the log mediator output contains regTextValue = Hello from registry text resource.
    • Asserts that Illegal base64 character does NOT appear in the logs.

Related

Issue Analysis

Issue: Accessing text-type registry resource through synapse expressions fails

Classification: Bug — High severity. All text/plain registry resources (the default media type) are unusable via synapse expressions.

Root Cause: EvaluationContext.getRegistryResource() in wso2-synapse unconditionally Base64-decoded every OMText registry resource. text/plain nodes are stored as plain OMText (isBinary() == false), causing IllegalArgumentException: Illegal base64 character 20 on any text with spaces.

Fix (in wso2-synapse): Check omText.isBinary() before decoding; return plain text directly when not binary.

Closes: #4436

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added integration test validating plain text registry resource handling in Synapse expressions. Ensures correct processing of registry values without encoding-related errors during API operations.

…ressions

Regression test for issue wso2#4436: verifies that accessing a text/plain
registry resource through the registry() synapse expression returns the
plain text content without triggering a Base64 decoding error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment on lines +54 to +58
public void setUp() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(context);
carbonLogReader = new CarbonLogReader();
carbonLogReader.start();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 1

Suggested change
public void setUp() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(context);
carbonLogReader = new CarbonLogReader();
carbonLogReader.start();
public void setUp() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(context);
carbonLogReader = new CarbonLogReader();
carbonLogReader.start();
log.info("Setting up test case for SynapseExpression text/plain registry resource test");

Comment on lines +64 to +67
public void testTextPlainRegistryResourceViaSynapseExpression() throws Exception {
// Deploy the CApp that contains the text/plain registry resource and a test API
File capp = new File(
getESBResourceLocation() + File.separator + "synapseExpressions" + File.separator + CAPP_NAME);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 2

Suggested change
public void testTextPlainRegistryResourceViaSynapseExpression() throws Exception {
// Deploy the CApp that contains the text/plain registry resource and a test API
File capp = new File(
getESBResourceLocation() + File.separator + "synapseExpressions" + File.separator + CAPP_NAME);
// Deploy the CApp that contains the text/plain registry resource and a test API
File capp = new File(
getESBResourceLocation() + File.separator + "synapseExpressions" + File.separator + CAPP_NAME);
log.info("Deploying CApp: " + CAPP_NAME + " for text/plain registry resource test");
serverConfigurationManager.copyToCarbonapps(capp);

Copy link
Copy Markdown
Contributor

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

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

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

Walkthrough

A new TestNG integration test class is added to validate that plain text registry resources are correctly handled by Synapse expressions without being misinterpreted as Base64 encoded data during API invocation.

Changes

Cohort / File(s) Summary
Integration Test for Plain Text Registry
integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/synapse/expression/test/SynapseExpressionTextPlainRegistryTestCase.java
New TestNG integration test class with setUp(), testTextPlainRegistryResourceViaSynapseExpression(), and tearDown() methods. Deploys a CarbonApp, verifies proper handling of plain text registry resources via Synapse expressions, and asserts absence of Base64 decoding errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A test hops in to check the way,
Plain text from registry holds sway,
No Base64 tricks to decode,
Just simple strings along the road,
Synapse expressions dance and play! 📝

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add integration test for text/plain registry resource via synapse expressions (#4436)' clearly and concisely describes the main change—adding a new integration test for a specific issue.
Description check ✅ Passed The description includes a clear summary of the test purpose, detailed test plan with specific assertions, and relevant issue/PR cross-references and analysis.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/synapse/expression/test/SynapseExpressionTextPlainRegistryTestCase.java (2)

73-77: Consider validating the HTTP response status.

The HTTP response from doGet is discarded. While the log-based assertion may be sufficient for this regression test, validating that the API returns a successful HTTP status (e.g., 200) would make the test more robust and help distinguish between different failure modes.

🔧 Optional improvement to validate response
         // Invoke the API
         String url = getApiInvocationURL(API_NAME);
         SimpleHttpClient httpClient = new SimpleHttpClient();
         Map<String, String> headers = new HashMap<>();
-        httpClient.doGet(url, headers);
+        org.apache.http.HttpResponse response = httpClient.doGet(url, headers);
+        int statusCode = response.getStatusLine().getStatusCode();
+        assertTrue(statusCode == 200, "Expected HTTP 200 but got " + statusCode);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/synapse/expression/test/SynapseExpressionTextPlainRegistryTestCase.java`
around lines 73 - 77, The test currently discards the HTTP response from
SimpleHttpClient.doGet when invoking getApiInvocationURL(API_NAME); change the
code to capture the response returned by SimpleHttpClient.doGet(url, headers)
and assert the HTTP status is 200 (or another expected success code) before
proceeding; reference the SimpleHttpClient.doGet call and
API_NAME/getApiInvocationURL to locate where to store the response and add an
assertion on its status to make the test robust.

1-17: Minor: Copyright year may be outdated.

The copyright year is 2024, but the current year is 2026. Consider updating to 2026 if this is newly written code.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/synapse/expression/test/SynapseExpressionTextPlainRegistryTestCase.java`
around lines 1 - 17, Update the file header copyright year from 2024 to 2026 in
the test class file (SynapseExpressionTextPlainRegistryTestCase); locate the
block comment at the top of the file and change the year value so the header
reflects the current year (2026).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/synapse/expression/test/SynapseExpressionTextPlainRegistryTestCase.java`:
- Around line 73-77: The test currently discards the HTTP response from
SimpleHttpClient.doGet when invoking getApiInvocationURL(API_NAME); change the
code to capture the response returned by SimpleHttpClient.doGet(url, headers)
and assert the HTTP status is 200 (or another expected success code) before
proceeding; reference the SimpleHttpClient.doGet call and
API_NAME/getApiInvocationURL to locate where to store the response and add an
assertion on its status to make the test robust.
- Around line 1-17: Update the file header copyright year from 2024 to 2026 in
the test class file (SynapseExpressionTextPlainRegistryTestCase); locate the
block comment at the top of the file and change the year value so the header
reflects the current year (2026).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c31399bb-4f4c-4197-951b-5e5fbe6f7424

📥 Commits

Reviewing files that changed from the base of the PR and between ba3568b and dacd835.

📒 Files selected for processing (2)
  • integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/synapse/expression/test/SynapseExpressionTextPlainRegistryTestCase.java
  • integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/synapseExpressions/SynapseExpressionTextPlainTestCase_1.0.0.car

@SasinduDilshara
Copy link
Copy Markdown
Author

SasinduDilshara commented Apr 6, 2026

Please check wso2/wso2-synapse#2528
for the issue analysis and the verification report.

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.

Accessing text-type registry resource through synapse expressions fails

1 participant