|
19 | 19 | class InferenceTest { |
20 | 20 |
|
21 | 21 | private InferenceResponse loadFromResource(String resourcePath) throws IOException { |
22 | | - MindeeClientV2 dummyClient = new MindeeClientV2("dummy"); |
23 | | - return dummyClient.loadInference(new LocalResponse(InferenceTest.class.getClassLoader().getResourceAsStream(resourcePath))); |
| 22 | + LocalResponse localResponse = new LocalResponse(InferenceTest.class.getClassLoader().getResourceAsStream(resourcePath)); |
| 23 | + return localResponse.deserializeResponse(InferenceResponse.class); |
24 | 24 | } |
25 | 25 |
|
26 | 26 | private String readFileAsString(String path) |
@@ -90,41 +90,55 @@ void asyncPredict_whenEmpty_mustHaveValidProperties() throws IOException { |
90 | 90 | class CompletePrediction { |
91 | 91 |
|
92 | 92 | @Test |
93 | | - @DisplayName("all properties must be valid") |
94 | | - void asyncPredict_whenComplete_mustHaveValidProperties() throws IOException { |
| 93 | + @DisplayName("every exposed property must be valid and consistent") |
| 94 | + void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException { |
95 | 95 | InferenceResponse response = loadFromResource("v2/products/financial_document/complete.json"); |
96 | | - InferenceFields fields = response.getInference().getResult().getFields(); |
| 96 | + Inference inf = response.getInference(); |
| 97 | + assertNotNull(inf, "Inference must not be null"); |
| 98 | + assertEquals("12345678-1234-1234-1234-123456789abc", inf.getId(), "Inference ID mismatch"); |
97 | 99 |
|
98 | | - assertEquals(21, fields.size(), "Expected 21 fields"); |
| 100 | + InferenceResultModel model = inf.getModel(); |
| 101 | + assertNotNull(model, "Model must not be null"); |
| 102 | + assertEquals("12345678-1234-1234-1234-123456789abc", model.getId(), "Model ID mismatch"); |
| 103 | + |
| 104 | + InferenceResultFile file = inf.getFile(); |
| 105 | + assertNotNull(file, "File must not be null"); |
| 106 | + assertEquals("complete.jpg", file.getName(), "File name mismatch"); |
| 107 | + assertNull(file.getAlias(), "File alias must be null for this payload"); |
| 108 | + |
| 109 | + InferenceFields fields = inf.getResult().getFields(); |
| 110 | + assertEquals(21, fields.size(), "Expected 21 fields in the payload"); |
| 111 | + |
| 112 | + SimpleField date = fields.get("date").getSimpleField(); |
| 113 | + assertEquals("2019-11-02", date.getValue(), "'date' value mismatch"); |
99 | 114 |
|
100 | 115 | DynamicField taxes = fields.get("taxes"); |
101 | 116 | assertNotNull(taxes, "'taxes' field must exist"); |
102 | 117 | ListField taxesList = taxes.getListField(); |
103 | 118 | assertNotNull(taxesList, "'taxes' must be a ListField"); |
104 | 119 | assertEquals(1, taxesList.getItems().size(), "'taxes' list must contain exactly one item"); |
105 | | - assertNotNull(taxes.toString(), "'taxes' toString() must not be null"); |
106 | | - |
107 | 120 | ObjectField taxItemObj = taxesList.getItems().get(0).getObjectField(); |
108 | 121 | assertNotNull(taxItemObj, "First item of 'taxes' must be an ObjectField"); |
109 | 122 | assertEquals(3, taxItemObj.getFields().size(), "Tax ObjectField must contain 3 sub-fields"); |
110 | | - assertEquals( |
111 | | - 31.5, |
112 | | - taxItemObj.getFields().get("base").getSimpleField().getValue(), |
113 | | - "'taxes.base' value mismatch" |
114 | | - ); |
| 123 | + SimpleField baseTax = taxItemObj.getFields().get("base").getSimpleField(); |
| 124 | + assertEquals(31.5, baseTax.getValue(), "'taxes.base' value mismatch"); |
| 125 | + assertNotNull(taxes.toString(), "'taxes'.toString() must not be null"); |
115 | 126 |
|
116 | 127 | DynamicField supplierAddress = fields.get("supplier_address"); |
117 | 128 | assertNotNull(supplierAddress, "'supplier_address' field must exist"); |
118 | | - |
119 | 129 | ObjectField supplierObj = supplierAddress.getObjectField(); |
120 | 130 | assertNotNull(supplierObj, "'supplier_address' must be an ObjectField"); |
121 | | - |
122 | 131 | DynamicField country = supplierObj.getFields().get("country"); |
123 | 132 | assertNotNull(country, "'supplier_address.country' must exist"); |
124 | | - assertEquals("USA", country.getSimpleField().getValue()); |
125 | | - assertEquals("USA", country.toString()); |
126 | | - |
| 133 | + assertEquals("USA", country.getSimpleField().getValue(), "Country mismatch"); |
| 134 | + assertEquals("USA", country.toString(), "'country'.toString() mismatch"); |
127 | 135 | assertNotNull(supplierAddress.toString(), "'supplier_address'.toString() must not be null"); |
| 136 | + |
| 137 | + ObjectField customerAddr = fields.get("customer_address").getObjectField(); |
| 138 | + SimpleField city = customerAddr.getFields().get("city").getSimpleField(); |
| 139 | + assertEquals("New York", city.getValue(), "City mismatch"); |
| 140 | + |
| 141 | + assertNull(inf.getResult().getOptions(), "Options must be null"); |
128 | 142 | } |
129 | 143 | } |
130 | 144 |
|
@@ -206,45 +220,6 @@ void rawTexts_mustBeAccessible() throws IOException { |
206 | 220 | } |
207 | 221 | } |
208 | 222 |
|
209 | | - @Nested |
210 | | - @DisplayName("complete.json – full inference response") |
211 | | - class FullInference { |
212 | | - @Test |
213 | | - @DisplayName("complete financial-document JSON must round-trip correctly") |
214 | | - void fullInferenceResponse_mustExposeEveryProperty() throws IOException { |
215 | | - InferenceResponse resp = loadFromResource("v2/products/financial_document/complete.json"); |
216 | | - |
217 | | - Inference inf = resp.getInference(); |
218 | | - assertNotNull(inf); |
219 | | - assertEquals("12345678-1234-1234-1234-123456789abc", inf.getId()); |
220 | | - |
221 | | - InferenceFields f = inf.getResult().getFields(); |
222 | | - |
223 | | - SimpleField date = f.get("date").getSimpleField(); |
224 | | - assertEquals("2019-11-02", date.getValue()); |
225 | | - |
226 | | - ListField taxes = f.get("taxes").getListField(); |
227 | | - ObjectField firstTax = taxes.getItems().get(0).getObjectField(); |
228 | | - SimpleField baseTax = firstTax.getFields().get("base").getSimpleField(); |
229 | | - assertEquals(31.5, baseTax.getValue()); |
230 | | - |
231 | | - ObjectField customerAddr = f.get("customer_address").getObjectField(); |
232 | | - SimpleField city = customerAddr.getFields().get("city").getSimpleField(); |
233 | | - assertEquals("New York", city.getValue()); |
234 | | - |
235 | | - InferenceResultModel model = inf.getModel(); |
236 | | - assertNotNull(model); |
237 | | - assertEquals("12345678-1234-1234-1234-123456789abc", model.getId()); |
238 | | - |
239 | | - InferenceResultFile file = inf.getFile(); |
240 | | - assertNotNull(file); |
241 | | - assertEquals("complete.jpg", file.getName()); |
242 | | - assertNull(file.getAlias()); |
243 | | - |
244 | | - assertNull(inf.getResult().getOptions()); |
245 | | - } |
246 | | - } |
247 | | - |
248 | 223 | @Nested |
249 | 224 | @DisplayName("rst display") |
250 | 225 | class RstDisplay { |
|
0 commit comments