@Test public void testTransformTreeToJsonEmpty() throws Exception { final StringOutputStream stringOutputStream = new StringOutputStream(); final SoftVis3dJsonWriter jsonWriter = new SoftVis3dJsonWriter(stringOutputStream); final TreeNodeJsonWriter underTest = new TreeNodeJsonWriter(); final RootTreeNode tree = new RootTreeNode("1"); underTest.transformRootTreeToJson(jsonWriter, tree); jsonWriter.close(); final String expectedStringResult = "{\"treeResult\":{\"id\":\"1\",\"name\":\"root\",\"isNode\":false,\"children\":[]}}"; assertEquals(expectedStringResult, stringOutputStream.toString()); }
@Test public void testTransformWithChildrenNodes() { final StringOutputStream stringOutputStream = new StringOutputStream(); final SoftVis3dJsonWriter jsonWriter = new SoftVis3dJsonWriter(stringOutputStream); final TreeNodeJsonWriter underTest = new TreeNodeJsonWriter(); final RootTreeNode treeNode1 = new RootTreeNode("1"); TestTreeBuilder.createValueTreeNode("2", treeNode1, 1); TestTreeBuilder.createValueTreeNode("3", treeNode1, 2); underTest.transformRootTreeToJson(jsonWriter, treeNode1); jsonWriter.close(); final String expectedResult = "{\"treeResult\":{\"id\":\"1\",\"name\":\"root\",\"isNode\":true,\"children\":[{\"id\":\"2\",\"name\":\"2\",\"isNode\":false,\"heightMetricValue\":2.0,\"footprintMetricValue\":2.0,\"colorMetricValue\":2.0,\"parentInfo\":{\"id\":\"1\",\"name\":\"root\",\"isNode\":true,\"heightMetricValue\":2.0,\"footprintMetricValue\":2.0,\"colorMetricValue\":2.0},\"children\":[]},{\"id\":\"3\",\"name\":\"3\",\"isNode\":false,\"heightMetricValue\":2.0,\"footprintMetricValue\":2.0,\"colorMetricValue\":2.0,\"parentInfo\":{\"id\":\"1\",\"name\":\"root\",\"isNode\":true,\"heightMetricValue\":2.0,\"footprintMetricValue\":2.0,\"colorMetricValue\":2.0},\"children\":[]}]}}"; assertEquals(expectedResult, stringOutputStream.toString()); }