2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.utils;
23 import com.google.common.collect.ImmutableList;
24 import org.jetbrains.annotations.NotNull;
25 import org.testng.annotations.DataProvider;
26 import org.testng.annotations.Test;
28 import java.util.List;
30 import static org.junit.Assert.assertFalse;
31 import static org.testng.Assert.*;
33 public class TreeTest {
36 protected Tree<String> buildTreeForTest() {
37 Tree<String> tree = new Tree<>("a");
38 tree.addPath("b","c","d");
39 tree.addPath("b","cc","dd");
40 tree.addPath("1","2","dd");
45 public static Object[][] pathsToFind() {
46 return new Object[][]{
47 {ImmutableList.of("b","c","d"), true},
48 {ImmutableList.of("b","c"), true},
49 {ImmutableList.of("b","cc","dd"), true},
50 {ImmutableList.of("b","cc","d"), false},
51 {ImmutableList.of("1","2","dd"), true},
52 {ImmutableList.of("b"), true},
53 {ImmutableList.of("c"), false},
54 {ImmutableList.of("z", "z", "z", "z", "z"), false},
58 @Test(dataProvider="pathsToFind")
59 public void whenBuildTree_nodesFoundsInRoute(List<String> path, boolean isFound) {
60 Tree<String> tree = buildTreeForTest();
61 assertEquals(isFound, tree.isPathExist(path));
64 @Test(dataProvider="pathsToFind")
65 public void whenBuildTree_subTreeGetRight(List<String> path, boolean isFound) {
66 Tree<String> tree = buildTreeForTest();
68 assertNotNull(tree.getSubTree(path));
71 assertNull(tree.getSubTree(path));
76 public void whenBuildTree_getSubTreeAsExpected() {
77 Tree<String> tree = buildTreeForTest();
78 Tree<String> subTree = tree.getSubTree("b","c");
79 assertEquals(subTree.getRootValue(), "c");
80 assertTrue(subTree.isPathExist("d"));
81 assertFalse(subTree.isPathExist("b","c","d"));
85 public void getChildrenDepthTest() {
86 Tree<String> tree = buildTreeForTest();
87 assertEquals(3, tree.getChildrenDepth());
88 Tree<String> subTree = tree.getSubTree("b");
89 assertEquals(2, subTree.getChildrenDepth());