Skip to content

Commit 99f0686

Browse files
add missing keys to workflow + add test + fix shell script
1 parent 13351ff commit 99f0686

File tree

5 files changed

+106
-46
lines changed

5 files changed

+106
-46
lines changed

src/main/java/com/mindee/MindeeClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import com.mindee.parsing.common.AsyncPredictResponse;
1414
import com.mindee.parsing.common.Inference;
1515
import com.mindee.parsing.common.PredictResponse;
16+
import com.mindee.parsing.common.WorkflowResponse;
1617
import com.mindee.pdf.PdfBoxApi;
1718
import com.mindee.pdf.PdfOperation;
1819
import com.mindee.pdf.SplitQuery;
1920
import com.mindee.product.custom.CustomV1;
2021
import com.mindee.product.generated.GeneratedV1;
21-
import com.mindee.parsing.common.WorkflowResponse;
2222
import java.io.IOException;
2323
import java.net.URL;
2424

src/main/java/com/mindee/parsing/common/Execution.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,62 @@
1919
@AllArgsConstructor
2020
@NoArgsConstructor
2121
public class Execution<DocT extends Inference> implements ApiObject {
22+
/**
23+
* Identifier for the batch to which the execution belongs.
24+
*/
25+
@JsonProperty("batch_name")
26+
private String batchName;
27+
28+
/**
29+
* The time at which the execution started.
30+
*/
31+
@JsonProperty("created_at")
32+
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
33+
private LocalDateTime createdAt;
34+
35+
/**
36+
* File representation within a workflow execution.
37+
*/
38+
@JsonProperty("file")
39+
private ExecutionFile file;
40+
2241
/**
2342
* Identifier for the execution.
2443
*/
2544
@JsonProperty("id")
2645
private String id;
2746

2847
/**
29-
* Identifier for the workflow.
48+
* Deserialized inference object.
3049
*/
31-
@JsonProperty("workflow_id")
32-
private String workflowId;
50+
@JsonProperty("inference")
51+
private DocT inference;
3352

3453
/**
35-
* The time at which the execution started.
54+
* Priority of the execution.
3655
*/
37-
@JsonProperty("created_at")
56+
@JsonProperty("priority")
57+
private String priority;
58+
59+
/**
60+
* The time at which the file was tagged as reviewed.
61+
*/
62+
@JsonProperty("reviewed_at")
3863
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
39-
private LocalDateTime createdAt;
64+
private LocalDateTime reviewedAt;
4065

4166
/**
4267
* The time at which the file was uploaded to a workflow.
4368
*/
44-
@JsonProperty("uploaded_at")
69+
@JsonProperty("available_at")
4570
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
4671
private LocalDateTime availableAt;
4772

4873
/**
49-
* The time at which the file was tagged as reviewed.
74+
* Reviewed fields and values.
5075
*/
51-
@JsonProperty("reviewed_at")
52-
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
53-
private LocalDateTime reviewedAt;
76+
@JsonProperty("reviewed_prediction")
77+
private GeneratedV1Document reviewedPrediction;
5478

5579
/**
5680
* Execution Status.
@@ -65,21 +89,15 @@ public class Execution<DocT extends Inference> implements ApiObject {
6589
private String type;
6690

6791
/**
68-
* Information about an error that occurred during the job processing.
69-
*/
70-
@JsonProperty("error")
71-
private Error error;
72-
73-
74-
/**
75-
* Deserialized inference object.
92+
* The time at which the file was uploaded to a workflow.
7693
*/
77-
@JsonProperty("inference")
78-
private DocT inference;
94+
@JsonProperty("uploaded_at")
95+
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
96+
private LocalDateTime uploadedAt;
7997

8098
/**
81-
* Reviewed fields and values.
99+
* Identifier for the workflow.
82100
*/
83-
@JsonProperty("reviewed_prediction")
84-
private GeneratedV1Document reviewedPrediction;
101+
@JsonProperty("workflow_id")
102+
private String workflowId;
85103
}

