Search in sources :

Example 46 with JsonArray

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

the class MetadataTest method audiencesAsList.

private List<String> audiencesAsList(JsonValue value) {
    JsonArray jsonValues = value.asArray();
    List<String> audiences = new ArrayList<>();
    for (JsonValue jsonValue : jsonValues) {
        audiences.add(jsonValue.asString());
    }
    return audiences;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue)

Example 47 with JsonArray

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

the class BoxWebHookTest method testCreateWebhookSucceedsAndSendsCorrectJson.

@Test
public void testCreateWebhookSucceedsAndSendsCorrectJson() throws IOException {
    final String webhookID = "12345";
    final String folderID = "1111";
    final String createdByID = "2222";
    final String createdByLogin = "test@user.com";
    final String address = "https:/example.com";
    final String webhookURL = "/webhooks";
    JsonObject innerObject = new JsonObject().add("type", "folder").add("id", "1111");
    JsonObject webhookObject = new JsonObject().add("target", innerObject).add("triggers", new JsonArray().add("FILE.LOCKED")).add("address", address);
    String result = TestConfig.getFixture("BoxWebhook/CreateWebhook201");
    wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(webhookURL)).withRequestBody(WireMock.equalToJson(webhookObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(result)));
    BoxFolder folder = new BoxFolder(this.api, folderID);
    BoxWebHook.Info webhookInfo = BoxWebHook.create(folder, new URL(address), BoxWebHook.Trigger.FILE_LOCKED);
    assertEquals(webhookID, webhookInfo.getID());
    assertEquals(folderID, webhookInfo.getTarget().getId());
    assertEquals(createdByID, webhookInfo.getCreatedBy().getID());
    assertEquals(createdByLogin, webhookInfo.getCreatedBy().getLogin());
    assertEquals(BoxWebHook.Trigger.FILE_LOCKED, webhookInfo.getTriggers().iterator().next());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) Test(org.junit.Test)

Example 48 with JsonArray

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

the class BoxWebHookTest method testUpdateWebhookInfoSucceeds.

@Test
public void testUpdateWebhookInfoSucceeds() throws IOException {
    final String newAddress = "https://newexample.com";
    final String webhookID = "12345";
    final String createdByLogin = "test@user.com";
    final String webhookURL = "/webhooks/" + webhookID;
    JsonArray triggers = new JsonArray().add("FILE.UPLOADED");
    JsonObject updateObject = new JsonObject().add("triggers", triggers).add("address", newAddress);
    String result = TestConfig.getFixture("BoxWebhook/UpdateWebhookInfo200");
    wireMockRule.stubFor(WireMock.get(WireMock.urlPathEqualTo(webhookURL)).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(result)));
    wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(webhookURL)).withRequestBody(WireMock.equalToJson(updateObject.toString())).willReturn(WireMock.aResponse().withHeader("Content-Type", "application/json").withBody(result)));
    BoxWebHook webhook = new BoxWebHook(this.api, webhookID);
    BoxWebHook.Info info = webhook.new Info();
    info.setAddress(new URL(newAddress));
    info.setTriggers(BoxWebHook.Trigger.FILE_UPLOADED);
    webhook.updateInfo(info);
    assertEquals(new URL(newAddress), info.getAddress());
    assertEquals(webhookID, info.getID());
    assertEquals(createdByLogin, info.getCreatedBy().getLogin());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) Test(org.junit.Test)

Example 49 with JsonArray

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

the class MetadataTemplateTest method testDeprecatedExecuteMetadataQuery.

