Skip to content

CAMEL-24373: Refactor camel-alibaba-eventbridge constants, headers and - #25552

Open
arunsrajan wants to merge 3 commits into
apache:mainfrom
arunsrajan:feature/CAMEL-24373-alibaba-phase2
Open

CAMEL-24373: Refactor camel-alibaba-eventbridge constants, headers and#25552
arunsrajan wants to merge 3 commits into
apache:mainfrom
arunsrajan:feature/CAMEL-24373-alibaba-phase2

Conversation

@arunsrajan

Copy link
Copy Markdown

tests

Refactor constant definitions and test assertions in the Alibaba Cloud EventBridge component to improve maintainability, follow Camel conventions,
and fix unit test execution:

  1. Constants and Header Hierarchy:

    • Introduce AlibabaEventBridgeConstants for event payload field keys (eventBusName, eventSource, eventType, eventSubject, eventData) and response dictionary keys.
    • Refactor AlibabaEventBridgeHeaders into a sealed class permitted for
      AlibabaEventBridgeProperties, centralizing common Camel header names
      and avoiding duplicate field declarations.
    • Update AlibabaEventBridgeHeaders constructor to package-private visibility to allow the permitted subclass to extend it.
  2. Utils Alignment:

    • Update AlibabaEventBridgeUtils to use AlibabaEventBridgeConstants for resolving CloudEvent fields and structuring response maps.
  3. Test Fixes:

    • Update PutEventsTest to use AlibabaEventBridgeConstants for Map body
      keys, ensuring event data is properly extracted and serialized.
    • Fix Map assertion keys against response metadata constants.
    • Verify all unit tests pass with Mockito and Camel Test framework.

Description

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

AI-assisted contributions

  • If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., Co-authored-by trailers) and the PR description identifies the AI tool used.

tests

Refactor constant definitions and test assertions in the Alibaba Cloud
EventBridge component to improve maintainability, follow Camel
conventions,
and fix unit test execution:

1. Constants and Header Hierarchy:
   - Introduce AlibabaEventBridgeConstants for event payload field keys
     (eventBusName, eventSource, eventType, eventSubject, eventData) and
     response dictionary keys.
   - Refactor AlibabaEventBridgeHeaders into a sealed class permitted
for
     AlibabaEventBridgeProperties, centralizing common Camel header
names
     and avoiding duplicate field declarations.
   - Update AlibabaEventBridgeHeaders constructor to package-private
     visibility to allow the permitted subclass to extend it.

2. Utils Alignment:
   - Update AlibabaEventBridgeUtils to use AlibabaEventBridgeConstants
     for resolving CloudEvent fields and structuring response maps.

3. Test Fixes:
   - Update PutEventsTest to use AlibabaEventBridgeConstants for Map
body
     keys, ensuring event data is properly extracted and serialized.
   - Fix Map assertion keys against response metadata constants.
   - Verify all unit tests pass with Mockito and Camel Test framework.

@atiaomar1978-hub atiaomar1978-hub left a comment

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.

Review summary

AI-generated review on behalf of atiaomar1978-hub (Bugbot + manual review)

Focused refactor — centralizing map-body and response keys in AlibabaEventBridgeConstants and deduplicating header/property definitions via the sealed AlibabaEventBridgeHeadersAlibabaEventBridgeProperties hierarchy is the right direction for maintainability.

What looks good

  • Response map keys unchanged at runtime (requestId, failedEntryCount, etc.) — only centralized behind constants.
  • PutEventsTest updated to use the new map-body keys consistently.
  • Header/property Camel-prefixed names preserved — no exchange-header breaking change.
  • Aligning map keys with URI parameter names (eventSource, eventType, …) is clearer than the previous CloudEvents-short names (source, type).

Issues to address

  1. Map body key rename — keys changed from source/type/subject/data to eventSource/eventType/eventSubject/eventData. Fine while Preview/unreleased; document the Map body schema in alibaba-eventbridge-component.adoc.

  2. @Metadata javaType accuracyEVENT_RESPONSE_FAILED_ENTRY_COUNT and EVENT_RESPONSE_ENTRY_LIST annotated as String but producer puts Integer and List<Map<…>>.

  3. @Metadata on map-body constants — these are Map payload fields, not exchange headers. Consider plain constants like OSS OSSConstants.

  4. Test gaps (minor) — consider eventSubject in map body, list-of-maps body, response entryList structure.

Verdict

Comment — good refactor, merge-ready after doc + metadata polish. No functional bugs found by Bugbot.


Review performed with code inspection and Bugbot.

