Skip to content

Commit 4770afa

Browse files
committed
fix ia extract test
1 parent e1c6970 commit 4770afa

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

src/intTest/java/com/box/sdk/BoxAIIT.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.eclipsesource.json.JsonObject;
1616
import java.text.ParseException;
1717
import java.util.ArrayList;
18+
import java.util.Arrays;
1819
import java.util.Collections;
1920
import java.util.Date;
2021
import java.util.List;
@@ -227,47 +228,43 @@ public void aiExtractStructuredWithFields() throws InterruptedException {
227228
BoxAIAgentExtractStructured agentExtractStructured = (BoxAIAgentExtractStructured) agent;
228229

229230
BoxFile uploadedFile = uploadFileToUniqueFolder(api, "[aiExtractStructuredWithFields] Test File.txt",
230-
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar and books.");
231+
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar.");
231232

232233
try {
233234
// When a file has been just uploaded, AI service may not be ready to return text response
234235
// and 412 is returned
235236
retry(() -> {
236237
BoxAIExtractStructuredResponse response = BoxAI.extractMetadataStructured(api,
237238
Collections.singletonList(new BoxAIItem(uploadedFile.getID(), BoxAIItem.Type.FILE)),
238-
new ArrayList<BoxAIExtractField>() {{
239-
add(new BoxAIExtractField("firstName"));
240-
add(new BoxAIExtractField("lastName"));
241-
add(new BoxAIExtractField("date",
239+
Arrays.asList(
240+
new BoxAIExtractField("firstName"),
241+
new BoxAIExtractField("lastName"),
242+
new BoxAIExtractField("date",
242243
"Person date of birth",
243244
"Birth date",
244245
"dateOfBirth",
245246
null,
246-
"What is the date of your birth?"));
247-
add(new BoxAIExtractField("float",
247+
"What is the date of your birth?"),
248+
new BoxAIExtractField("float",
248249
"Person age",
249250
"Age",
250251
"age",
251252
null,
252-
"How old are you?"));
253-
add(new BoxAIExtractField("multiSelect",
253+
"How old are you?"),
254+
new BoxAIExtractField("multiSelect",
254255
"Person hobby",
255256
"Hobby",
256257
"hobby",
257-
new ArrayList<BoxAIExtractFieldOption>() {{
258-
add(new BoxAIExtractFieldOption("guitar"));
259-
add(new BoxAIExtractFieldOption("books"));
260-
}},
261-
"What is your hobby?"));
262-
}},
258+
Collections.singletonList(new BoxAIExtractFieldOption("guitar")),
259+
"What is your hobby?")
260+
),
263261
agentExtractStructured);
264262
JsonObject sourceJson = response.getSourceJson();
265263
assertThat(sourceJson.get("firstName").asString(), is(equalTo("John")));
266264
assertThat(sourceJson.get("lastName").asString(), is(equalTo("Doe")));
267265
assertThat(sourceJson.get("dateOfBirth").asString(), is(equalTo("1990-07-04")));
268266
assertThat(sourceJson.get("age").asInt(), is(equalTo(34)));
269267
assertThat(sourceJson.get("hobby").asArray().get(0).asString(), is(equalTo("guitar")));
270-
assertThat(sourceJson.get("hobby").asArray().get(1).asString(), is(equalTo("books")));
271268
}, 2, 2000);
272269
} finally {
273270
deleteFile(uploadedFile);
@@ -281,30 +278,31 @@ public void aiExtractStructuredWithMetadataTemplate() throws InterruptedExceptio
281278
BoxAIAgentExtractStructured agentExtractStructured = (BoxAIAgentExtractStructured) agent;
282279

283280
BoxFile uploadedFile = uploadFileToUniqueFolder(api, "[aiExtractStructuredWithMetadataTemplate] Test File.txt",
284-
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar and books.");
285-
String templateKey = "key" + java.util.UUID.randomUUID().toString();
281+
"My name is John Doe. I was born in 4th July 1990. I am 34 years old. My hobby is guitar.");
282+
String templateKey = "key" + java.util.UUID.randomUUID();
286283
MetadataTemplate template = MetadataTemplate.createMetadataTemplate(api,
287284
"enterprise",
288285
templateKey,
289286
templateKey,
290287
false,
291-
new ArrayList<MetadataTemplate.Field>() {{
292-
add(new MetadataTemplate.Field(Json.parse(
288+
Arrays.asList(
289+
new MetadataTemplate.Field(Json.parse(
293290
"{\"key\":\"firstName\",\"displayName\":\"First name\","
294-
+ "\"description\":\"Person first name\",\"type\":\"string\"}").asObject()));
295-
add(new MetadataTemplate.Field(Json.parse(
291+
+ "\"description\":\"Person first name\",\"type\":\"string\"}").asObject()),
292+
new MetadataTemplate.Field(Json.parse(
296293
"{\"key\":\"lastName\",\"displayName\":\"Last name\","
297-
+ "\"description\":\"Person last name\",\"type\":\"string\"}").asObject()));
298-
add(new MetadataTemplate.Field(Json.parse(
294+
+ "\"description\":\"Person last name\",\"type\":\"string\"}").asObject()),
295+
new MetadataTemplate.Field(Json.parse(
299296
"{\"key\":\"dateOfBirth\",\"displayName\":\"Birth date\","
300-
+ "\"description\":\"Person date of birth\",\"type\":\"date\"}").asObject()));
301-
add(new MetadataTemplate.Field(Json.parse(
297+
+ "\"description\":\"Person date of birth\",\"type\":\"date\"}").asObject()),
298+
new MetadataTemplate.Field(Json.parse(
302299
"{\"key\":\"age\",\"displayName\":\"Age\","
303-
+ "\"description\":\"Person age\",\"type\":\"float\"}").asObject()));
304-
add(new MetadataTemplate.Field(Json.parse(
300+
+ "\"description\":\"Person age\",\"type\":\"float\"}").asObject()),
301+
new MetadataTemplate.Field(Json.parse(
305302
"{\"key\":\"hobby\",\"displayName\":\"Hobby\","
306-
+ "\"description\":\"Person hobby\",\"type\":\"multiSelect\"}").asObject()));
307-
}});
303+
+ "\"description\":\"Person hobby\",\"type\":\"multiSelect\","
304+
+ " \"options\":[{\"key\": \"guitar\"}, {\"key\": \"books\"}]}").asObject())
305+
));
308306

309307
try {
310308
// When a file has been just uploaded, AI service may not be ready to return text response
@@ -320,7 +318,6 @@ public void aiExtractStructuredWithMetadataTemplate() throws InterruptedExceptio
320318
assertThat(sourceJson.get("dateOfBirth").asString(), is(equalTo("1990-07-04T00:00:00Z")));
321319
assertThat(sourceJson.get("age").asInt(), is(equalTo(34)));
322320
assertThat(sourceJson.get("hobby").asArray().get(0).asString(), is(equalTo("guitar")));
323-
assertThat(sourceJson.get("hobby").asArray().get(1).asString(), is(equalTo("books")));
324321
}, 2, 2000);
325322
} finally {
326323
deleteFile(uploadedFile);

src/test/java/com/box/sdk/BoxAITest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.text.ParseException;
1313
import java.util.ArrayList;
14+
import java.util.Arrays;
1415
import java.util.Collections;
1516
import java.util.Date;
1617
import java.util.List;
@@ -364,10 +365,10 @@ public void testExtractMetadataStructuredWithFieldSuccess() {
364365
"The name of the file",
365366
"Name",
366367
"name",
367-
new ArrayList<BoxAIExtractFieldOption>() {{
368-
add(new BoxAIExtractFieldOption("option 1"));
369-
add(new BoxAIExtractFieldOption("option 2"));
370-
}},
368+
Arrays.asList(
369+
new BoxAIExtractFieldOption("option 1"),
370+
new BoxAIExtractFieldOption("option 2")
371+
),
371372
"What is the name of the file?");
372373

373374
final JsonObject expectedRequestBody = new JsonObject()

0 commit comments

Comments
 (0)