e0384e72bed581e17e50bc583c8f510322c3f9db
[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.onf14;
23
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.Optional;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14DomInterfacePacManager;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
39 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
40 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
41 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
42 import org.opendaylight.mdsal.dom.api.DOMNotification;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
44 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.AttributeValueChangedNotification;
45 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LAYERPROTOCOLNAMETYPEAIRLAYER;
46 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectCreationNotification;
47 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectDeletionNotification;
48 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ProblemNotification;
49 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
50 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
51 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPoint;
52 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointBuilder;
53 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointKey;
54 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocol;
55 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolBuilder;
56 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolKey;
57 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER;
58 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LAYERPROTOCOLNAMETYPEWIRELAYER;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
60
61 @RunWith(MockitoJUnitRunner.class)
62 public class TestOnf14DomInterfacePacManager {
63
64     private static String NODEIDSTRING = "nSky";
65
66     @Mock
67     NetconfDomAccessor netconfDomAccessor;
68     @Mock
69     DeviceManagerServiceProvider serviceProvider;
70     @Mock
71     ControlConstruct controlConstruct;
72     @Mock
73     BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer;
74     @Mock
75     FaultService faultService;
76     @Mock
77     WebsocketManagerService websocketService;
78     @Mock
79     DataProvider databaseService;
80
81     Onf14DomInterfacePacManager domPacManager;
82     NodeId nodeId = new NodeId(NODEIDSTRING);
83
84     @Before
85     public void init() {
86         when(netconfDomAccessor.getNodeId()).thenReturn(nodeId);
87         when(netconfDomAccessor.getBindingNormalizedNodeSerializer()).thenReturn(bindingNormalizedNodeSerializer);
88         when(serviceProvider.getFaultService()).thenReturn(faultService);
89         when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
90         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
91
92         domPacManager = new Onf14DomInterfacePacManager(netconfDomAccessor, serviceProvider);
93
94         UniversalId uuid = new UniversalId("0Aabcdef-0abc-0cfD-0abC-0123456789AB");
95         @NonNull Map<LogicalTerminationPointKey, LogicalTerminationPoint> lptMap = new HashMap<LogicalTerminationPointKey, LogicalTerminationPoint>();
96         var lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
97
98         LayerProtocol lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEAIRLAYER.class).setLocalId("TESTAIRLAYER").build();
99         LayerProtocolKey lpKey = new LayerProtocolKey("AIRPROTOCOL");
100         lpMap.put(lpKey, lp);
101         LogicalTerminationPoint ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
102         UniversalId ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789AB");
103         LogicalTerminationPointKey ltpKey = new LogicalTerminationPointKey(ltpUuid);
104
105         lptMap.put(ltpKey, ltp);
106
107         lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER.class).setLocalId("TESTETHCONTAINERLAYER").build();
108         lpKey = new LayerProtocolKey("ETHERNETCONTAINERPROTOCOL");
109         lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
110         lpMap.put(lpKey, lp);
111         ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
112         ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789BC");
113         ltpKey = new LogicalTerminationPointKey(ltpUuid);
114
115         lptMap.put(ltpKey, ltp);
116
117         lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEWIRELAYER.class).setLocalId("TESTWIRELAYER").build();
118         lpKey = new LayerProtocolKey("WIREPROTOCOL");
119         lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
120         lpMap.put(lpKey, lp);
121         ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
122         ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789CD");
123         ltpKey = new LogicalTerminationPointKey(ltpUuid);
124
125         lptMap.put(ltpKey, ltp);
126
127         when(Optional.of(controlConstruct).get().nonnullLogicalTerminationPoint()).thenReturn(lptMap);
128     }
129
130     @Test
131     public void test() {
132         domPacManager.readKeys(controlConstruct);
133     }
134
135     @Test
136     public void testProblemNotification() {
137         DOMNotification domNotif = mock(DOMNotification.class);
138         ProblemNotification problemNotif = mock(ProblemNotification.class);
139         when(bindingNormalizedNodeSerializer.fromNormalizedNodeNotification(domNotif.getType(), domNotif.getBody())).thenReturn(problemNotif);
140         when(problemNotif.getCounter()).thenReturn(10);
141         when(problemNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
142         when(problemNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
143         when(problemNotif.getProblem()).thenReturn("modulationIsDownShifted");
144
145         domPacManager.onNotification(domNotif);
146     }
147
148     @Test
149     public void testAVCNotification() {
150         DOMNotification domNotif = mock(DOMNotification.class);
151         AttributeValueChangedNotification attrValChangedNotif = mock(AttributeValueChangedNotification.class);
152         when(bindingNormalizedNodeSerializer.fromNormalizedNodeNotification(domNotif.getType(), domNotif.getBody())).thenReturn(attrValChangedNotif);
153         when(attrValChangedNotif.getAttributeName()).thenReturn("12345678-0123-2345-abcd-0123456789AB");
154         when(attrValChangedNotif.getCounter()).thenReturn(20);
155         when(attrValChangedNotif.getNewValue()).thenReturn("new-value");
156         when(attrValChangedNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
157         when(attrValChangedNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
158         domPacManager.onNotification(domNotif);
159     }
160
161     @Test
162     public void testObjectDeletionNotification() {
163         DOMNotification domNotif = mock(DOMNotification.class);
164         ObjectDeletionNotification deletionNotif = mock(ObjectDeletionNotification.class);
165         when(bindingNormalizedNodeSerializer.fromNormalizedNodeNotification(domNotif.getType(), domNotif.getBody())).thenReturn(deletionNotif);
166         when(deletionNotif.getCounter()).thenReturn(20);
167         when(deletionNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
168         when(deletionNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
169         domPacManager.onNotification(domNotif);
170     }
171
172     @Test
173     public void testObjectCreationNotification() {
174         DOMNotification domNotif = mock(DOMNotification.class);
175         ObjectCreationNotification creationNotif = mock(ObjectCreationNotification.class);
176         when(bindingNormalizedNodeSerializer.fromNormalizedNodeNotification(domNotif.getType(), domNotif.getBody())).thenReturn(creationNotif);
177         when(creationNotif.getObjectType()).thenReturn("air-interface-name");
178         when(creationNotif.getCounter()).thenReturn(20);
179         when(creationNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
180         when(creationNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
181         domPacManager.onNotification(domNotif);
182     }
183
184 }