Java Code Examples for com.google.gson.internal.LinkedTreeMap#put()

The following examples show how to use com.google.gson.internal.LinkedTreeMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomObjectMapperTest.java    From airtable.java with MIT License 5 votes vote down vote up
@Test
public void convertListTest(){

    listConverter.setListClass(Attachment.class);

    Class type = List.class;
    List value = new ArrayList();

    LinkedTreeMap ltm = new LinkedTreeMap();
    ltm.put("id","id0001");
    ltm.put("url","http://test.com");
    ltm.put("filename","filename.txt");
    ltm.put("size","10");
    ltm.put("type","image/jpeg");

    Map<String,Thumbnail> thumbnails = new HashMap<>();
    Thumbnail tmb = new Thumbnail();

    tmb.setName("Thumbnail");
    tmb.setUrl("http:example.com");
    tmb.setWidth(Float.valueOf(10));
    tmb.setHeight(Float.valueOf(10));

    thumbnails.put("small", tmb);

    ltm.put("thumbnails",thumbnails);

    value.add(0, ltm);

    List<Attachment> list = (List<Attachment>) listConverter.convert(type, value);
    assertNotNull(list);
    assertNotNull(list.get(0).getId());
    assertNotNull(list.get(0).getFilename());
    assertNotNull(list.get(0).getSize());
    assertNotNull(list.get(0).getType());
    assertNotNull(list.get(0).getUrl());
    assertNotNull(list.get(0).getThumbnails());

}
 
Example 2
Source File: ObjectTypeAdapter.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public Object read(JsonReader jsonreader)
{
    JsonToken jsontoken = jsonreader.peek();
    switch (h.a[jsontoken.ordinal()])
    {
    default:
        throw new IllegalStateException();

    case 1: // '\001'
        ArrayList arraylist = new ArrayList();
        jsonreader.beginArray();
        for (; jsonreader.hasNext(); arraylist.add(read(jsonreader))) { }
        jsonreader.endArray();
        return arraylist;

    case 2: // '\002'
        LinkedTreeMap linkedtreemap = new LinkedTreeMap();
        jsonreader.beginObject();
        for (; jsonreader.hasNext(); linkedtreemap.put(jsonreader.nextName(), read(jsonreader))) { }
        jsonreader.endObject();
        return linkedtreemap;

    case 3: // '\003'
        return jsonreader.nextString();

    case 4: // '\004'
        return Double.valueOf(jsonreader.nextDouble());

    case 5: // '\005'
        return Boolean.valueOf(jsonreader.nextBoolean());

    case 6: // '\006'
        jsonreader.nextNull();
        return null;
    }
}
 
Example 3
Source File: HashMapHelperTest.java    From remote-monitoring-services-java with MIT License 4 votes vote down vote up
@Test(timeout = 1000)
@Category({UnitTest.class})
public void MapToHashSetTest() {
    Assert.assertTrue(HashMapHelper.mapToHashSet("", null).size() == 0);

    LinkedTreeMap linkedTreeMap = new LinkedTreeMap();
    linkedTreeMap.put("mapLevel3", "string value");
    HashMap table = new HashMap<String, Object>() {
        {
            put("aString", "string value");
            put("aBool", true);
            put("aNumber", 12.3);
            put("map1Level1", new HashMap<String, String>() {{
                put("aString", "string value");
            }});
            put("map2Level1", new HashMap<String, Object>() {{
                put("map2Level2-1", new HashMap<String, Object>() {
                    {
                        put("aString", "string value");
                    }
                });
                put("map2Level2-2", linkedTreeMap);
            }});
        }
    };

    HashSet<String> set = HashMapHelper.mapToHashSet("Tags", table);

    List<String> expectedList = Arrays.asList(
        "Tags.aString",
        "Tags.aBool",
        "Tags.aNumber",
        "Tags.map1Level1.aString",
        "Tags.map2Level1.map2Level2-1.aString",
        "Tags.map2Level1.map2Level2-2.mapLevel3"
    );
    Assert.assertTrue(set.containsAll(expectedList));
    Assert.assertTrue(expectedList.containsAll(set));

    HashSet<String> setWithoutPrefix = HashMapHelper.mapToHashSet("", table);

    List<String> expectedListWithoutPrefix = Arrays.asList(
            "aString",
            "aBool",
            "aNumber",
            "map1Level1.aString",
            "map2Level1.map2Level2-1.aString",
            "map2Level1.map2Level2-2.mapLevel3"
    );
    Assert.assertTrue(setWithoutPrefix.containsAll(expectedListWithoutPrefix));
    Assert.assertTrue(expectedListWithoutPrefix.containsAll(setWithoutPrefix));
}
 
Example 4
Source File: CustomObjectMapperTest.java    From airtable.java with MIT License 4 votes vote down vote up
@Test
public void convertMapTest(){

    mapConverter.setMapClass(Thumbnail.class);

    Class type = Map.class;

    LinkedTreeMap<String, Object> value = new LinkedTreeMap<>();
    LinkedTreeMap<String, Object> innerMap = new LinkedTreeMap<>();

    innerMap.put("url","http://example.com");
    value.put("small",innerMap);


    Map<String,Thumbnail> thumb = (Map<String,Thumbnail>) mapConverter.convert(type,value);
    System.out.println(thumb);
    assertNotNull(thumb);
    assertNotNull(thumb.get("small"));
    assertNotNull(thumb.get("small").getUrl());



}
 
