7a664eef185094ffdfb31fba21538439d78f1a32
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.v3po.translate.util.read.registry;
18
19 import static org.hamcrest.CoreMatchers.hasItem;
20 import static org.hamcrest.CoreMatchers.hasItems;
21 import static org.hamcrest.CoreMatchers.is;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertThat;
24 import static org.junit.Assert.assertTrue;
25
26 import com.google.common.collect.Sets;
27 import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject1;
28 import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject3;
29 import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject4;
30 import org.junit.Test;
31
32 public class TypeHierarchyTest {
33
34     @Test
35     public void testHierarchy() throws Exception {
36         final TypeHierarchy typeHierarchy = TypeHierarchy.create(Sets.newHashSet(
37                 DataObject4.DataObject41.DataObject411.IID,
38                 DataObject4.DataObject41.IID,/* Included in previous already */
39                 DataObject1.IID,
40                 DataObject3.DataObject31.IID));
41
42         // Roots
43         assertThat(typeHierarchy.getRoots().size(), is(3));
44         assertThat(typeHierarchy.getRoots(), hasItems(DataObject1.IID, DataObject3.IID, DataObject4.IID));
45
46         // Leaves
47         assertThat(typeHierarchy.getDirectChildren(DataObject1.IID).size(), is(0));
48         assertThat(typeHierarchy.getDirectChildren(DataObject3.DataObject31.IID).size(), is(0));
49         assertThat(typeHierarchy.getDirectChildren(DataObject4.DataObject41.DataObject411.IID).size(), is(0));
50
51         // Intermediate leaves
52         assertThat(typeHierarchy.getDirectChildren(DataObject3.IID).size(), is(1));
53         assertThat(typeHierarchy.getDirectChildren(DataObject3.IID), hasItem(DataObject3.DataObject31.IID));
54         assertEquals(typeHierarchy.getDirectChildren(DataObject3.IID), typeHierarchy.getAllChildren(DataObject3.IID));
55
56         assertThat(typeHierarchy.getDirectChildren(DataObject4.DataObject41.IID).size(), is(1));
57         assertThat(typeHierarchy.getDirectChildren(DataObject4.DataObject41.IID), hasItem(
58                 DataObject4.DataObject41.DataObject411.IID));
59         assertEquals(typeHierarchy.getDirectChildren(DataObject4.DataObject41.IID), typeHierarchy.getAllChildren(
60                 DataObject4.DataObject41.IID));
61
62         assertThat(typeHierarchy.getDirectChildren(DataObject4.IID).size(), is(1));
63         assertThat(typeHierarchy.getDirectChildren(DataObject4.IID), hasItem(DataObject4.DataObject41.IID));
64         assertThat(typeHierarchy.getAllChildren(DataObject4.IID).size(), is(2));
65         assertTrue(typeHierarchy.getAllChildren(DataObject4.IID).contains(DataObject4.DataObject41.IID));
66         assertTrue(typeHierarchy.getAllChildren(DataObject4.IID).contains(DataObject4.DataObject41.DataObject411.IID));
67     }
68 }
69