src/main/java/com/mindee/parsing/common/WorkflowResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class WorkflowResponse<DocT extends Inference> extends ApiResponse {
2020
@JsonProperty("execution")
2121
Execution<DocT> execution;
2222

23-
// Type alias for default type parameter
23+
/**
24+
* Default product is GeneratedV1.
25+
*/
2426
public static class Default extends WorkflowResponse<GeneratedV1> {}
2527
}
Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
11
package com.mindee.workflow;
22

3+
import static org.mockito.Mockito.when;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
36
import com.mindee.MindeeClient;
4-
import com.mindee.http.Endpoint;
57
import com.mindee.http.MindeeApi;
68
import com.mindee.input.LocalInputSource;
7-
import com.mindee.parsing.common.Document;
89
import com.mindee.parsing.common.Execution;
9-
import com.mindee.parsing.common.PredictResponse;
1010
import com.mindee.parsing.common.WorkflowResponse;
1111
import com.mindee.pdf.PdfOperation;
12-
import com.mindee.product.custom.CustomV1;
1312
import com.mindee.product.generated.GeneratedV1;
1413
import java.io.File;
1514
import java.io.IOException;
1615
import org.junit.jupiter.api.Assertions;
1716
import org.junit.jupiter.api.BeforeEach;
1817
import org.junit.jupiter.api.Test;
1918
import org.junit.jupiter.api.extension.ExtendWith;
19+
import org.mockito.Mock;
2020
import org.mockito.Mockito;
21+
import org.mockito.MockitoAnnotations;
2122
import org.mockito.junit.jupiter.MockitoExtension;
2223