Example 5
Source File: NodesApiTest.java    From alfresco-client-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void folderLifeCycleTests() throws IOException
{
    // Request Node By Id
    NodesAPI nodeService = client.getAPI(NodesAPI.class);

    // Request Site By Id
    Response<ResultPaging<NodeRepresentation>> response = nodeService.listNodeChildrenCall(NodesAPI.FOLDER_MY)
            .execute();
    Assert.assertNotNull(response);
    Assert.assertEquals(response.isSuccessful(), true);

    // Check Response
    ResultPaging<NodeRepresentation> nodesResponse = response.body();
    Assert.assertNotNull(nodesResponse, "Response is empty");
    Assert.assertNotNull(nodesResponse.getList(), "Response has no listActivitiesForPersonCall object");
    // Assert.assertNotNull(nodesResponse.getList().getPagination(),
    // "Response has no pagination");

    // Clean Up if necessary
    if (nodesResponse.getCount() != 7)
    {
        for (int i = 0; i < nodesResponse.getCount(); i++)
        {
            String name = nodesResponse.getList().get(i).getName();
            if (name.equals("TestV3") || name.equals("TestV2") || name.equals("Test"))
            {
                nodeService.deleteNodeCall(nodesResponse.getList().get(i).getId()).execute();
            }
        }
        nodesResponse = nodeService.listNodeChildrenCall(NodesAPI.FOLDER_MY).execute().body();
    }

    Assert.assertEquals(nodesResponse.getCount(), 7, "Pagination Total items is wrong. Stale state ?");
    // Assert.assertEquals(nodesResponse.getCount(), 7,
    // "Pagination Count is wrong. Stale state ?");

    Assert.assertNotNull(nodesResponse.getList().get(0), "Response has no pagination");

    // CREATE
    NodeBodyCreate request = new NodeBodyCreate("Test", "cm:folder");
    Response<NodeRepresentation> testNodeResponse = nodeService.createNodeCall(NodesAPI.FOLDER_ROOT, request)
            .execute();
    Assert.assertNotNull(testNodeResponse, "Response is empty");
    Assert.assertEquals(testNodeResponse.isSuccessful(), true);
    Assert.assertNotNull(testNodeResponse.body(), "Response body is empty");

    // Check Node Info
    NodeRepresentation testNode = testNodeResponse.body();
    Assert.assertTrue(testNode.isFolder(), "Test Folder is not a Folder ??");
    Assert.assertEquals(testNode.getName(), "Test", "Root Folder is not Company Home");
    Assert.assertEquals(testNode.getNodeType(), "cm:folder", "Root Folder is not a Folder ??");
    Assert.assertNotNull(testNode.getId(), "Node Identifier is empty");
    Assert.assertTrue(NodeRefUtils.isIdentifier(testNode.getId()), "Node Identifier is not an identifier");
    Assert.assertNotNull(testNode.getParentId(), "Test has a Parent ?");
    for (String aspect : testNode.getAspects())
    {
        Assert.assertTrue(DEFAULT_FOLDER_ASPECTS.contains(aspect), aspect + "is not a default aspect");
    }

    Assert.assertFalse(testNode.hasAspects("cm:titled"), "Titled has been set without requesting");
    Assert.assertNull(testNode.getProperties(), "Properties is defined");

    // RENAME
    NodeBodyUpdate renameRequest = new NodeBodyUpdate("TestV2");
    Response<NodeRepresentation> updatedResponse = nodeService.updateNodeCall(testNode.getId(), renameRequest)
            .execute();
    Assert.assertEquals(updatedResponse.body().getName(), "TestV2", "Folder renaming is wrong");

    Response<NodeRepresentation> updated2Response = nodeService.getNodeCall(testNode.getId()).execute();
    Assert.assertEquals(updated2Response.body().getName(), "TestV2", "Folder renaming is wrong");
    Assert.assertEquals(updated2Response.body().getName(), updatedResponse.body().getName(),
            "Folder renaming is wrong");

    // EDIT PROPERTIES
    LinkedTreeMap<String, Object> properties = new LinkedTreeMap<>();
    properties.put("cm:title", "ALFRESCO");
    NodeBodyUpdate editRequest = new NodeBodyUpdate("TestV3", null, properties, null);
    Response<NodeRepresentation> editedResponse = nodeService.updateNodeCall(testNode.getId(), editRequest)
            .execute();

    Assert.assertEquals(editedResponse.body().getProperties().get("cm:title"), "ALFRESCO",
            "Wrong value for cm:title");
    Assert.assertNull(editedResponse.body().getProperties().get("cm:description"),
            "Wrong value for cm:description");

    // DELETE
    Response<Void> deleteResponse = nodeService.deleteNodeCall(testNode.getId()).execute();
    Assert.assertNotNull(deleteResponse, "Response is empty");
    Assert.assertEquals(deleteResponse.isSuccessful(), true);
    Assert.assertNull(deleteResponse.body(), "Response body is not empty");
}
 
