jamesnetherton commented on code in PR #8197:
URL: https://github.com/apache/camel-quarkus/pull/8197#discussion_r2717549981


##########
extensions/docling/deployment/src/main/java/org/apache/camel/quarkus/component/docling/deployment/DoclingProcessor.java:
##########
@@ -73,5 +74,7 @@ void registerForReflection(
         
reflectiveClass.produce(ReflectiveClassBuildItem.builder(doclingCoreBuilderClasses.toArray(new
 String[0]))
                 .methods(true)
                 .build());
+
+        
reflectiveClass.produce(ReflectiveClassBuildItem.builder(DocumentMetadata.class).constructors().methods(true).build());

Review Comment:
   Just to clarify - are we registering `DocumentMetadata` because something in 
Camel or elsewhere does reflective operations on it?
   
   Or are we only adding it because it's used with `ObjectMapper` in the tests?



##########
integration-tests/docling/src/test/java/org/apache/camel/quarkus/component/docling/it/DoclingTest.java:
##########
@@ -127,12 +133,62 @@ public void extractText() {
                 .post("/docling/extract/text")
                 .then()
                 .statusCode(200)
-                .body(not(emptyString()));
+                .body(containsString(testContent));
     }
 
     @Test
-    public void extractMetadata() {
-        String testContent = "# Test Document\nSome content for metadata 
extraction.";
+    void extractMetadataFromPdf() {
+        RestAssured.given()
+                .when()
+                .post("/docling/metadata/extract/pdf")
+                .then()
+                .statusCode(200)
+                .body(new BaseMatcher<String>() {
+
+                    private DocumentMetadata documentMetadata;
+
+                    @Override
+                    public boolean matches(Object actual) {
+                        ObjectMapper mapper = new ObjectMapper();
+                        try {
+                            documentMetadata = mapper.readValue((String) 
actual, DocumentMetadata.class);
+                            return 
documentMetadata.getFileName().startsWith("docling-test")
+                                    && 
documentMetadata.getFilePath().contains("docling-test");
+                            // TODO: improve test by checking other metadatas 
when https://issues.apache.org/jira/browse/CAMEL-22888 is fixed
+                        } catch (JsonProcessingException e) {
+                            e.printStackTrace();
+                            return false;
+                        }
+                    }
+
+                    @Override
+                    public void describeTo(Description description) {
+                        if (documentMetadata != null) {
+                            
description.appendText(documentMetadata.toString());
+                        } else {
+                            description.appendText("Wasn't able to parse the 
answer");
+                        }
+                    }
+                });

Review Comment:
   If you just want to do assertions on a JSON response. There is a much easier 
way:
   
   https://github.com/rest-assured/rest-assured/wiki/usage#example-1---json
   
   



##########
integration-tests/docling/src/test/java/org/apache/camel/quarkus/component/docling/it/DoclingTest.java:
##########
@@ -141,7 +197,33 @@ public void extractMetadata() {
                 .post("/docling/metadata/extract")
                 .then()
                 .statusCode(200)
-                .body(not(emptyString()));
+                .body(new BaseMatcher<String>() {
+
+                    private DocumentMetadata documentMetadata;
+
+                    @Override
+                    public boolean matches(Object actual) {
+                        ObjectMapper mapper = new ObjectMapper();
+                        try {
+                            documentMetadata = mapper.readValue((String) 
actual, DocumentMetadata.class);
+                            return 
documentMetadata.getFileName().startsWith("docling-test")
+                                    && 
documentMetadata.getFilePath().contains("docling-test");

Review Comment:
   See previous comment about JSON response matching.



##########
integration-tests/docling/src/main/java/org/apache/camel/quarkus/component/docling/it/DoclingResource.java:
##########
@@ -206,13 +210,38 @@ public Response extractMetadata(String documentContent) 
throws IOException {
         java.nio.file.Path tempFile = Files.createTempFile("docling-test", 
".md");
         Files.writeString(tempFile, documentContent);
         try {
-            String result = 
producerTemplate.requestBody("direct:extractMetadata", tempFile.toString(), 
String.class);
-            return Response.ok(result).build();
+            DocumentMetadata result = 
producerTemplate.requestBody("direct:extractMetadata", tempFile.toString(),
+                    DocumentMetadata.class);
+            ObjectWriter ow = new 
ObjectMapper().writer().withDefaultPrettyPrinter();
+            String json = ow.writeValueAsString(result);
+            return Response.ok(json).build();

Review Comment:
   I you use `quarkus-resteasy-jackson` or `quarkus-resteasy-jsonb`, you can 
set the `Response` entity to `result` and it'll get serialized to JSON 
automatically. Thus no need for `ObjectMapper`.
   
   Same for `extractMetadataFromPdf `.



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