use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class MetadataTest method testAdd.
@Test
public void testAdd() {
Metadata m = new Metadata().add("/foo", "bar");
JsonArray operations = Json.parse(m.getPatch()).asArray();
assertEquals(1, operations.size());
JsonObject op = operations.get(0).asObject();
assertEquals("add", op.get("op").asString());
assertEquals("/foo", op.get("path").asString());
assertEquals("bar", op.get("value").asString());
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class MetadataTest method testTest.
@Test
public void testTest() {
Metadata m = new Metadata().test("/foo", "bar");
JsonArray operations = Json.parse(m.getPatch()).asArray();
assertEquals(1, operations.size());
JsonObject op = operations.get(0).asObject();
assertEquals("test", op.get("op").asString());
assertEquals("/foo", op.get("path").asString());
assertEquals("bar", op.get("value").asString());
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxZipTest method createZipSucceeds.
@Test
public void createZipSucceeds() throws IOException, ParseException {
final String fileID = "466239504569";
final String folderID = "466239504580";
final String downloadFileName = "test";
final String downloadURL = "https://api.box.com/zip_downloads/124hfiowk3fa8kmrwh/content";
final String statusURL = "https://api.box.com/zip_downloads/124hfiowk3fa8kmrwh/status";
final Date expiresAt = BoxDateFormat.parse("2018-04-25T11:00:18-07:00");
ArrayList<BoxZipItem> items = new ArrayList<>();
JsonArray itemsBody = new JsonArray();
BoxZipItem file = new BoxZipItem("file", fileID);
BoxZipItem folder = new BoxZipItem("folder", folderID);
items.add(file);
items.add(folder);
itemsBody.add(file.getJSONObject()).add(folder.getJSONObject());
JsonObject body = new JsonObject().add("items", itemsBody).add("download_file_name", downloadFileName);
String result = TestConfig.getFixture("BoxZip/CreateZipFile202");
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo("/zip_downloads")).withRequestBody(WireMock.equalToJson(body.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(result)));
BoxZip zip = new BoxZip(this.api);
BoxZipInfo zipInfo = zip.create(downloadFileName, items);
BoxZipConflict conflict1 = zipInfo.getNameConflicts().get(0);
List<BoxZipConflictItem> conflict1Items = conflict1.getItems();
assertEquals(downloadURL, zipInfo.getDownloadURL().toString());
assertEquals(statusURL, zipInfo.getStatusURL().toString());
assertEquals(expiresAt, zipInfo.getExpiresAt());
assertEquals("100", conflict1Items.get(0).getID());
assertEquals("salary.pdf", conflict1Items.get(0).getOriginalName());
assertEquals("aqc823.pdf", conflict1Items.get(0).getDownloadName());
assertEquals("200", conflict1Items.get(1).getID());
assertEquals("salary.pdf", conflict1Items.get(1).getOriginalName());
assertEquals("aci23s.pdf", conflict1Items.get(1).getDownloadName());
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class MetadataTemplateTest method testSetOptionReturnsCorrectly.
@Test
public void testSetOptionReturnsCorrectly() throws IOException {
final String metadataTemplateURL = "/metadata_templates/schema";
String result = TestConfig.getFixture("BoxMetadataTemplate/CreateMetadataTemplate200");
JsonObject keyObject = new JsonObject();
keyObject.add("key", "FY16");
JsonObject secondKeyObject = new JsonObject();
secondKeyObject.add("key", "FY17");
JsonArray optionsArray = new JsonArray();
optionsArray.add(keyObject);
optionsArray.add(secondKeyObject);
JsonObject enumObject = new JsonObject();
enumObject.add("type", "enum").add("key", "fy").add("displayName", "FY").add("options", optionsArray);
JsonArray fieldsArray = new JsonArray();
fieldsArray.add(enumObject);
JsonObject templateBody = new JsonObject();
templateBody.add("scope", "enterprise").add("displayName", "Document Flow 03").add("hidden", false).add("templateKey", "documentFlow03").add("fields", fieldsArray);
wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(metadataTemplateURL)).withRequestBody(WireMock.equalToJson(templateBody.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(result)));
MetadataTemplate.Field fyField = new MetadataTemplate.Field();
fyField.setType("enum");
fyField.setKey("fy");
fyField.setDisplayName("FY");
List<String> options = new ArrayList<>();
options.add("FY16");
options.add("FY17");
fyField.setOptions(options);
List<MetadataTemplate.Field> fields = new ArrayList<>();
fields.add(fyField);
MetadataTemplate template = MetadataTemplate.createMetadataTemplate(this.api, "enterprise", "documentFlow03", "Document Flow 03", false, fields);
assertEquals("FY16", template.getFields().get(0).getOptions().get(0));
assertEquals("FY17", template.getFields().get(0).getOptions().get(1));
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class MetadataTemplateTest method testUpdateMetadataReturnsCorrectly.
@Test
public void testUpdateMetadataReturnsCorrectly() throws IOException {
final String metadataTemplateURL = "/metadata_templates/enterprise/documentFlow03/schema";
String result = TestConfig.getFixture("BoxMetadataTemplate/UpdateMetadataTemplate200");
JsonObject editCopyDataObject = new JsonObject();
editCopyDataObject.add("copyInstanceOnItemCopy", true);
JsonObject editCopyOperation = new JsonObject();
editCopyOperation.add("op", "editTemplate");
editCopyOperation.add("data", editCopyDataObject);
JsonArray body = new JsonArray();
body.add(editCopyOperation);
wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(metadataTemplateURL)).withRequestBody(WireMock.equalToJson(body.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(result)));
List<MetadataTemplate.FieldOperation> fieldOperations = new ArrayList<>();
MetadataTemplate.FieldOperation editTemplate = new MetadataTemplate.FieldOperation();
editTemplate.setOp(MetadataTemplate.Operation.editTemplate);
MetadataTemplate.Field copyInstanceField = new MetadataTemplate.Field();
copyInstanceField.setCopyInstanceOnItemCopy(Boolean.TRUE);
editTemplate.setData(copyInstanceField);
fieldOperations.add(editTemplate);
MetadataTemplate template = MetadataTemplate.updateMetadataTemplate(this.api, "enterprise", "documentFlow03", fieldOperations);
assertEquals("Copy instance on item copy not set", true, template.getCopyInstanceOnItemCopy());
}
Aggregations