@Test
public void testDeprecatedExecuteMetadataQuery() throws IOException {
    final String metadataQueryURL = "/metadata_queries/execute_read";
    final String from = "enterprise_67890.relayWorkflowInformation";
    final String query = "templateName >= :arg";
    final JsonObject queryParameters = new JsonObject().add("arg", "Templ Name");
    final String ancestorFolderId = "0";
    final String indexName = null;
    final JsonArray orderBy = null;
    final int limit = 2;
    final String marker = null;
    // First request will return a page of results with two items
    String request1 = TestConfig.getFixture("BoxMetadataTemplate/MetadataQuery1stRequest");
    String result1 = TestConfig.getFixture("BoxMetadataTemplate/MetadataQuery1stResponse200");
    wireMockRule.stubFor(post(urlPathEqualTo(metadataQueryURL)).withRequestBody(equalToJson(request1)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(result1)));
    // Second request will contain a marker and will return a page of results with remaining one item
    String result2 = TestConfig.getFixture("BoxMetadataTemplate/MetadataQuery2ndResponse200");
    String request2 = TestConfig.getFixture("BoxMetadataTemplate/MetadataQuery2ndRequest");
    wireMockRule.stubFor(post(urlPathEqualTo(metadataQueryURL)).withRequestBody(equalToJson(request2)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(result2)));
    // Make the first request and get the result
    BoxResourceIterable<BoxMetadataQueryItem> results = MetadataTemplate.executeMetadataQuery(this.api, from, query, queryParameters, ancestorFolderId, indexName, orderBy, limit, marker);
    // First item on the first page of results
    BoxMetadataQueryItem currBoxItem = results.iterator().next();
    assertEquals("file", currBoxItem.getItem().getType());
    assertEquals("123450", currBoxItem.getItem().getID());
    assertEquals("1.jpg", currBoxItem.getItem().getName());
    HashMap<String, ArrayList<Metadata>> metadata = currBoxItem.getMetadata();
    assertEquals("relayWorkflowInformation", metadata.get("enterprise_67890").get(0).getTemplateName());
    assertEquals("enterprise_67890", metadata.get("enterprise_67890").get(0).getScope());
    assertEquals("Werk Flow 0", metadata.get("enterprise_67890").get(0).getString("/workflowName"));
    // Second item on the first page of results
    currBoxItem = results.iterator().next();
    assertEquals("file", currBoxItem.getItem().getType());
    assertEquals("123451", currBoxItem.getItem().getID());
    assertEquals("2.jpg", currBoxItem.getItem().getName());
    metadata = currBoxItem.getMetadata();
    assertEquals("relayWorkflowInformation", metadata.get("enterprise_67890").get(0).getTemplateName());
    assertEquals("randomTemplate", metadata.get("enterprise_67890").get(1).getTemplateName());
    assertEquals("someTemplate", metadata.get("enterprise_123456").get(0).getTemplateName());
    // First item on the second page of results (this next call makes the second request to get the second page)
    currBoxItem = results.iterator().next();
    assertEquals("file", currBoxItem.getItem().getType());
    assertEquals("123452", currBoxItem.getItem().getID());
    assertEquals("3.jpg", currBoxItem.getItem().getName());
    metadata = currBoxItem.getMetadata();
    assertEquals("relayWorkflowInformation", metadata.get("enterprise_67890").get(0).getTemplateName());
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) Test(org.junit.Test)

Example 50 with JsonArray

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

the class MetadataTemplateTest method testExecuteMetadataQueryWithFields.

@Test
public void testExecuteMetadataQueryWithFields() throws IOException {
    final String metadataQueryURL = "/metadata_queries/execute_read";
    final String from = "enterprise_67890.catalogImages";
    final String query = "photographer = :arg";
    final String ancestorFolderId = "0";
    final String field1 = "sha1";
    final String field2 = "name";
    final String field3 = "id";
    final String field4 = "metadata.enterprise_240748.catalogImages.photographer";
    final int limit = 2;
    JsonArray fields = new JsonArray();
    fields.add(field1);
    fields.add(field2);
    fields.add(field3);
    fields.add(field4);
    JsonObject body = new JsonObject();
    body.add("from", from);
    body.add("query", query);
    body.add("query_params", new JsonObject().add("arg", "Bob Dylan"));
    body.add("ancestor_folder_id", ancestorFolderId);
    body.add("limit", limit);
    body.add("fields", fields);
    // First request will return a page of results with two items
    String result = TestConfig.getFixture("BoxMetadataTemplate/MetadataQueryResponseForFields200");
    wireMockRule.stubFor(post(urlPathEqualTo(metadataQueryURL)).withRequestBody(equalToJson(body.toString())).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(result)));
    // Make the first request and get the result
    MetadataQuery queryBody = new MetadataQuery(from, limit).setQuery(query).addParameter("arg", "Bob Dylan").setAncestorFolderId(ancestorFolderId).setFields(field1, field2, field3, field4);
    BoxResourceIterable<BoxItem.Info> results = MetadataTemplate.executeMetadataQuery(this.api, queryBody);
    // First item on the first page of results
    BoxFile.Info fileBoxItem = (BoxFile.Info) results.iterator().next();
    assertEquals("file", fileBoxItem.getType());
    assertEquals("1244738582", fileBoxItem.getID());
    assertEquals("Very Important.docx", fileBoxItem.getName());
    Metadata fileMetadata = fileBoxItem.getMetadata("catalogImages", "enterprise_67890");
    assertEquals("catalogImages", fileMetadata.getTemplateName());
    assertEquals("enterprise_67890", fileMetadata.getScope());
    assertEquals("Bob Dylan", fileMetadata.getString("/photographer"));
    // Second item on the first page of results
    BoxFolder.Info folderBoxItem = (BoxFolder.Info) results.iterator().next();
    assertEquals("folder", folderBoxItem.getType());
    assertEquals("124242482", folderBoxItem.getID());
    assertEquals("Also Important.docx", folderBoxItem.getName());
    Metadata folderMetadata = folderBoxItem.getMetadata("catalogImages", "enterprise_67890");
    assertEquals("catalogImages", folderMetadata.getTemplateName());
    assertEquals("enterprise_67890", folderMetadata.getScope());
    assertEquals("Bob Dylan", folderMetadata.getString("/photographer"));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) 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