Add bounds to sphinx requirement
[ccsdk/features.git] / sdnr / wt / devicemanager-o-ran-sc / o-ran / ru-fh / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / oran / impl / binding / TestORanToInternalDataModel.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import java.io.IOException;
23 import java.util.List;
24 import java.util.Optional;
25 import java.util.function.IntConsumer;
26 import java.util.stream.IntStream;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.junit.Test;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
32 import org.opendaylight.yangtools.yang.common.Uint32;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class TestORanToInternalDataModel {
37
38     private static final Logger LOG = LoggerFactory.getLogger(TestORanToInternalDataModel.class);
39
40     NodeId nodeId = new NodeId("ORan-1000");
41
42     @Test
43     public void testInventory() {
44         String dateTimeString = "2020-02-05T12:30:45.283Z";
45         String name = "Slot-0";
46
47         Component testComponent = ComponentHelper.get(name, dateTimeString);
48         Optional<Inventory> oInventory = ORanToInternalDataModel.getInternalEquipment(nodeId, testComponent, 0);
49
50         assertTrue(oInventory.isPresent());
51         Inventory inventory = oInventory.get();
52         assertEquals(name, inventory.getUuid());
53         assertEquals(dateTimeString, inventory.getDate());
54         assertEquals(nodeId.getValue(), inventory.getNodeId());
55     }
56
57     @Test
58     public void testInventoryList() throws IOException, ClassNotFoundException {
59         List<Component> componentList = ComponentHelper.getComponentList("/Device-ietf-hardware-Output.json");
60         List<Inventory> inventoryList = ORanToInternalDataModel.getInventoryList(nodeId, componentList);
61         //componentList.forEach(System.out::println);
62         assertEquals("All elements", 27, inventoryList.size());
63         assertEquals("Fully parseable", componentList.size(), inventoryList.size());
64         assertEquals("Treelevel always there", 0,
65                 inventoryList.stream().filter(inventory -> inventory.getTreeLevel() == null).count());
66         listAsTree(inventoryList);
67     }
68
69     private void listAsTree(List<Inventory> inventoryList) {
70         //Walk through complete list and print parameters
71         IntConsumer action = level -> IntStream.range(0, inventoryList.size())
72                 .filter(idx -> inventoryList.get(idx).getTreeLevel().intValue() == level)
73                 .forEach(idx2 -> printElements(idx2, level, inventoryList.get(idx2)));
74         //Walk trough 10 levels
75         IntStream.range(0, 10)
76                 .forEach(action);
77     }
78
79     private void printElements(int idx2, int level, Inventory inventory) {
80         System.out.println(level + ": " + inventory.getParentUuid() + " "
81                 + inventory.getUuid());
82     }
83
84     @SuppressWarnings("unused")
85     private boolean compareLevel(int idx, List<Component> componentList, List<Inventory> inventoryList) {
86         @Nullable
87         Integer relPos = componentList.get(idx).getParentRelPos();
88         @Nullable
89         Uint32 treeLevel = inventoryList.get(idx).getTreeLevel();
90         LOG.warn("Treelevel relPos: {} treeLevel: {}", relPos, treeLevel);
91         if (relPos != null && treeLevel != null) {
92             return relPos == treeLevel.intValue();
93         }
94         return false;
95     }
96 }