Ayush0612005 opened a new pull request, #30514:
URL: https://github.com/apache/camel/pull/30514

   # Description
   
   [CAMEL-27194](https://issues.apache.org/jira/browse/CAMEL-27194): the 
`insert` part of the issue (a `byte[]` body failing with `ClassCastException`) 
was fixed in CAMEL-27259 (#30454). This PR covers the other part the issue 
describes, in `createDoUpdate()`.
   
   Without the `CamelMongoDbCriteria` header, `update` converts the body to a 
`List` of the criteria and the update. A `String` JSON array converts 
(`MongoDbBasicConverters.fromStringToList`), but the same text as a `byte[]` 
body, which Kafka consumers, files and Kamelet sources produce, did not, and 
the update failed with `MongoDB operation = insert, failed because body is not 
a List of Document objects with size = 2`.
   
   - A `byte[]` body is now read as text first (`getBody(String.class)`, with 
the exchange charset), so it converts as the same `String` does. Other body 
types are converted as before, and a body that does not convert still fails 
with `InvalidPayloadException` ("Invalid payload for update").
   - The size error now names the `update` operation instead of `insert`.
   
   An update with the criteria in the header and a `byte[]` update body already 
worked (the `byte[]` to `Document` converter), and is covered by a test now.
   
   # Tests
   
   New `MongoDbProducerUpdateBodyTest`, with a mocked `MongoClient` like 
`MongoDbProducerInsertBodyTest`:
   - a `byte[]` JSON array of the criteria and the update is applied with 
`updateOne`;
   - a `byte[]` update with the criteria header;
   - a body of the wrong size fails with a message that names the `update` 
operation.
   
   Without the change, the first and third tests fail with the `insert` 
message. `MongoDbProducer*Test` and the converter tests pass (14 of 14). The 
MongoDB container ITs were not run locally (no Docker).
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I built camel-mongodb with `install` (including code generation, 
`formatter:format` and `impsort:sort`); no generated file changed.
   
   _Claude Code on behalf of Ayush0612005_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to