22c9c11dda24ca1f6872bff28ba6e201ab7bec61
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import org.junit.Test;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmInventoryInput;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.OpenroadmVersionType;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.Interface;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.OrgOpenroadmDevice;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Info;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.InfoBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Xponder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.Shelves;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48 import org.opendaylight.yangtools.yang.common.Uint16;
49 import org.opendaylight.yangtools.yang.common.Uint32;
50 import org.opendaylight.yangtools.yang.common.Uint8;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 public class TestOpenRoadmInventory {
55     private static final Logger LOG = LoggerFactory.getLogger(OpenroadmInventoryInput.class);
56     private NetconfAccessor accessor = mock(NetconfAccessor.class);
57     private long value1 = 1;
58     private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11"));
59     private NodeId nodeId = new NodeId("RoadmA2");
60     private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB")
61             .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress)
62             .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20")))
63             .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm)
64             .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234")
65             .setPrefixLength(Uint8.valueOf(28)).setMaxDegrees(Uint16.valueOf(2)).setMaxSrgs(Uint16.valueOf(3))
66             .setMaxNumBin15minHistoricalPm(Uint16.valueOf(32)).setMaxNumBin24hourHistoricalPm(Uint16.valueOf(7))
67             .setOpenroadmVersion(OpenroadmVersionType._20).build();
68
69     private OrgOpenroadmDevice device = mock(OrgOpenroadmDevice.class);;
70     private Shelves shelf = mock(Shelves.class);
71     private Interface interfaces = mock(Interface.class);
72     private CircuitPacks cp = mock(CircuitPacks.class);
73     private Xponder xpdr = mock(Xponder.class);
74     OpenroadmInventoryInput roadmInventory = new OpenroadmInventoryInput(accessor, device);
75
76     @Test
77     public void TestDevice() {
78         when(accessor.getNodeId()).thenReturn(nodeId);
79         when(device.getInfo()).thenReturn(info);
80
81         roadmInventory.getInventoryData(Uint32.valueOf(value1));
82         assertEquals(info, device.getInfo());
83
84     }
85
86     @Test
87     public void TestShelves() {
88         when(accessor.getNodeId()).thenReturn(nodeId);
89         when(device.getInfo()).thenReturn(info);
90         when(shelf.getShelfPosition()).thenReturn("10");
91         when(shelf.getOperationalState()).thenReturn(State.InService);
92         when(shelf.getSerialId()).thenReturn("nodeid-1");
93         when(shelf.getShelfName()).thenReturn("Shelf1");
94         when(shelf.getShelfType()).thenReturn("Shelf");
95         when(shelf.getClei()).thenReturn("1234567890");
96         when(shelf.getVendor()).thenReturn("vendorA");
97         when(shelf.getModel()).thenReturn("1");
98         when(shelf.getHardwareVersion()).thenReturn("0.1");
99         when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
100         assertNotNull(roadmInventory.getShelvesInventory(shelf, Uint32.valueOf(value1 + 1)));
101
102         LOG.info("Shelves test completed");
103
104     }
105
106     @Test
107     public void TestCircuitPacks() {
108         when(accessor.getNodeId()).thenReturn(nodeId);
109         when(cp.getCircuitPackName()).thenReturn("1/0");
110         when(cp.getVendor()).thenReturn("VendorA");
111         when(cp.getModel()).thenReturn("Model1");
112         when(cp.getSerialId()).thenReturn("46277sgh6");
113         when(cp.getClei()).thenReturn("136268785");
114         when(cp.getHardwareVersion()).thenReturn("0.1");
115         when(cp.getType()).thenReturn("WSS");
116         when(cp.getProductCode()).thenReturn("oooooo");
117         when(cp.getCircuitPackMode()).thenReturn("inServiceMode");
118         when(device.getInfo()).thenReturn(info);
119         assertNotNull(roadmInventory.getCircuitPackInventory(cp, Uint32.valueOf(value1 + 1)));
120
121     }
122
123     @Test
124     public void TestInterfaces() {
125         when(accessor.getNodeId()).thenReturn(nodeId);
126         when(interfaces.getName()).thenReturn("1GE-interface-1");
127         when(interfaces.getDescription()).thenReturn("Ethernet Interface");
128         when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0");
129         when(device.getInfo()).thenReturn(info);
130         assertNotNull(roadmInventory.getInterfacesInventory(interfaces, Uint32.valueOf(value1 + 2)));
131     }
132
133     @Test
134     public void TestXponder() {
135         when(xpdr.getXpdrNumber()).thenReturn(Uint16.valueOf(1));
136         when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr);
137         when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed);
138         when(accessor.getNodeId()).thenReturn(nodeId);
139         when(device.getInfo()).thenReturn(info);
140         assertNotNull(roadmInventory.getXponderInventory(xpdr, Uint32.valueOf(value1 + 1)));
141
142     }
143
144 }