Search in sources :

Example 26 with JsonArray

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

the class BoxFileTest method testSetClassification.

@Test
public void testSetClassification() throws IOException {
    final String fileID = "12345";
    final String classificationType = "Internal";
    final String metadataURL = "/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo";
    JsonObject metadataObject = new JsonObject().add("op", "replace").add("path", "/Box__Security__Classification__Key").add("value", "Internal");
    JsonArray metadataArray = new JsonArray().add(metadataObject);
    String result = TestConfig.getFixture("BoxFile/UpdateClassificationOnFile200");
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(metadataURL)).willReturn(WireMock.aResponse().withStatus(409)));
    wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(metadataURL)).withRequestBody(WireMock.equalToJson(metadataArray.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json-patch+json").withBody(result)));
    BoxFile file = new BoxFile(this.api, fileID);
    String classification = file.setClassification(classificationType);
    assertEquals(classificationType, classification);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 27 with JsonArray

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

the class BoxFileTest method testChunkedUploadWithCorrectPartSize.

@Test
public void testChunkedUploadWithCorrectPartSize() throws IOException, InterruptedException {
    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";
    FakeStream stream = new FakeStream("aaaaa");
    String sessionResult = TestConfig.getFixture("BoxFile/CreateUploadSession201", wireMockRule.port());
    String uploadResult = TestConfig.getFixture("BoxFile/UploadPartOne200");
    String commitResult = TestConfig.getFixture("BoxFile/CommitUpload201");
    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);
    JsonObject commitObject = new JsonObject().add("parts", parts);
    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);
    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());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 28 with JsonArray

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

the class JsonIterator method loadNextPage.

private void loadNextPage() {
    QueryStringBuilder builder = pagingParameters.asQueryStringBuilder();
    URL url;
    try {
        url = builder.addToURL(this.url);
    } catch (MalformedURLException e) {
        throw new BoxAPIException("Couldn't append a query string to the provided URL.");
    }
    BoxAPIRequest request = new BoxAPIRequest(this.api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    String json = response.getJSON();
    JsonObject responseObject = Json.parse(json).asObject();
    if (pagingParameters.isMarkerBasedPaging()) {
        continueAsMarkerBasedPaging(responseObject);
    } else {
        continueAsOffsetBasedPaging(responseObject);
    }
    JsonArray jsonArray = responseObject.get("entries").asArray();
    this.currentPage = jsonArray.iterator();
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) MalformedURLException(java.net.MalformedURLException) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Example 29 with JsonArray

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

the class Metadata method test.

/**
 * Tests that a list of properties has the expected value.
 * The values passed in will have to be an exact match with no extra elements.
 *
 * @param path   the path that designates the key. Must be prefixed with a "/".
 * @param values the list of expected values.
 * @return this metadata object.
 */
public Metadata test(String path, List<String> values) {
    JsonArray arr = new JsonArray();
    for (String value : values) {
        arr.add(value);
    }
    this.addOp("test", path, arr);
    return this;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray)

Example 30 with JsonArray

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

the class Metadata method replace.

/**
 * Replaces an existing metadata value of array type.
 *
 * @param path   the path that designates the key. Must be prefixed with a "/".
 * @param values the collection of values.
 * @return the metadata object.
 */
public Metadata replace(String path, List<String> values) {
    JsonArray arr = new JsonArray();
    for (String value : values) {
        arr.add(value);
    }
    this.values.add(this.pathToProperty(path), arr);
    this.addOp("replace", path, arr);
    return this;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray)

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