cad0994ccaa5014f61be69c7f8518f424a81c078
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2021 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.dom;
19
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23 import com.google.common.io.Files;
24 import java.io.File;
25 import java.io.IOException;
26 import java.nio.charset.StandardCharsets;
27 import java.util.Optional;
28 import org.junit.After;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.OnapSystem;
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.devicemanager.service.VESCollectorService;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
41 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
42 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
43 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
45 import org.opendaylight.yangtools.yang.common.QNameModule;
46 import org.opendaylight.yangtools.yang.common.Revision;
47 import org.opendaylight.yangtools.yang.common.XMLNamespace;
48
49 public class TestORanNetworkElementFactory {
50
51     private static String NODEIDSTRING = "nSky";
52
53     private static NetconfAccessor accessor;
54     private static NetconfDomAccessor domAccessor;
55     private static DeviceManagerServiceProvider serviceProvider;
56     private static Capabilities capabilities;
57     private static VESCollectorService vesCollectorService;
58     private static FaultService faultService;
59     private static WebsocketManagerService notificationService;
60     private static DataProvider databaseService;
61     private static ORanDMConfig oranDmConfig;
62     private static ConfigurationFileRepresentation oranCfg;
63     private static NodeId nodeId = new NodeId(NODEIDSTRING);
64
65     private static String fileName = "test1.properties";
66     // @formatter:off
67     private static final String TESTCONFIG_CONTENT = "[ORAN-SUPERVISION]\n"
68             + "supervision-notification-interval=60\n"
69             + "guard-timer-overhead=10\n"
70             + "";
71     // @formatter:on
72
73
74     @BeforeClass
75     public static void init() throws InterruptedException, IOException {
76         accessor = mock(NetconfAccessor.class);
77         domAccessor = mock(NetconfDomAccessor.class);
78         capabilities = mock(Capabilities.class);
79         serviceProvider = mock(DeviceManagerServiceProvider.class);
80         vesCollectorService = mock(VESCollectorService.class);
81         faultService = mock(FaultService.class);
82         notificationService = mock(WebsocketManagerService.class);
83         databaseService = mock(DataProvider.class);
84         oranDmConfig = mock(ORanDMConfig.class);
85
86         when(domAccessor.getCapabilites()).thenReturn(capabilities);
87         when(domAccessor.getNodeId()).thenReturn(nodeId);
88         when(accessor.getCapabilites()).thenReturn(capabilities);
89         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
90         when(serviceProvider.getFaultService()).thenReturn(faultService);
91         when(serviceProvider.getWebsocketService()).thenReturn(notificationService);
92         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
93         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
94         when(capabilities.isSupportingNamespaceAndRevision(
95                 QNameModule.create(XMLNamespace.of(ORANFM.NAMESPACE), Revision.of("2022-08-15")))).thenReturn(true);
96         when(capabilities.isSupportingNamespaceAndRevision(
97                 QNameModule.create(XMLNamespace.of(OnapSystem.NAMESPACE), Revision.of("2022-11-04")))).thenReturn(true);
98         Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
99         oranCfg = new ConfigurationFileRepresentation(fileName);
100
101     }
102
103     @Test
104     public void testCreateORANHWComponent() throws Exception {
105         when(domAccessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
106         ORanNetworkElementFactory factory = new ORanNetworkElementFactory(oranCfg, oranDmConfig);
107         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
108     }
109
110     @Test
111     public void testCreateNone() throws Exception {
112         when(domAccessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(false);
113         ORanNetworkElementFactory factory = new ORanNetworkElementFactory(oranCfg, oranDmConfig);
114         assertTrue(!(factory.create(accessor, serviceProvider).isPresent()));
115     }
116
117     @After
118     public void cleanUp() throws Exception {
119         File file = new File(fileName);
120         if (file.exists()) {
121             System.out.println("File exists, Deleting it");
122             file.delete();
123         }
124
125     }
126 }
127