Example 6
Source File: TutorialTest.java    From alfresco-client-sdk with Apache License 2.0 4 votes vote down vote up
static void tutorialPart4ManagingNodes() throws IOException {

        // Select NodesAPI
        NodesAPI nodesAPI = client.getNodesAPI();

        //Create Empty Node with Properties
        LinkedTreeMap<String, Object> properties = new LinkedTreeMap<>();
        properties.put(ContentModel.PROP_TITLE, "The Title");

        NodeBodyCreate emptyFileBody = new NodeBodyCreate("my-file.txt", ContentModel.TYPE_CONTENT, properties, null);

        Response<NodeRepresentation> emptyNodeResponse = nodesAPI.createNodeCall(NodesAPI.FOLDER_MY, emptyFileBody, true, null, null).execute();

        NodeRepresentation emptyNode = emptyNodeResponse.body();
        Assert.assertEquals(emptyNode.getContent().getSizeInBytes(), 0);

        //Get Node Information
        String nodeId = emptyNode.getId();
        NodeRepresentation node = nodesAPI.getNodeCall(nodeId).execute().body();
        Assert.assertNotNull(node.getProperties());
        Assert.assertNotNull(node.getAspects());
        Assert.assertTrue(node.isFile());
        Assert.assertFalse(node.isFolder());
        Assert.assertNull(node.isLink());
        Assert.assertNull(node.getPath());

        //Get node information with isLink and path
        node = nodesAPI.getNodeCall(nodeId, new IncludeParam(Arrays.asList("isLink", "path")), null, null).execute().body();
        Assert.assertFalse(node.isLink());
        Assert.assertNotNull(node.getPath());

        //Update Node Information
        LinkedTreeMap<String, Object> props = new LinkedTreeMap<>();
        props.put(ContentModel.PROP_DESCRIPTION, "The Description");
        props.put(ContentModel.PROP_MANUFACTURER, "Canon");
        NodeRepresentation updatedNode = nodesAPI.updateNodeCall(nodeId, new NodeBodyUpdate(props)).execute().body();
        Assert.assertEquals(updatedNode.getProperties().get(ContentModel.PROP_DESCRIPTION), "The Description");
        Assert.assertEquals(updatedNode.getProperties().get(ContentModel.PROP_MANUFACTURER), "Canon");

        //Rename Node
        NodeRepresentation renamedNode = nodesAPI.updateNodeCall(nodeId, new NodeBodyUpdate("renamed-file.txt")).execute().body();
        Assert.assertEquals(renamedNode.getName(), "renamed-file.txt");

        //Change owner
        props = new LinkedTreeMap<>();
        props.put("cm:owner", "gavinc");
        NodeRepresentation ownerNode = nodesAPI.updateNodeCall(nodeId, new NodeBodyUpdate(props)).execute().body();
        Assert.assertEquals(((LinkedTreeMap) ownerNode.getProperties().get("cm:owner")).get("id"), "gavinc");

        //Remove Exif Aspects
        List<String> aspectNames = new ArrayList<>();
        aspectNames.add(ContentModel.ASPECT_TITLED);
        aspectNames.add(ContentModel.ASPECT_AUDITABLE);
        aspectNames.add("cm:ownable");
        NodeRepresentation aspectNode = nodesAPI.updateNodeCall(nodeId, new NodeBodyUpdate(null, null, null, aspectNames)).execute().body();
        Assert.assertTrue(aspectNode.getAspects().contains(ContentModel.ASPECT_TITLED));
        Assert.assertTrue(aspectNode.getAspects().contains(ContentModel.ASPECT_AUDITABLE));
        Assert.assertTrue(aspectNode.getAspects().contains("cm:ownable"));
        Assert.assertFalse(aspectNode.getAspects().contains(ContentModel.ASPECT_EXIF));

        //Change Node Type
        NodeRepresentation changedTypeNode = nodesAPI.updateNodeCall(nodeId, new NodeBodyUpdate(null, "cm:savedquery", null, null)).execute().body();
        Assert.assertEquals(changedTypeNode.getNodeType(), "cm:savedquery");

        //Update Content
        RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), "This is the initial content for the file.");
        NodeRepresentation updatedContentNode = nodesAPI.updateNodeContentCall(nodeId, requestBody).execute().body();
        Assert.assertEquals(updatedContentNode.getContent().getSizeInBytes(), 41);

        //Get Content
        Call<ResponseBody> downloadCall = nodesAPI.getNodeContentCall(nodeId);
        File dlFile = new File("W:\\", "dl.txt");
        IOUtils.copyFile(downloadCall.execute().body().byteStream(), dlFile);

        //Delete Node
        Response<Void> deleteCall = nodesAPI.deleteNodeCall(nodeId).execute();
        Assert.assertTrue(deleteCall.isSuccessful());

        //Delete Node Permanently
        Response<Void> deleteCallPermanently = nodesAPI.deleteNodeCall(nodeId, true).execute();
        Assert.assertTrue(deleteCallPermanently.isSuccessful());

    }