Search in sources :

Example 91 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class BoxFolderTest method testChunkedParallelUploadWithCorrectPartSizeAndAttributes.

@Test
public void testChunkedParallelUploadWithCorrectPartSizeAndAttributes() throws IOException, InterruptedException {
    String javaVersion = System.getProperty("java.version");
    Assume.assumeFalse("Test is not run for JDK 7", javaVersion.contains("1.7"));
    final String preflightURL = "/files/content";
    final String sessionURL = "/files/upload_sessions";
    final String uploadURL = "/files/upload_sessions/D5E3F8ADA11A38F0A66AD0B64AACA658";
    final String commitURL = "/files/upload_sessions/D5E3F8ADA11A38F0A66AD0B64AACA658/commit";
    BoxFileTest.FakeStream stream = new BoxFileTest.FakeStream("aaaaa");
    String sessionResult = TestConfig.getFixture("BoxFile/CreateUploadSession201", wireMockRule.port());
    String uploadResult = TestConfig.getFixture("BoxFile/UploadPartOne200");
    String commitResult = TestConfig.getFixture("BoxFile/CommitUploadWithAttributes201");
    JsonObject idObject = new JsonObject().add("id", "12345");
    JsonObject preflightObject = new JsonObject().add("name", "testfile.txt").add("size", 5).add("parent", idObject);
    JsonObject sessionObject = new JsonObject().add("folder_id", "12345").add("file_size", 5).add("file_name", "testfile.txt");
    JsonObject partOne = new JsonObject().add("part_id", "CFEB5BA9").add("offset", 0).add("size", 5);
    JsonArray parts = new JsonArray().add(partOne);
    Map<String, String> fileAttributes = new HashMap<>();
    fileAttributes.put("content_modified_at", "2017-04-08T00:58:08Z");
    JsonObject fileAttributesJson = new JsonObject();
    for (String attrKey : fileAttributes.keySet()) {
        fileAttributesJson.set(attrKey, fileAttributes.get(attrKey));
    }
    JsonObject commitObject = new JsonObject().add("parts", parts).add("attributes", fileAttributesJson);
    wireMockRule.stubFor(WireMock.options(WireMock.urlPathEqualTo(preflightURL)).withRequestBody(WireMock.equalToJson(preflightObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withStatus(200)));
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(sessionURL)).withRequestBody(WireMock.equalToJson(sessionObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(sessionResult)));
    wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(uploadURL)).withHeader("Digest", WireMock.containing("sha=31HjfCaaqU04+T5Te/biAgshQGw=")).withHeader("Content-Type", WireMock.containing("application/octet-stream")).withHeader("Content-Range", WireMock.containing("bytes 0-4/5")).withRequestBody(WireMock.equalTo("aaaaa")).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(uploadResult)));
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(commitURL)).withHeader("Content-Type", WireMock.equalTo("application/json")).withRequestBody(WireMock.containing(commitObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(commitResult)));
    BoxFolder folder = new BoxFolder(this.api, "12345");
    BoxFile.Info uploadedFile = folder.uploadLargeFile(stream, "testfile.txt", 5, 2, 60, TimeUnit.SECONDS, fileAttributes);
    assertEquals("1111111", uploadedFile.getID());
    assertEquals("testuser@box.com", uploadedFile.getModifiedBy().getLogin());
    assertEquals("Test User", uploadedFile.getOwnedBy().getName());
    assertEquals("folder", uploadedFile.getParent().getType());
    assertEquals("testfile.txt", uploadedFile.getName());
    assertEquals(1491613088000L, uploadedFile.getContentModifiedAt().getTime());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) HashMap(java.util.HashMap) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 92 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class BoxUserTest method trackingCodesJson.

private JsonObject trackingCodesJson(Map<String, String> trackingCodes) {
    JsonArray trackingCodesJsonArray = new JsonArray();
    for (String attrKey : trackingCodes.keySet()) {
        JsonObject trackingCode = new JsonObject();
        trackingCode.set("type", "tracking_code");
        trackingCode.set("name", attrKey);
        trackingCode.set("value", trackingCodes.get(attrKey));
        trackingCodesJsonArray.add(trackingCode);
    }
    JsonObject trackingCodesJson = new JsonObject();
    trackingCodesJson.set("tracking_codes", trackingCodesJsonArray);
    return trackingCodesJson;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 93 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataQueryTest method createsMetadataQuery.

@Test
public void createsMetadataQuery() {
    MetadataQuery query = new MetadataQuery("from somewhere", 100).setQuery("some query").setAncestorFolderId("23456789").setMarker("some marker").setOrderBy(ascending("field1"), descending("field2")).setFields("field3", "field4");
    JsonObject json = query.toJsonObject();
    assertThat(json.getString(FROM, ""), is("from somewhere"));
    assertThat(json.getInt(LIMIT, 0), is(100));
    assertThat(json.getString(QUERY, ""), is("some query"));
    assertThat(json.getString(ANCESTOR_FOLDER_ID, ""), is("23456789"));
    assertThat(json.getString(MARKER, ""), is("some marker"));
    assertThat(json.get(ORDER_BY).asArray(), is(new JsonArray().add(new JsonObject().add("field_key", "field1").add("direction", "asc")).add(new JsonObject().add("field_key", "field2").add("direction", "desc"))));
    assertThat(json.get(FIELDS).asArray(), is(new JsonArray().add("field3").add("field4")));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 94 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTest method testReplace.

@Test
public void testReplace() {
    Metadata m = new Metadata().replace("/foo", "bar");
    JsonArray operations = Json.parse(m.getPatch()).asArray();
    assertEquals(1, operations.size());
    JsonObject op = operations.get(0).asObject();
    assertEquals("replace", 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 95 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTest method testMultiSelect.

@Test
public void testMultiSelect() {
    String expectedList = "[\"public test 1\",\"public test 2\",\"public test 3\"]";
    List<String> list = new ArrayList<>();
    list.add("public test 1");
    list.add("public test 2");
    list.add("public test 3");
    Metadata m = new Metadata().test("/foo", list);
    JsonArray operations = Json.parse(m.getPatch()).asArray();
    JsonObject op = operations.get(0).asObject();
    assertEquals("test", op.get("op").asString());
    assertEquals("/foo", op.get("path").asString());
    assertEquals(expectedList, op.get("value").toString());
}
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