Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/com/mindee/input/LocalResponseV2Test.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/mindee/parsing/v2/InferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
}
}
Loading