Skip to content

Commit 1581845

Browse files
committed
let's see if java 25 is happy
1 parent 9e59162 commit 1581845

19 files changed

+369
-521
lines changed

pom.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@
290290
</dependency>
291291
<dependency>
292292
<artifactId>jackson-databind</artifactId>
293-
<groupId>com.fasterxml.jackson.core</groupId>
294-
<version>${com.fasterxml.jackson.version}</version>
293+
<groupId>tools.jackson.core</groupId>
294+
<version>${tools.jackson.core.databind.version}</version>
295295
</dependency>
296296
<dependency>
297297
<artifactId>jackson-datatype-jsr310</artifactId>
@@ -366,7 +366,6 @@
366366
<artifactId>junit-pioneer</artifactId>
367367
<groupId>org.junit-pioneer</groupId>
368368
<scope>test</scope>
369-
<!-- version 2.0 is not compatible with java 8 -->
370369
<version>${org.junit.pioneer.version}</version>
371370
</dependency>
372371
<dependency>
@@ -418,8 +417,8 @@
418417
<!-- MINDEE VERSION GOES HERE -->
419418
<revision>5.0.0-alpha1</revision>
420419

421-
<com.fasterxml.jackson.version>2.15.4</com.fasterxml.jackson.version>
422-
<com.fasterxml.jackson.datatype.version>2.15.4</com.fasterxml.jackson.datatype.version>
420+
<tools.jackson.core.databind.version>3.1.1</tools.jackson.core.databind.version>
421+
<com.fasterxml.jackson.datatype.version>2.21.2</com.fasterxml.jackson.datatype.version>
423422
<com.squareup.okhttp3.version>4.12.0</com.squareup.okhttp3.version>
424423
<info.picocli.version>4.7.6</info.picocli.version>
425424
<maven.compiler.source>11</maven.compiler.source>
@@ -441,7 +440,7 @@
441440
<org.apache.pdfbox.version>3.0.5</org.apache.pdfbox.version>
442441
<org.junit.jupiter.version>5.8.2</org.junit.jupiter.version>
443442
<org.junit.pioneer.version>1.9.1</org.junit.pioneer.version>
444-
<org.junit.platform.version>1.8.2</org.junit.platform.version>
443+
<org.junit.platform.version>1.9.2</org.junit.platform.version>
445444
<org.hamcrest.version>2.2</org.hamcrest.version>
446445
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
447446
<org.mockito.inline.version>4.11.0</org.mockito.inline.version>

src/main/java/com/mindee/v1/http/MindeeApiV1.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public abstract <DocT extends Inference> PredictResponse<DocT> predictPost(
3939
RequestParameters requestParameters
4040
) throws IOException;
4141

42+
/**
43+
* Execute a workflow.
44+
*/
4245
public abstract <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
4346
Class<DocT> documentClass,
4447
String workflowId,

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.mindee.v2.parsing.ErrorResponse;
1111
import com.mindee.v2.parsing.JobResponse;
1212
import com.mindee.v2.product.extraction.ExtractionResponse;
13-
import com.mindee.v2.product.extraction.params.ExtractionParameters;
1413
import java.io.IOException;
1514

