Skip to content

Commit dc06ae7

Browse files
committed
use array instead of list for webhook ids
1 parent 0318904 commit dc06ae7

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

src/main/java/com/mindee/InferenceParameters.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.mindee;
22

3-
import com.mindee.input.PageOptions;
4-
import java.util.Collections;
5-
import java.util.List;
63
import java.util.Objects;
74
import lombok.Data;
85
import lombok.Getter;
@@ -28,7 +25,7 @@ public final class InferenceParameters {
2825
/**
2926
* IDs of webhooks to propagate the API response to (may be empty).
3027
*/
31-
private final List<String> webhookIds;
28+
private final String[] webhookIds;
3229
/**
3330
* Polling options. Set only if having timeout issues.
3431
*/
@@ -52,7 +49,7 @@ public static final class Builder {
5249
private final String modelId;
5350
private boolean rag = false;
5451
private String alias;
55-
private List<String> webhookIds = Collections.emptyList();
52+
private String[] webhookIds = new String[]{};
5653
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
5754

5855
private Builder(String modelId) {
@@ -72,12 +69,11 @@ public Builder alias(String alias) {
7269
}
7370

7471
/** Provide IDs of webhooks to forward the API response to. */
75-
public Builder webhookIds(List<String> webhookIds) {
72+
public Builder webhookIds(String[] webhookIds) {
7673
this.webhookIds = webhookIds;
7774
return this;
7875
}
7976

80-
8177
public Builder pollingOptions(AsyncPollingOptions pollingOptions) {
8278
this.pollingOptions = pollingOptions;
8379
return this;

src/main/java/com/mindee/http/MindeeHttpApiV2.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,33 +248,33 @@ private MindeeHttpExceptionV2 getHttpError(ClassicHttpResponse response) {
248248

249249
private HttpEntity buildHttpBody(
250250
MultipartEntityBuilder builder,
251-
InferenceParameters options
251+
InferenceParameters params
252252
) {
253253

254-
if (options.getAlias() != null) {
254+
if (params.getAlias() != null) {
255255
builder.addTextBody(
256256
"alias",
257-
options.getAlias().toLowerCase()
257+
params.getAlias().toLowerCase()
258258
);
259259
}
260260

261-
builder.addTextBody("model_id", options.getModelId());
262-
if (options.isRag()) {
261+
builder.addTextBody("model_id", params.getModelId());
262+
if (params.isRag()) {
263263
builder.addTextBody("rag", "true");
264264
}
265-
if (options.getAlias() != null) {
266-
builder.addTextBody("alias", options.getAlias());
265+
if (params.getAlias() != null) {
266+
builder.addTextBody("alias", params.getAlias());
267267
}
268-
if (!options.getWebhookIds().isEmpty()) {
269-
builder.addTextBody("webhook_ids", String.join(",", options.getWebhookIds()));
268+
if (params.getWebhookIds().length > 0) {
269+
builder.addTextBody("webhook_ids", String.join(",", params.getWebhookIds()));
270270
}
271271
return builder.build();
272272
}
273273

274274

275275
private HttpPost buildHttpPost(
276276
String url,
277-
InferenceParameters options
277+
InferenceParameters params
278278
) {
279279
HttpPost post;
280280
try {

src/test/java/com/mindee/MindeeClientV2IT.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
3030
LocalInputSource source = new LocalInputSource(
3131
new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf"));
3232

33-
InferenceParameters options = InferenceParameters
33+
InferenceParameters params = InferenceParameters
3434
.builder(modelId)
3535
.rag(false)
3636
.alias("java-integration-test")
3737
.build();
3838

39-
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options);
39+
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, params);
4040

4141
assertNotNull(response);
4242
assertNotNull(response.getInference());
@@ -93,15 +93,33 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc
9393
@DisplayName("Invalid model ID – enqueue must raise 422")
9494
void invalidModel_mustThrowError() throws IOException {
9595
LocalInputSource source = new LocalInputSource(
96-
new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf"));
96+
new File("src/test/resources/file_types/pdf/blank_1.pdf"));
9797

98-
InferenceParameters options = InferenceParameters
99-
.builder("INVALID MODEL ID")
98+
InferenceParameters params = InferenceParameters
99+
.builder("INVALID_MODEL_ID")
100+
.build();
101+
102+
MindeeHttpExceptionV2 ex = assertThrows(
103+
MindeeHttpExceptionV2.class,
104+
() -> mindeeClient.enqueueInference(source, params)
105+
);
106+
assertEquals(422, ex.getStatus());
107+
}
108+
109+
@Test
110+
@DisplayName("Invalid webhook ID – enqueue must raise 422")
111+
void invalidWebhook_mustThrowError() throws IOException {
112+
LocalInputSource source = new LocalInputSource(
113+
new File("src/test/resources/file_types/pdf/blank_1.pdf"));
114+
115+
InferenceParameters params = InferenceParameters
116+
.builder(modelId)
117+
.webhookIds(new String[]{"INVALID_WEBHOOK_ID"})
100118
.build();
101119

102120
MindeeHttpExceptionV2 ex = assertThrows(
103121
MindeeHttpExceptionV2.class,
104-
() -> mindeeClient.enqueueInference(source, options)
122+
() -> mindeeClient.enqueueInference(source, params)
105123
);
106124
assertEquals(422, ex.getStatus());
107125
}
@@ -111,7 +129,7 @@ void invalidModel_mustThrowError() throws IOException {
111129
void invalidJob_mustThrowError() {
112130
MindeeHttpExceptionV2 ex = assertThrows(
113131
MindeeHttpExceptionV2.class,
114-
() -> mindeeClient.getInference("not-a-valid-job-ID")
132+
() -> mindeeClient.getInference("INVALID_JOB_ID")
115133
);
116134
assertEquals(422, ex.getStatus());
117135
assertNotNull(ex);

0 commit comments

Comments
 (0)