From 42004ad5deb4010d30b842521b43ff1fe75a9f4d Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 2 Dec 2025 10:59:16 +0100 Subject: [PATCH 1/3] :sparkles: add text context return option --- .../parsing/v2/InferenceActiveOptions.java | 8 +++ ...onseTest.java => LocalResponseV1Test.java} | 4 +- .../com/mindee/input/LocalResponseV2Test.java | 63 +++++++++++++++++++ .../com/mindee/parsing/v2/InferenceTest.java | 19 ++++++ src/test/resources | 2 +- 5 files changed, 92 insertions(+), 4 deletions(-) rename src/test/java/com/mindee/input/{LocalResponseTest.java => LocalResponseV1Test.java} (94%) create mode 100644 src/test/java/com/mindee/input/LocalResponseV2Test.java diff --git a/src/main/java/com/mindee/parsing/v2/InferenceActiveOptions.java b/src/main/java/com/mindee/parsing/v2/InferenceActiveOptions.java index f43effd8f..a49fbaa42 100644 --- a/src/main/java/com/mindee/parsing/v2/InferenceActiveOptions.java +++ b/src/main/java/com/mindee/parsing/v2/InferenceActiveOptions.java @@ -27,6 +27,9 @@ public final class InferenceActiveOptions { @JsonProperty("confidence") private boolean confidence; + @JsonProperty("text_context") + private boolean textContext; + /** * Data schema options provided for the inference. */ @@ -62,6 +65,11 @@ public boolean getConfidence() { return confidence; } + /** + * Whether the text context feature was activated. + */ + public boolean getTextContext() { return textContext; } + @Override public String toString() { StringJoiner joiner = new StringJoiner("\n"); diff --git a/src/test/java/com/mindee/input/LocalResponseTest.java b/src/test/java/com/mindee/input/LocalResponseV1Test.java similarity index 94% rename from src/test/java/com/mindee/input/LocalResponseTest.java rename to src/test/java/com/mindee/input/LocalResponseV1Test.java index 55557c1fa..32bdf3537 100644 --- a/src/test/java/com/mindee/input/LocalResponseTest.java +++ b/src/test/java/com/mindee/input/LocalResponseV1Test.java @@ -6,13 +6,11 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import static com.mindee.TestingUtilities.getV1ResourcePath; -import static com.mindee.TestingUtilities.getV1ResourcePathString; -public class LocalResponseTest { +public class LocalResponseV1Test { /** * Fake secret key. */ diff --git a/src/test/java/com/mindee/input/LocalResponseV2Test.java b/src/test/java/com/mindee/input/LocalResponseV2Test.java new file mode 100644 index 000000000..d55009fd8 --- /dev/null +++ b/src/test/java/com/mindee/input/LocalResponseV2Test.java @@ -0,0 +1,63 @@ +package com.mindee.input; + +import com.mindee.parsing.v2.InferenceResponse; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import static com.mindee.TestingUtilities.getV2ResourcePath; + + +public class LocalResponseV2Test { + /** + * Fake secret key. + */ + String secretKey = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; + + /** + * Real signature using fake secret key. + */ + String signature = "b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be"; + + /** + * File which the signature applies to. + */ + Path filePath = getV2ResourcePath("inference/standard_field_types.json"); + + protected void assertLocalResponse(LocalResponse localResponse) { + Assertions.assertNotNull(localResponse.getFile()); + Assertions.assertFalse(localResponse.isValidHmacSignature( + this.secretKey, "invalid signature is invalid") + ); + Assertions.assertEquals(this.signature, localResponse.getHmacSignature(this.secretKey)); + Assertions.assertTrue(localResponse.isValidHmacSignature(this.secretKey, this.signature)); + InferenceResponse response = localResponse.deserializeResponse(InferenceResponse.class); + } + + @Test + void loadDocument_withFile_mustReturnValidLocalResponse() throws IOException { + LocalResponse localResponse = new LocalResponse(new File(this.filePath.toString())); + assertLocalResponse(localResponse); + } + + @Test + void loadDocument_withString_mustReturnValidLocalResponse() { + LocalResponse localResponse = new LocalResponse("{'some': 'json', 'with': 'data'}"); + Assertions.assertNotNull(localResponse.getFile()); + Assertions.assertFalse(localResponse.isValidHmacSignature( + this.secretKey, "invalid signature is invalid") + ); + } + + @Test + void loadDocument_withInputStream_mustReturnValidLocalResponse() throws IOException { + LocalResponse localResponse = new LocalResponse( + Files.newInputStream(this.filePath) + ); + assertLocalResponse(localResponse); + } +} diff --git a/src/test/java/com/mindee/parsing/v2/InferenceTest.java b/src/test/java/com/mindee/parsing/v2/InferenceTest.java index 6207308de..d51f11f20 100644 --- a/src/test/java/com/mindee/parsing/v2/InferenceTest.java +++ b/src/test/java/com/mindee/parsing/v2/InferenceTest.java @@ -148,6 +148,11 @@ void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException { InferenceActiveOptions activeOptions = inference.getActiveOptions(); assertNotNull(activeOptions); + assertFalse(activeOptions.getConfidence()); + assertFalse(activeOptions.getRag()); + assertFalse(activeOptions.getRawText()); + assertFalse(activeOptions.getTextContext()); + assertFalse(activeOptions.getPolygon()); } } @@ -466,6 +471,7 @@ void rawTexts_mustBeAccessible() throws IOException { assertTrue(activeOptions.getRawText()); assertFalse(activeOptions.getPolygon()); assertFalse(activeOptions.getConfidence()); + assertFalse(activeOptions.getTextContext()); assertFalse(activeOptions.getDataSchema().getOverride()); assertNull(inference.getResult().getRag()); @@ -525,4 +531,17 @@ void rstDisplay_mustBeAccessible() throws IOException { assertEquals(rstRef, resp.getInference().toString()); } } + + @Nested + @DisplayName("Text Context Return") + class TextContextTest { + @Test + @DisplayName("should be present and true when enabled") + void textContext_mustBePresentAndTrue() throws IOException { + InferenceResponse resp = loadInference("inference/text_context_enabled.json"); + Inference inf = resp.getInference(); + assertNotNull(inf); + assertTrue(inf.getActiveOptions().getTextContext()); + } + } } diff --git a/src/test/resources b/src/test/resources index 932b387e4..f86f3eaf5 160000 --- a/src/test/resources +++ b/src/test/resources @@ -1 +1 @@ -Subproject commit 932b387e48d909202d7b69ccf9230531dee3f036 +Subproject commit f86f3eaf540f0babeb3d4f1a458d764856a2170b From d616a3af16ed1d5143f9f5a0f36ad0d8b1c54d1a Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 2 Dec 2025 11:53:42 +0100 Subject: [PATCH 2/3] add test --- src/test/java/com/mindee/input/LocalResponseV2Test.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/mindee/input/LocalResponseV2Test.java b/src/test/java/com/mindee/input/LocalResponseV2Test.java index d55009fd8..8c5374201 100644 --- a/src/test/java/com/mindee/input/LocalResponseV2Test.java +++ b/src/test/java/com/mindee/input/LocalResponseV2Test.java @@ -51,6 +51,9 @@ void loadDocument_withString_mustReturnValidLocalResponse() { Assertions.assertFalse(localResponse.isValidHmacSignature( this.secretKey, "invalid signature is invalid") ); + InferenceResponse response = localResponse.deserializeResponse(InferenceResponse.class); + Assertions.assertNotNull(response); + Assertions.assertNotNull(response.getInference()); } @Test From d5aa980ccf22ffc376dab03c2a07847db6dd7ec1 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 2 Dec 2025 11:56:46 +0100 Subject: [PATCH 3/3] fix broken test --- src/test/java/com/mindee/input/LocalResponseV2Test.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/mindee/input/LocalResponseV2Test.java b/src/test/java/com/mindee/input/LocalResponseV2Test.java index 8c5374201..4ddd14e96 100644 --- a/src/test/java/com/mindee/input/LocalResponseV2Test.java +++ b/src/test/java/com/mindee/input/LocalResponseV2Test.java @@ -36,6 +36,8 @@ protected void assertLocalResponse(LocalResponse localResponse) { Assertions.assertEquals(this.signature, localResponse.getHmacSignature(this.secretKey)); Assertions.assertTrue(localResponse.isValidHmacSignature(this.secretKey, this.signature)); InferenceResponse response = localResponse.deserializeResponse(InferenceResponse.class); + Assertions.assertNotNull(response); + Assertions.assertNotNull(response.getInference()); } @Test @@ -51,9 +53,6 @@ void loadDocument_withString_mustReturnValidLocalResponse() { Assertions.assertFalse(localResponse.isValidHmacSignature( this.secretKey, "invalid signature is invalid") ); - InferenceResponse response = localResponse.deserializeResponse(InferenceResponse.class); - Assertions.assertNotNull(response); - Assertions.assertNotNull(response.getInference()); } @Test