2324
@ExtendWith(MockitoExtension.class)
2425
public class WorkflowTest {
2526
MindeeClient client;
27+
@Mock
28+
MindeeClient mockedClient;
2629
MindeeApi mindeeApi;
2730
PdfOperation pdfOperation;
2831

32+
private ObjectMapper objectMapper;
2933
@BeforeEach
3034
public void setUp() {
3135
mindeeApi = Mockito.mock(MindeeApi.class);
3236
pdfOperation = Mockito.mock(PdfOperation.class);
3337
client = new MindeeClient(pdfOperation, mindeeApi);
38+
39+
MockitoAnnotations.openMocks(this);
40+
objectMapper = new ObjectMapper();
3441
}
3542

3643
@Test
@@ -39,23 +46,62 @@ void givenAWorkflowMockFileShouldReturnAValidWorkflowObject()
3946

4047
File file = new File("src/test/resources/file_types/pdf/blank_1.pdf");
4148

42-
WorkflowResponse predictResponse = new WorkflowResponse();
43-
predictResponse.setExecution(new Execution());
44-
predictResponse.setApiRequest(null);
45-
Mockito.when(
49+
WorkflowResponse workflowResponse = new WorkflowResponse();
50+
workflowResponse.setExecution(new Execution());
51+
workflowResponse.setApiRequest(null);
52+
when(
4653
mindeeApi.executeWorkflowPost(
47-
GeneratedV1.class,
54+
Mockito.any(),
4855
Mockito.any(),
4956
Mockito.any()))
50-
.thenReturn(predictResponse);
57+
.thenReturn(workflowResponse);
5158

52-
WorkflowResponse<GeneratedV1> workflowResponse = client.executeWorkflow(
59+
WorkflowResponse<GeneratedV1> execution = client.executeWorkflow(
5360
"",
5461
new LocalInputSource(file)
5562
);
5663

57-
Assertions.assertNotNull(workflowResponse);
64+
Assertions.assertNotNull(execution);
5865
Mockito.verify(mindeeApi, Mockito.times(1))
59-
.predictPost(Mockito.any(), Mockito.any(), Mockito.any());
66+
.executeWorkflowPost(Mockito.any(), Mockito.any(), Mockito.any());
67+
}
68+
69+
@Test
70+
void sendingADocumentToAnExecutionShouldDeserializeResponseCorrectly() throws IOException {
71+
File jsonFile = new File("src/test/resources/workflows/success.json");
72+
WorkflowResponse.Default mockResponse =
73+
objectMapper.readValue(jsonFile, WorkflowResponse.Default.class);
74+
75+
// Mock the executeWorkflow method
76+
when(mockedClient.executeWorkflow(Mockito.anyString(), Mockito.any(LocalInputSource.class)))
77+
.thenReturn(mockResponse);
78+
79+
// Test execution
80+
String workflowId = "workflow-id";
81+
String filePath = "src/test/resources/file_types/pdf/blank_1.pdf";
82+
LocalInputSource inputSource = new LocalInputSource(filePath);
83+
84+
WorkflowResponse<GeneratedV1> response = mockedClient.executeWorkflow(workflowId, inputSource);
85+
86+
// Assertions
87+
Assertions.assertNotNull(response);
88+
Assertions.assertNotNull(response.getApiRequest());
89+
Assertions.assertNull(response.getExecution().getBatchName());
90+
Assertions.assertNull(response.getExecution().getCreatedAt());
91+
Assertions.assertNull(response.getExecution().getFile().getAlias());
92+
Assertions.assertEquals("default_sample.jpg", response.getExecution().getFile().getName());
93+
Assertions.assertEquals("8c75c035-e083-4e77-ba3b-7c3598bd1d8a", response.getExecution().getId());
94+
Assertions.assertNull(response.getExecution().getInference());
95+
Assertions.assertEquals("medium", response.getExecution().getPriority());
96+
Assertions.assertNull(response.getExecution().getReviewedAt());
97+
Assertions.assertNull(response.getExecution().getReviewedPrediction());
98+
Assertions.assertEquals("processing", response.getExecution().getStatus());
99+
Assertions.assertEquals("manual", response.getExecution().getType());
100+
Assertions.assertEquals("2024-11-13T13:02:31.699190", response.getExecution().getUploadedAt().toString());
101+
Assertions.assertEquals("07ebf237-ff27-4eee-b6a2-425df4a5cca6", response.getExecution().getWorkflowId());
102+
103+
// Verify that executeWorkflow was called with the correct parameters
104+
Mockito.verify(mockedClient).executeWorkflow(workflowId, inputSource);
60105
}
106+
61107
}

tests/test_code_samples.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ OUTPUT_FILE='SimpleMindeeClient.java'
55
ACCOUNT=$1
66
ENDPOINT=$2
77
API_KEY=$3
8-
WORKFLOW_ID=$4
98

109
if [ -z "${ACCOUNT}" ]; then echo "ACCOUNT is required"; exit 1; fi
1110
if [ -z "${ENDPOINT}" ]; then echo "ENDPOINT is required"; exit 1; fi
1211

1312
# We need the dependencies otherwise we get class not found exceptions
1413
mvn dependency:copy-dependencies
1514

16-
for f in $(find docs/code_samples -maxdepth 1 -name "*.txt" | sort -h)
15+
for f in $(find docs/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_execution.txt" | sort -h)
1716
do
1817
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
1918
echo "${f}"
@@ -42,11 +41,6 @@ do
4241
sed -i "s/my-version/1/" $OUTPUT_FILE
4342
fi
4443

45-
if echo "${f}" | grep -q "workflow_execution.txt"
46-
then
47-
sed -i "s/workflow-id/$WORKFLOW_ID/" $OUTPUT_FILE
48-
fi
49-
5044
sed -i "s/my-api-key/$API_KEY/" $OUTPUT_FILE
5145
sed -i "s/\/path\/to\/the\/file.ext/src\/test\/resources\/file_types\/pdf\/blank_1.pdf/" $OUTPUT_FILE
5246

0 commit comments

Comments
 (0)