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').

@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.

Re-review summary

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

All feedback from the prior review has been addressed in commits c8c2de0 and ad9a973. This looks ready to merge.

Prior feedback — resolved

  1. Map body schema documentedalibaba-eventbridge-component.adoc now documents input Map keys (eventBusName, eventSource, eventType, eventSubject, eventData), response body structure, and examples for String/JSON, Map, and multi-event payloads.
  2. @Metadata javaType mismatchAlibabaEventBridgeConstants is now plain dictionary-key constants (aligned with OSSConstants), with no incorrect @Metadata annotations on payload/response map keys.
  3. Test coverage expandedtestPutEventsWithListOfMapsAndSubjectAndEntryList covers eventSubject overrides, List<Map> batch publishing, and full entryList response assertions.

What looks good

  • Clean separation: AlibabaEventBridgeHeaders (exchange headers with @Metadata) vs AlibabaEventBridgeConstants (Map body/response keys).
  • Sealed HeadersProperties hierarchy deduplicates exchange header declarations without changing public constant names.
  • Utils and tests consistently use constants instead of magic strings.
  • Map keys align with endpoint option naming (eventSource vs CloudEvents-short source) — sensible for a Preview component not yet released.

Bugbot

No bugs found on latest diff.

Non-blocking notes

  • Manual header tables in the adoc overlap with include::partial$component-endpoint-headers.adoc[] — fine for now; could dedupe later if generated docs stay in sync.
  • Sealed header hierarchy differs from other Alibaba modules (OSS/KMS use separate final classes) — acceptable for EventBridge; no need to block.

Verdict

Approved — thanks @arunsrajan for the thorough follow-up commits.


Review performed with code inspection and Bugbot. Does not replace specialized tools (CodeRabbit, Sourcery, SonarCloud).

/**
* Constants for Alibaba EventBridge payload and response dictionary keys.
*/
public final class AlibabaEventBridgeConstants {

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.

Resolved — plain constants, no incorrect @metadata

Good follow-up: payload and response dictionary keys are now plain String constants with class-level Javadoc, matching OSSConstants. This removes the prior javaType mismatches on failedEntryCount and entryList.


|=======================================================================

=== Event payload Map keys evaluated by the producer

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.

Resolved — Map body schema documented

Input Map keys, response metadata structure, and String/JSON + Map + multi-event examples are all documented. Prior concern about the sourceeventSource rename is mitigated since this is a Preview 4.23 component not yet released.

}

@Test
void testPutEventsWithListOfMapsAndSubjectAndEntryList() throws Exception {

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.

Resolved — expanded test coverage

testPutEventsWithListOfMapsAndSubjectAndEntryList covers eventSubject overrides, batch List<Map> publishing, and full entryList response metadata assertions. Good AssertJ usage throughout.

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor

Re-review complete

AI-generated on behalf of atiaomar1978-hub

Verdict: Approved

All prior review feedback has been addressed:

  • Constants simplified (plain dictionary keys, no wrong @Metadata)
  • Component docs cover Map body keys, response structure, and examples
  • New test for multi-event List<Map> + eventSubject + entryList assertions

Bugbot found no issues on the latest diff. LGTM — thanks @arunsrajan!

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