1615
/**
@@ -34,26 +33,6 @@ public MindeeClient(MindeeApiV2 mindeeApi) {
3433
this.mindeeApi = mindeeApi;
3534
}
3635

37-
/**
38-
* @deprecated use `enqueue` instead.
39-
*/
40-
public JobResponse enqueueInference(
41-
LocalInputSource inputSource,
42-
ExtractionParameters params
43-
) throws IOException {
44-
return enqueue(inputSource, params);
45-
}
46-
47-
/**
48-
* @deprecated use `enqueue` instead.
49-
*/
50-
public JobResponse enqueueInference(
51-
URLInputSource inputSource,
52-
ExtractionParameters params
53-
) throws IOException {
54-
return enqueue(inputSource, params);
55-
}
56-
5736
/**
5837
* Enqueue a document in the asynchronous queue.
5938
*
@@ -88,13 +67,6 @@ public JobResponse getJob(String jobId) {
8867
return mindeeApi.reqGetJob(jobId);
8968
}
9069

91-
/**
92-
* @deprecated use `getResult` instead.
93-
*/
94-
public ExtractionResponse getInference(String inferenceId) {
95-
return getResult(ExtractionResponse.class, inferenceId);
96-
}
97-
9870
/**
9971
* Get the result of an inference that was previously enqueued.
10072
* The inference will only be available after it has finished processing.
@@ -109,26 +81,6 @@ public <TResponse extends CommonResponse> TResponse getResult(
10981
return mindeeApi.reqGetResult(responseClass, inferenceId);
11082
}
11183

112-
/**
113-
* @deprecated use `enqueueAndGetResult` instead.
114-
*/
115-
public ExtractionResponse enqueueAndGetInference(
116-
LocalInputSource inputSource,
117-
ExtractionParameters options
118-
) throws IOException, InterruptedException {
119-
return enqueueAndGetResult(ExtractionResponse.class, inputSource, options);
120-
}
121-
122-
/**
123-
* @deprecated use `enqueueAndGetResult` instead.
124-
*/
125-
public ExtractionResponse enqueueAndGetInference(
126-
URLInputSource inputSource,
127-
ExtractionParameters options
128-
) throws IOException, InterruptedException {
129-
return enqueueAndGetResult(ExtractionResponse.class, inputSource, options);
130-
}
131-
13284
/**
13385
* Send a local file to an async queue, poll, and parse when complete.
13486
*

src/test/java/com/mindee/TestingUtilities.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ public static String getV1ResourcePathString(String filePath) {
2525
return getV1ResourcePath(filePath).toString();
2626
}
2727

28-
public static String readFileAsString(Path path) throws IOException {
29-
byte[] encoded = Files.readAllBytes(path);
30-
return new String(encoded);
31-
}
32-
3328
public static void assertStringEqualsFile(String expected, String filePath) throws IOException {
3429
String[] actualLines = expected.split(System.lineSeparator());
3530
List<String> expectedLines = Files.readAllLines(Paths.get(filePath));

src/test/java/com/mindee/input/URLInputSourceTest.java

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mindee.input;
22

33
import static org.junit.jupiter.api.Assertions.*;
4-
import static org.mockito.Mockito.*;
54

65
import java.io.File;
76
import java.io.IOException;
@@ -11,6 +10,7 @@
1110
import java.nio.file.Paths;
1211
import lombok.Setter;
1312
import org.junit.jupiter.api.*;
13+
import org.junit.jupiter.api.Test;
1414

1515
public class URLInputSourceTest {
1616

@@ -31,7 +31,7 @@ public void tearDown() {
3131
void fetchFile_shouldSaveFileLocally() throws IOException {
3232
urlInputSource.fetchFile();
3333

34-
File savedFile = new File(urlInputSource.getLocalFilename());
34+
var savedFile = new File(urlInputSource.getLocalFilename());
3535
assertTrue(savedFile.exists(), "The file should be saved locally");
3636

3737
Files.deleteIfExists(savedFile.toPath());
@@ -47,7 +47,7 @@ void fetchFile_shouldThrowIOException_onFailedFetch() {
4747

4848
@Test
4949
void fetchFile_shouldHandleRedirects() throws IOException {
50-
urlInputSource.setMockResponseCode(HttpURLConnection.HTTP_MOVED_TEMP);
50+
urlInputSource.setMockResponseCode(HttpURLConnection.HTTP_OK);
5151
urlInputSource.setMockRedirectUrl("https://example.com/redirectedfile.pdf");
5252

5353
urlInputSource.setMockResponseCode(HttpURLConnection.HTTP_OK);
@@ -84,7 +84,7 @@ void toLocalInputSource_shouldCreateLocalInputSource() throws IOException {
8484
urlInputSource.cleanup();
8585
}
8686

87-
class TestableURLInputSource extends URLInputSource {
87+
static class TestableURLInputSource extends URLInputSource {
8888

8989
@Setter
9090
private int mockResponseCode = HttpURLConnection.HTTP_OK;
@@ -98,23 +98,51 @@ public TestableURLInputSource(String url) {
9898

9999
@Override
100100
protected HttpURLConnection createConnection(String urlString) throws IOException {
101-
HttpURLConnection mockConnection = mock(HttpURLConnection.class);
102-
103-
when(mockConnection.getResponseCode()).thenReturn(mockResponseCode);
101+
java.net.URL url = new java.net.URL(urlString);
102+
boolean wasRedirected = isRedirected;
104103

105-
Path path = Paths.get("src/test/resources/file_types/pdf/multipage.pdf");
106-
if (isRedirected) {
107-
when(mockConnection.getHeaderField("Location")).thenReturn(null);
108-
when(mockConnection.getInputStream()).thenReturn(Files.newInputStream(path));
109-
} else {
110-
when(mockConnection.getHeaderField("Location")).thenReturn(mockRedirectUrl);
111-
when(mockConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_MOVED_TEMP);
104+
if (!isRedirected && mockRedirectUrl != null) {
112105
isRedirected = true;
113-
return mockConnection;
114106
}
115107

116-
when(mockConnection.getInputStream()).thenReturn(Files.newInputStream(path));
117-
return mockConnection;
108+
return new HttpURLConnection(url) {
109+
@Override
110+
public void disconnect() {
111+
}
112+
113+
@Override
114+
public boolean usingProxy() {
115+
return false;
116+
}
117+
118+
@Override
119+
public void connect() {
120+
}
121+
122+
@Override
123+
public int getResponseCode() {
124+
if (mockRedirectUrl != null && !wasRedirected) {
125+
return HttpURLConnection.HTTP_MOVED_TEMP;
126+
}
127+
return mockResponseCode;
128+
}
129+
130+
@Override
131+
public String getHeaderField(String name) {
132+
if ("Location".equalsIgnoreCase(name)) {
133+
if (mockRedirectUrl != null && !wasRedirected) {
134+
return mockRedirectUrl;
135+
}
136+
}
137+
return null;
138+
}
139+
140+
@Override
141+
public java.io.InputStream getInputStream() throws IOException {
142+
Path path = Paths.get("src/test/resources/file_types/pdf/multipage.pdf");
143+
return Files.newInputStream(path);
144+
}
145+
};
118146
}
119147
}
120148
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.mindee.v1;
2+
3+
import com.mindee.v1.http.Endpoint;
4+
import com.mindee.v1.http.MindeeApiV1;
5+
import com.mindee.v1.http.RequestParameters;
6+
import com.mindee.v1.parsing.common.AsyncPredictResponse;
7+
import com.mindee.v1.parsing.common.Inference;
8+
import com.mindee.v1.parsing.common.PredictResponse;
9+
import com.mindee.v1.parsing.common.WorkflowResponse;
10+
import java.io.IOException;
11+
12+
public class FakeMindeeApiV1<T extends Inference> extends MindeeApiV1 {
13+
14+
private final AsyncPredictResponse<T> asyncPredictResponse;
15+
private final PredictResponse<T> predictResponse;
16+
private final WorkflowResponse<T> workflowResponse;
17+
18+
public FakeMindeeApiV1(AsyncPredictResponse<T> asyncPredictResponse) {
19+
this.asyncPredictResponse = asyncPredictResponse;
20+
this.predictResponse = null;
21+
this.workflowResponse = null;
22+
}
23+
24+
public FakeMindeeApiV1(PredictResponse<T> predictResponse) {
25+
this.asyncPredictResponse = null;
26+
this.predictResponse = predictResponse;
27+
this.workflowResponse = null;
28+
}
29+
30+
public FakeMindeeApiV1(WorkflowResponse<T> workflowResponse) {
31+
this.asyncPredictResponse = null;
32+
this.predictResponse = null;
33+
this.workflowResponse = workflowResponse;
34+
}
35+
36+
@Override
37+
public <DocT extends Inference> AsyncPredictResponse<DocT> documentQueueGet(
38+
Class<DocT> documentClass,
39+
Endpoint endpoint,
40+
String jobId
41+
) {
42+
return (AsyncPredictResponse<DocT>) asyncPredictResponse;
43+
}
44+
45+
@Override
46+
public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
47+
Class<DocT> documentClass,
48+
Endpoint endpoint,
49+
RequestParameters requestParameters
50+
) throws IOException {
51+
return (AsyncPredictResponse<DocT>) asyncPredictResponse;
52+
}
53+
54+
@Override
55+
public <DocT extends Inference> PredictResponse<DocT> predictPost(
56+
Class<DocT> documentClass,
57+
Endpoint endpoint,
58+
RequestParameters requestParameters
59+
) throws IOException {
60+
return (PredictResponse<DocT>) predictResponse;
61+
}
62+
63+
@Override
64+
public <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
65+
Class<DocT> documentClass,
66+
String workflowId,
67+
RequestParameters requestParameters
68+
) throws IOException {
69+
return (WorkflowResponse<DocT>) workflowResponse;
70+
}
71+
}

0 commit comments

Comments
 (0)