Search in sources :

Example 11 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class TreeItemUtil_Test method testCopyTree.

@Test
public void testCopyTree() {
    TreeItemIdNode copy = TreeItemUtil.copyTreeNode(MockTreeItemData.TEST_MULTI_TREE);
    Assert.assertTrue("Copy of tree should be the same", TreeItemUtil.isTreeSame(MockTreeItemData.TEST_MULTI_TREE, copy));
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) Test(org.junit.Test)

Example 12 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class TreeItemUtil_Test method testConvertJsonToTreeEmptyString.

@Test
public void testConvertJsonToTreeEmptyString() {
    TreeItemIdNode root = TreeItemUtil.convertJsonToTree("");
    Assert.assertNotNull("Empty string - Root node not returned", root);
    Assert.assertTrue("Empty String - Root should have no children", root.getChildren().isEmpty());
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) Test(org.junit.Test)

Example 13 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class TreeItemUtil_Test method testConvertJsonToTreeMultipleLevel.

@Test
public void testConvertJsonToTreeMultipleLevel() {
    // Mock custom structure
    // A
    // C
    // - C.1
    // - B (hasChildren)
    // C.1.1 (hasChildren)
    TreeItemIdNode root = TreeItemUtil.convertJsonToTree(MockTreeItemData.TEST_MULTI_JSON);
    Assert.assertNotNull("Root node not returned", root);
    Assert.assertEquals("Root should have three children", 3, root.getChildren().size());
    // A
    TreeItemIdNode node = root.getChildren().get(0);
    Assert.assertEquals("Incorrect node id", "A", node.getItemId());
    Assert.assertTrue("Node should have no children", node.getChildren().isEmpty());
    Assert.assertFalse("Node hasChildren flag incorrect", node.hasChildren());
    // C
    node = root.getChildren().get(1);
    Assert.assertEquals("Incorrect node id", "C", node.getItemId());
    Assert.assertEquals("Node should have one child", 1, node.getChildren().size());
    Assert.assertTrue("Node hasChildren flag incorrect", node.hasChildren());
    // C.1
    node = node.getChildren().get(0);
    Assert.assertEquals("Incorrect node id", "C.1", node.getItemId());
    Assert.assertEquals("Node should have one child", 1, node.getChildren().size());
    Assert.assertTrue("Node hasChildren flag incorrect", node.hasChildren());
    // B
    node = node.getChildren().get(0);
    Assert.assertEquals("Incorrect node id", "B", node.getItemId());
    Assert.assertTrue("Node should have no children", node.getChildren().isEmpty());
    Assert.assertTrue("Node hasChildren flag incorrect", node.hasChildren());
    // C.1.1
    node = root.getChildren().get(2);
    Assert.assertEquals("Incorrect node id", "C.1.1", node.getItemId());
    Assert.assertTrue("Node should have no children", node.getChildren().isEmpty());
    Assert.assertTrue("Node hasChildren flag incorrect", node.hasChildren());
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) Test(org.junit.Test)

Example 14 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class TreeItemUtil_Test method testConvertTreeToJsonEmpty.

@Test
public void testConvertTreeToJsonEmpty() {
    String json = TreeItemUtil.convertTreeToJson(new TreeItemIdNode(null));
    Assert.assertEquals("Empty node - json should be emtpy", "{}", json);
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) Test(org.junit.Test)

Example 15 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class TreeItemUtil_Test method testConvertJsonToTreeBasic.

@Test
public void testConvertJsonToTreeBasic() {
    TreeItemIdNode root = TreeItemUtil.convertJsonToTree(MockTreeItemData.TEST_BASIC_JSON);
    Assert.assertNotNull("Root node not returned", root);
    Assert.assertEquals("Root should have one child", 1, root.getChildren().size());
    TreeItemIdNode node = root.getChildren().get(0);
    Assert.assertEquals("Incorrect node id", "A", node.getItemId());
    Assert.assertTrue("Node should have no children", node.getChildren().isEmpty());
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) Test(org.junit.Test)

Aggregations

TreeItemIdNode (com.github.bordertech.wcomponents.TreeItemIdNode)17 Test (org.junit.Test)8 JsonArray (com.google.gson.JsonArray)4 JsonObject (com.google.gson.JsonObject)4 WTree (com.github.bordertech.wcomponents.WTree)3 TreeItemModel (com.github.bordertech.wcomponents.TreeItemModel)2 HashSet (java.util.HashSet)2 TreeItemImage (com.github.bordertech.wcomponents.TreeItemImage)1 Gson (com.google.gson.Gson)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1