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..4ddd14e96 --- /dev/null +++ b/src/test/java/com/mindee/input/LocalResponseV2Test.java @@ -0,0 +1,65 @@ +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); + Assertions.assertNotNull(response); + Assertions.assertNotNull(response.getInference()); + } + + @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