Search in sources :

Example 96 with JsonArray

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());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 97 with JsonArray

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());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 98 with JsonArray

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());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) Date(java.util.Date) Test(org.junit.Test)

Example 99 with JsonArray

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));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 100 with JsonArray

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());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonArray (com.eclipsesource.json.JsonArray)111 JsonObject (com.eclipsesource.json.JsonObject)96 JsonValue (com.eclipsesource.json.JsonValue)32 Test (org.junit.Test)30 URL (java.net.URL)28 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)11 Matchers.containsString (org.hamcrest.Matchers.containsString)6 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)5 Map (java.util.Map)5 Link (org.eclipse.leshan.Link)4 Date (java.util.Date)3 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)3 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)2 MalformedURLException (java.net.MalformedURLException)2 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2