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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
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.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanToInternalDataModel;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
33 import org.opendaylight.yangtools.yang.common.Uint32;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class TestORanToInternalDataModel {
39 private static final Logger LOG = LoggerFactory.getLogger(TestORanToInternalDataModel.class);
41 NodeId nodeId = new NodeId("ORan-1000");
44 public void testInventory() {
45 String dateTimeString = "2020-02-05T12:30:45.283Z";
46 String name = "Slot-0";
48 Component testComponent = ComponentHelper.get(name, dateTimeString);
49 Optional<Inventory> oInventory = ORanToInternalDataModel.getInternalEquipment(nodeId, testComponent, 0);
51 assertTrue(oInventory.isPresent());
52 Inventory inventory = oInventory.get();
53 assertEquals(name, inventory.getUuid());
54 assertEquals(dateTimeString, inventory.getDate());
55 assertEquals(nodeId.getValue(), inventory.getNodeId());
59 public void testInventoryList() throws IOException, ClassNotFoundException {
60 List<Component> componentList = ComponentHelper.getComponentList("/Device-ietf-hardware-Output.json");
61 List<Inventory> inventoryList = ORanToInternalDataModel.getInventoryList(nodeId, componentList);
62 //componentList.forEach(System.out::println);
63 assertEquals("All elements", 27, inventoryList.size());
64 assertEquals("Fully parseable", componentList.size(), inventoryList.size());
65 assertEquals("Treelevel always there", 0,
66 inventoryList.stream().filter(inventory -> inventory.getTreeLevel() == null).count());
67 listAsTree(inventoryList);
70 private void listAsTree(List<Inventory> inventoryList) {
71 //Walk through complete list and print parameters
72 IntConsumer action = level -> IntStream.range(0, inventoryList.size())
73 .filter(idx -> inventoryList.get(idx).getTreeLevel().intValue() == level)
74 .forEach(idx2 -> printElements(idx2, level, inventoryList.get(idx2)));
75 //Walk trough 10 levels
76 IntStream.range(0, 10)
80 private void printElements(int idx2, int level, Inventory inventory) {
81 System.out.println(level + ": " + inventory.getParentUuid() + " "
82 + inventory.getUuid());
85 @SuppressWarnings("unused")
86 private boolean compareLevel(int idx, List<Component> componentList, List<Inventory> inventoryList) {
88 Integer relPos = componentList.get(idx).getParentRelPos();
90 Uint32 treeLevel = inventoryList.get(idx).getTreeLevel();
91 LOG.warn("Treelevel relPos: {} treeLevel: {}", relPos, treeLevel);
92 if (relPos != null && treeLevel != null) {
93 return relPos == treeLevel.intValue();