55import com .mindee .http .MindeeApiV2 ;
66import com .mindee .input .LocalInputSource ;
77import com .mindee .input .LocalResponse ;
8- import com .mindee .parsing .v2 .CommonResponse ;
98import com .mindee .parsing .v2 .InferenceResponse ;
109import com .mindee .parsing .v2 .JobResponse ;
1110import java .io .File ;
1211import java .io .IOException ;
12+ import org .apache .commons .io .FileUtils ;
1313import org .junit .jupiter .api .DisplayName ;
1414import org .junit .jupiter .api .Nested ;
1515import org .junit .jupiter .api .Test ;
1616import org .mockito .Mockito ;
17+
1718import static org .junit .jupiter .api .Assertions .*;
1819import static org .mockito .ArgumentMatchers .*;
1920import static org .mockito .Mockito .*;
@@ -53,11 +54,11 @@ void enqueue_post_async() throws IOException {
5354 }
5455
5556 @ Nested
56- @ DisplayName ("parseQueued ()" )
57- class ParseQueued {
57+ @ DisplayName ("getJob ()" )
58+ class GetJob {
5859 @ Test
5960 @ DisplayName ("hits the HTTP endpoint once and returns a non-null response" )
60- void document_getQueued_async () throws JsonProcessingException {
61+ void document_getJob_async () throws JsonProcessingException {
6162 MindeeApiV2 predictable = Mockito .mock (MindeeApiV2 .class );
6263 String json = "{\" job\" : {\" id\" : \" dummy-id\" , \" status\" : \" Processing\" }}" ;
6364 ObjectMapper mapper = new ObjectMapper ();
@@ -70,8 +71,44 @@ void document_getQueued_async() throws JsonProcessingException {
7071
7172 MindeeClientV2 mindeeClient = makeClientWithMockedApi (predictable );
7273
73- CommonResponse response = mindeeClient .getJob ("dummy-id" );
74- assertNotNull (response , "parseQueued() must return a response" );
74+ JobResponse response = mindeeClient .getJob ("dummy-id" );
75+ assertNotNull (response , "getJob() must return a response" );
76+ verify (predictable , atMostOnce ()).reqGetJob (anyString ());
77+ }
78+ }
79+
80+
81+ @ Nested
82+ @ DisplayName ("getInference()" )
83+ class GetInference {
84+ @ Test
85+ @ DisplayName ("hits the HTTP endpoint once and returns a non-null response" )
86+ void document_getInference_async () throws IOException {
87+ MindeeApiV2 predictable = Mockito .mock (MindeeApiV2 .class );
88+
89+ String json = FileUtils .readFileToString (new File ("src/test/resources/v2/products/financial_document/complete.json" ));
90+
91+ ObjectMapper mapper = new ObjectMapper ();
92+ mapper .findAndRegisterModules ();
93+
94+ InferenceResponse processing = mapper .readValue (json , InferenceResponse .class );
95+
96+ when (predictable .reqGetInference (anyString ()))
97+ .thenReturn (processing );
98+
99+ MindeeClientV2 mindeeClient = makeClientWithMockedApi (predictable );
100+
101+ InferenceResponse response = mindeeClient .getInference ("12345678-1234-1234-1234-123456789abc" );
102+ assertNotNull (response , "getInference() must return a response" );
103+ assertEquals (
104+ 21 , response .getInference ().getResult ().getFields ().size (),
105+ "Result must have one field"
106+ );
107+ assertEquals (
108+ "John Smith" ,
109+ response .getInference ().getResult ().getFields ().get ("supplier_name" ).getSimpleField ().getValue (),
110+ "Result must deserialize fields properly."
111+ );
75112 verify (predictable , atMostOnce ()).reqGetInference (anyString ());
76113 }
77114 }
0 commit comments