String data = jsonDataValue(mapBody.get("data"));
String eventBusName
= stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_BUS_NAME), configuration.getEventBusName());
String source = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SOURCE), configuration.getEventSource());

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.

Map body keys renamed — document this

Previous Map keys were CloudEvents-short (source, type, subject, data); now aligned with URI params (eventSource, eventType, eventSubject, eventData). Fine for unreleased Preview, but please document the Map body schema in the component guide.

@Metadata(label = "producer", description = "Event resource owner account identifier", javaType = "String")
public static final String EVENT_RESPONSE_RESOURCE_OWNER_ACCOUNT_IDENTIFIER = "resourceOwnerAccountId";

@Metadata(label = "producer", description = "Event failed entry count", javaType = "String")

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.

@Metadata javaType mismatch

EVENT_RESPONSE_FAILED_ENTRY_COUNT stores an Integer from getFailedEntryCount(). EVENT_RESPONSE_ENTRY_LIST is a List<Map<String,Object>>, not a String. Please fix javaType for catalog accuracy.

import org.apache.camel.spi.Metadata;

public final class AlibabaEventBridgeHeaders {
public sealed class AlibabaEventBridgeHeaders permits AlibabaEventBridgeProperties {

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.

Sealed hierarchy — consider consistency

Sealed HeadersProperties deduplicates exchange keys nicely. Other Alibaba modules (OSS, KMS, SMS) use separate final classes. Worth aligning across CAMEL-24373 if a convention is emerging.

event.put("source", testConfiguration.getProperty("eventSource"));
event.put("type", testConfiguration.getProperty("eventType"));
event.put("data", Map.of("key", "value"));
event.put(AlibabaEventBridgeConstants.EVENT_BUS_NAME, testConfiguration.getProperty("eventBusName"));

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.

Tests updated correctly

Map body test now uses AlibabaEventBridgeConstants keys. Minor gap: no coverage for eventSubject override or multi-event list body — non-blocking for this refactor.

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor

Review complete

AI-generated on behalf of atiaomar1978-hub

Verdict: Comment — solid constants refactor, no blocking bugs.

Bugbot flagged metadata javaType mismatches and missing Map body documentation. I also noted the intentional map-key rename (sourceeventSource, etc.) — fine pre-release but needs a doc example.

Test coverage is adequate for the scope (string body + map body paths updated).

Thanks @arunsrajan for keeping response map runtime keys stable while centralizing constants.

document headers and map keys

Address pull request feedback on the Alibaba Cloud EventBridge
component:

1. Metadata Accuracy:
   - Correct `@Metadata` `javaType` on
`EVENT_RESPONSE_FAILED_ENTRY_COUNT` from `String` to `Integer`.
   - Correct `@Metadata` `javaType` on `EVENT_RESPONSE_ENTRY_LIST` from
`String` to `List<Map<String, Object>>`.
   - Add class-level Javadoc to `AlibabaEventBridgeConstants`.

2. Component Documentation:
   - Document message headers evaluated and set by the EventBridge
producer in `alibaba-eventbridge-component.adoc`.
   - Document the input Map body schema and keys (`eventBusName`,
`eventSource`, `eventType`, `eventSubject`, `eventData`).
   - Document response metadata structure returned in the message body
(`requestId`, `resourceOwnerAccountId`, `failedEntryCount`,
`entryList`).
   - Add examples for String/JSON payload, Map payload, and
multiple-event publishing.
map schema, and expand test coverage

Address pull request review feedback for the Alibaba Cloud EventBridge
component:

1. Constants Refactoring:
   - Convert 'AlibabaEventBridgeConstants' to plain constants without
'@metadata' annotations, aligning with 'OSSConstants' since these
represent payload dictionary and response map keys rather than Camel
exchange headers.
   - Add class-level Javadoc.

2. Component Documentation:
   - Document message headers evaluated and set by the EventBridge
producer in 'alibaba-eventbridge-component.adoc'.
   - Document the input Map body schema and keys ('eventBusName',
'eventSource', 'eventType', 'eventSubject', 'eventData').
   - Document response metadata structure in the message body
('requestId', 'resourceOwnerAccountId', 'failedEntryCount',
'entryList').
   - Add examples for String/JSON payload, Map payload, and multi-event
publishing.

3. Test Coverage:
   - Add 'testPutEventsWithListOfMapsAndSubjectAndEntryList' in
'PutEventsTest' to test 'eventSubject' overrides in Map payloads, batch
multi-event publishing ('List<Map<String, Object>>'), and full
assertions on response 'entryList' metadata ('eventId', 'errorCode',
'errorMessage').
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.

4 participants