7fd94721184092d9cd4555933f533000d8318a8e
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 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.oran.impl.dom;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import com.google.common.io.Files;
29 import java.io.File;
30 import java.io.IOException;
31 import java.nio.charset.StandardCharsets;
32 import java.util.Optional;
33 import org.eclipse.jdt.annotation.NonNull;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.OnapSystem;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
45 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
46 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
47 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
48 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
49 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
50 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
51 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
53 import org.opendaylight.yangtools.yang.common.QName;
54 import org.opendaylight.yangtools.yang.common.QNameModule;
55 import org.opendaylight.yangtools.yang.common.Revision;
56 import org.opendaylight.yangtools.yang.common.XMLNamespace;
57
58 public class TestORanDOMNetworkElement {
59
60     private static final QName OneCell =
61             QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern();
62     private static final @NonNull QName OnapSystem1 =
63             QName.create("urn:onap:system", "2020-10-26", "onap-system").intern();
64     private static String NODEIDSTRING = "nSky";
65     private static NodeId nodeId = new NodeId(NODEIDSTRING);
66
67     private static NetconfAccessor accessor;
68     private static DeviceManagerServiceProvider serviceProvider;
69     private static Capabilities capabilities;
70     private static NetconfDomAccessor domAccessor;
71     private static VESCollectorService vesCollectorService;
72     private static NotificationProxyParser notificationProxyParser;
73     private static VESCollectorCfgService vesCfgService;
74     private static WebsocketManagerService websocketManagerService;
75     private static ORanDMConfig oranDmConfig;
76     private static ConfigurationFileRepresentation oranCfg;
77
78     private static String fileName = "test1.properties";
79     // @formatter:off
80     private static final String TESTCONFIG_CONTENT = "[ORAN-SUPERVISION]\n"
81             + "supervision-notification-interval=60\n"
82             + "guard-timer-overhead=10\n"
83             + "";
84     // @formatter:on
85
86     @BeforeClass
87     public static void init() throws InterruptedException, IOException {
88         capabilities = mock(Capabilities.class);
89         accessor = mock(NetconfAccessor.class);
90         serviceProvider = mock(DeviceManagerServiceProvider.class);
91         domAccessor = mock(NetconfDomAccessor.class);
92         vesCollectorService = mock(VESCollectorService.class);
93         notificationProxyParser = mock(NotificationProxyParser.class);
94         vesCfgService = mock(VESCollectorCfgService.class);
95         websocketManagerService = mock(WebsocketManagerService.class);
96         oranDmConfig = mock(ORanDMConfig.class);
97
98         when(accessor.getCapabilites()).thenReturn(capabilities);
99         when(accessor.getNodeId()).thenReturn(nodeId);
100         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
101         when(domAccessor.getNodeId()).thenReturn(nodeId);
102         when(domAccessor.getCapabilites()).thenReturn(capabilities);
103         when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser);
104         when(capabilities.isSupportingNamespaceAndRevision(
105                 QNameModule.create(XMLNamespace.of(ORANFM.NAMESPACE), Revision.of("2022-08-15")))).thenReturn(true);
106         when(capabilities.isSupportingNamespaceAndRevision(
107                 QNameModule.create(XMLNamespace.of(OnapSystem.NAMESPACE), Revision.of("2022-11-04")))).thenReturn(true);
108
109         DataProvider dataProvider = mock(DataProvider.class);
110         FaultService faultService = mock(FaultService.class);
111         when(serviceProvider.getWebsocketService()).thenReturn(websocketManagerService);
112         when(serviceProvider.getFaultService()).thenReturn(faultService);
113         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
114         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
115         when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
116         when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
117
118         Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
119         oranCfg = new ConfigurationFileRepresentation(fileName);
120     }
121
122     @Test
123     public void test() {
124         Optional<NetworkElement> oRanNe;
125         when(capabilities.isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
126         when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false);
127         when(capabilities.isSupportingNamespace(OnapSystem1)).thenReturn(false);
128
129         ORanNetworkElementFactory factory = new ORanNetworkElementFactory(oranCfg, oranDmConfig);
130         oRanNe = factory.create(accessor, serviceProvider);
131         assertTrue(factory.create(accessor, serviceProvider).isPresent());
132         oRanNe.get().register();
133         oRanNe.get().deregister();
134         oRanNe.get().getAcessor();
135         oRanNe.get().getDeviceType();
136         assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
137     }
138 }