use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testTreeExpandedRecursive.
@Test
public void testTreeExpandedRecursive() throws Exception {
// (root)
// +-(node)
// | +-(node)
// | | +-(node)
// | | +-(node)
// | +-(node)
// +-(node)
// | +-(node)
// +-(node)
List<ITreeNode> nodes = new ArrayList<ITreeNode>();
nodes.add(new TreeNode());
nodes.add(new TreeNode());
nodes.add(new TreeNode());
ITree tree = createTree(nodes);
tree.addChildNode(tree.getRootNode().getChildNode(0), new TreeNode());
tree.addChildNode(tree.getRootNode().getChildNode(0), new TreeNode());
tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
tree.addChildNode(tree.getRootNode().getChildNode(1), new TreeNode());
IJsonAdapter<? super ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
m_uiSession.currentJsonResponse().addAdapter(jsonTree);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
System.out.println("Response #1: " + response);
JsonTestUtility.endRequest(m_uiSession);
// --------------------------------------
tree.expandAll(tree.getRootNode());
response = m_uiSession.currentJsonResponse().toJson();
System.out.println("Response #2: " + response);
List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
assertEquals(3, events.size());
assertEquals("nodeExpanded", events.get(0).getType());
assertEquals(true, events.get(0).getData().optBoolean("expanded"));
assertEquals(true, events.get(0).getData().optBoolean("recursive"));
assertEquals("nodeExpanded", events.get(1).getType());
assertEquals(true, events.get(1).getData().optBoolean("expanded"));
assertEquals(true, events.get(1).getData().optBoolean("recursive"));
assertEquals("nodeExpanded", events.get(2).getType());
assertEquals(true, events.get(2).getData().optBoolean("expanded"));
assertEquals(true, events.get(2).getData().optBoolean("recursive"));
JsonTestUtility.endRequest(m_uiSession);
// --------------------------------------
tree.collapseAll(tree.getRootNode().getChildNode(0));
response = m_uiSession.currentJsonResponse().toJson();
System.out.println("Response #3: " + response);
events = m_uiSession.currentJsonResponse().getEventList();
assertEquals(1, events.size());
assertEquals("nodeExpanded", events.get(0).getType());
assertEquals(false, events.get(0).getData().optBoolean("expanded"));
assertEquals(true, events.get(0).getData().optBoolean("recursive"));
}
use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testNodesDeletedEvent.
/**
* Tests whether a deletion event with correct node id gets sent whenever a node gets deleted.
*/
@Test
public void testNodesDeletedEvent() throws JSONException {
List<ITreeNode> nodes = new ArrayList<ITreeNode>();
nodes.add(new TreeNode());
nodes.add(new TreeNode());
nodes.add(new TreeNode());
ITree tree = createTree(nodes);
JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
String node1Id = jsonTree.getOrCreateNodeId(nodes.get(1));
tree.removeNode(nodes.get(1));
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_DELETED);
assertTrue(responseEvents.size() == 1);
assertEventTypeAndNodeIds(responseEvents.get(0), "nodesDeleted", node1Id);
}
use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testGetVsOpt.
@Test
public void testGetVsOpt() {
List<ITreeNode> nodes = new ArrayList<ITreeNode>();
nodes.add(new TreeNode());
nodes.add(new TreeNode());
nodes.add(new TreeNode());
ITree tree = createTree(nodes);
JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
String node0Id = jsonTree.getOrCreateNodeId(nodes.get(0));
assertNotNull(node0Id);
assertEquals(node0Id, jsonTree.optNodeId(nodes.get(0)));
assertEquals(node0Id, jsonTree.getNodeId(nodes.get(0)));
assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
assertNotNull(jsonTree.getTreeNodeForNodeId(node0Id));
String nonExistingNodeId = "bla";
ITreeNode nonExistingTreeNode = new TreeNode();
assertNull(jsonTree.optNodeId(nonExistingTreeNode));
try {
jsonTree.getNodeId(nonExistingTreeNode);
fail("Expected UiException");
} catch (UiException e) {
// ok
}
assertNull(jsonTree.optTreeNodeForNodeId(nonExistingNodeId));
try {
jsonTree.getTreeNodeForNodeId(nonExistingNodeId);
fail("Expected UiException");
} catch (UiException e) {
// ok
}
}
Aggregations