2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.features.sdnr.northbound.ranSlice;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
30 import java.io.InputStream;
32 import java.text.SimpleDateFormat;
33 import java.util.Date;
34 import java.util.Properties;
35 import java.util.concurrent.ExecutionException;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicLoader;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
42 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicClassResolver;
43 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProviderImpl;
44 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl;
45 import org.opendaylight.mdsal.binding.api.DataBroker;
46 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
47 import org.opendaylight.mdsal.binding.api.RpcProviderService;
48 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
49 /*import org.opendaylight.controller.md.sal.binding.api.DataBroker;
50 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
51 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
52 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
53 */import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200806.*;
54 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200806.common.header.CommonHeaderBuilder;
55 import org.opendaylight.yangtools.concepts.ObjectRegistration;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
59 public class RANSliceProviderTest {
61 Logger LOG = LoggerFactory.getLogger(RANSliceProvider.class);
62 private RANSliceProvider provider;
65 * @throws java.lang.Exception
68 public void setUp() throws Exception {
69 DataBroker dataBroker = mock(DataBroker.class);
70 DOMDataBroker domDataBroker = mock(DOMDataBroker.class);
71 NotificationPublishService notifyService = mock(NotificationPublishService.class);
72 //RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class);
73 RpcProviderService rpcRegistry = mock(RpcProviderService.class);
74 ObjectRegistration<RanSliceApiService> rpcRegistration = mock(ObjectRegistration.class);
75 when(rpcRegistry.registerRpcImplementation(any(Class.class), any(RanSliceApiService.class))).thenReturn(rpcRegistration);
78 // Load svclogic.properties and get a SvcLogicStore
79 InputStream propStr = RANSliceProviderTest.class.getResourceAsStream("/svclogic.properties");
80 Properties svcprops = new Properties();
81 svcprops.load(propStr);
83 SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops);
87 URL graphUrl = RANSliceProviderTest.class.getClassLoader().getResource("graphs");
88 LOG.info("Graph URL:" + graphUrl);
91 if (graphUrl == null) {
92 fail("Cannot find graphs directory");
95 SvcLogicLoader loader = new SvcLogicLoader(graphUrl.getPath(), store);
96 loader.loadAndActivate();
98 // Create a ServiceLogicService
99 SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl(),
100 new SvcLogicClassResolver());
102 // Finally ready to create sliapiProvider
103 RANSliceClient client = new RANSliceClient(svc);
104 provider = new RANSliceProvider();
105 provider.setDataBroker(dataBroker);
106 provider.setDomDataBroker(domDataBroker);
107 provider.setNotificationPublishService(notifyService);
108 provider.setClient(client);
115 * @throws java.lang.Exception
118 public void tearDown() throws Exception {
124 public void testConfigureNearRTRIC() {
125 ConfigureNearRTRICInputBuilder builder = new ConfigureNearRTRICInputBuilder();
127 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
128 hdrBuilder.setApiVer("1");
129 hdrBuilder.setFlags(null);
130 hdrBuilder.setOriginatorId("jUnit");
131 hdrBuilder.setRequestId("123");
132 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
133 builder.setCommonHeader(hdrBuilder.build());
135 builder.setAction(Action.Reconfigure);
138 ConfigureNearRTRICOutput results = provider.configureNearRTRIC(builder.build()).get().getResult();
139 LOG.info("configureNearRTRIC returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
140 assert(results.getStatus().getCode().intValue() == 400);
141 } catch (InterruptedException | ExecutionException e) {
142 LOG.error("Caught exception", e);
143 fail("configureNearRTRIC threw exception");
150 public void testInstantiateRANSlice() {
151 InstantiateRANSliceInputBuilder builder = new InstantiateRANSliceInputBuilder();
153 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
154 hdrBuilder.setApiVer("1");
155 hdrBuilder.setFlags(null);
156 hdrBuilder.setOriginatorId("jUnit");
157 hdrBuilder.setRequestId("123");
158 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
159 builder.setCommonHeader(hdrBuilder.build());
161 builder.setAction(Action.Reconfigure);
164 InstantiateRANSliceOutput results = provider.instantiateRANSlice(builder.build()).get().getResult();
165 LOG.info("instantiateRANSlice returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
166 assert(results.getStatus().getCode().intValue() == 400);
167 } catch (InterruptedException | ExecutionException e) {
168 LOG.error("Caught exception", e);
169 fail("instantiateRANSlice threw exception");
176 public void testConfigureRANSliceInstance() {
177 ConfigureRANSliceInstanceInputBuilder builder = new ConfigureRANSliceInstanceInputBuilder();
179 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
180 hdrBuilder.setApiVer("1");
181 hdrBuilder.setFlags(null);
182 hdrBuilder.setOriginatorId("jUnit");
183 hdrBuilder.setRequestId("123");
184 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
185 builder.setCommonHeader(hdrBuilder.build());
187 builder.setAction(Action.Reconfigure);
190 ConfigureRANSliceInstanceOutput results = provider.configureRANSliceInstance(builder.build()).get().getResult();
191 LOG.info("configureRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
192 assert(results.getStatus().getCode().intValue() == 400);
193 } catch (InterruptedException | ExecutionException e) {
194 LOG.error("Caught exception", e);
195 fail("configureRANSliceInstance threw exception");
201 public void testConfigureCU() {
202 ConfigureCUInputBuilder builder = new ConfigureCUInputBuilder();
204 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
205 hdrBuilder.setApiVer("1");
206 hdrBuilder.setFlags(null);
207 hdrBuilder.setOriginatorId("jUnit");
208 hdrBuilder.setRequestId("123");
209 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
210 builder.setCommonHeader(hdrBuilder.build());
212 builder.setAction(Action.Reconfigure);
215 ConfigureCUOutput results = provider.configureCU(builder.build()).get().getResult();
216 LOG.info("configureCU returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
217 assert(results.getStatus().getCode().intValue() == 400);
218 } catch (InterruptedException | ExecutionException e) {
219 LOG.error("Caught exception", e);
220 fail("configureCU threw exception");
227 public void testConfigureDU() {
228 ConfigureDUInputBuilder builder = new ConfigureDUInputBuilder();
230 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
231 hdrBuilder.setApiVer("1");
232 hdrBuilder.setFlags(null);
233 hdrBuilder.setOriginatorId("jUnit");
234 hdrBuilder.setRequestId("123");
235 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
236 builder.setCommonHeader(hdrBuilder.build());
238 builder.setAction(Action.Reconfigure);
241 ConfigureDUOutput results = provider.configureDU(builder.build()).get().getResult();
242 LOG.info("configureDU returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
243 assert(results.getStatus().getCode().intValue() == 400);
244 } catch (InterruptedException | ExecutionException e) {
245 LOG.error("Caught exception", e);
246 fail("configureDU threw exception");
252 public void testActivateRANSliceInstance() {
253 ActivateRANSliceInstanceInputBuilder builder = new ActivateRANSliceInstanceInputBuilder();
255 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
256 hdrBuilder.setApiVer("1");
257 hdrBuilder.setFlags(null);
258 hdrBuilder.setOriginatorId("jUnit");
259 hdrBuilder.setRequestId("123");
260 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
261 builder.setCommonHeader(hdrBuilder.build());
263 builder.setAction(Action.Reconfigure);
266 ActivateRANSliceInstanceOutput results = provider.activateRANSliceInstance(builder.build()).get().getResult();
267 LOG.info("activateRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
268 assert(results.getStatus().getCode().intValue() == 400);
269 } catch (InterruptedException | ExecutionException e) {
270 LOG.error("Caught exception", e);
271 fail("activateRANSliceInstance threw exception");
278 public void testDeactivateRANSliceInstance() {
279 DeactivateRANSliceInstanceInputBuilder builder = new DeactivateRANSliceInstanceInputBuilder();
281 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
282 hdrBuilder.setApiVer("1");
283 hdrBuilder.setFlags(null);
284 hdrBuilder.setOriginatorId("jUnit");
285 hdrBuilder.setRequestId("123");
286 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
287 builder.setCommonHeader(hdrBuilder.build());
289 builder.setAction(Action.Reconfigure);
292 DeactivateRANSliceInstanceOutput results = provider.deactivateRANSliceInstance(builder.build()).get().getResult();
293 LOG.info("deactivateRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
294 assert(results.getStatus().getCode().intValue() == 400);
295 } catch (InterruptedException | ExecutionException e) {
296 LOG.error("Caught exception", e);
297 fail("deactivateRANSliceInstance threw exception");
303 public void testTerminateRANSliceInstance() {
304 TerminateRANSliceInstanceInputBuilder builder = new TerminateRANSliceInstanceInputBuilder();
306 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
307 hdrBuilder.setApiVer("1");
308 hdrBuilder.setFlags(null);
309 hdrBuilder.setOriginatorId("jUnit");
310 hdrBuilder.setRequestId("123");
311 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
312 builder.setCommonHeader(hdrBuilder.build());
314 builder.setAction(Action.Reconfigure);
317 TerminateRANSliceInstanceOutput results = provider.terminateRANSliceInstance(builder.build()).get().getResult();
318 LOG.info("terminateRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
319 assert(results.getStatus().getCode().intValue() == 400);
320 } catch (InterruptedException | ExecutionException e) {
321 LOG.error("Caught exception", e);
322 fail("terminateRANSliceInstance threw exception");
328 public void testDetermineRANSliceResources() {
329 DetermineRANSliceResourcesInputBuilder builder = new DetermineRANSliceResourcesInputBuilder();
331 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
332 hdrBuilder.setApiVer("1");
333 hdrBuilder.setFlags(null);
334 hdrBuilder.setOriginatorId("jUnit");
335 hdrBuilder.setRequestId("123");
336 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
337 builder.setCommonHeader(hdrBuilder.build());
339 builder.setAction(Action.Reconfigure);
342 DetermineRANSliceResourcesOutput results = provider.determineRANSliceResources(builder.build()).get().getResult();
343 LOG.info("determineRANSliceResources returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
344 assert(results.getStatus().getCode().intValue() == 400);
345 } catch (InterruptedException | ExecutionException e) {
346 LOG.error("Caught exception", e);
347 fail("determineRANSliceResources threw exception");
354 public void testConfigNotification() {
355 ConfigNotificationInputBuilder builder = new ConfigNotificationInputBuilder();
357 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
358 hdrBuilder.setApiVer("1");
359 hdrBuilder.setFlags(null);
360 hdrBuilder.setOriginatorId("jUnit");
361 hdrBuilder.setRequestId("123");
362 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
363 builder.setCommonHeader(hdrBuilder.build());
365 builder.setAction(Action.Reconfigure);
368 ConfigNotificationOutput results = provider.configNotification(builder.build()).get().getResult();
369 LOG.info("configNotification returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
370 assert(results.getStatus().getCode().intValue() == 400);
371 } catch (InterruptedException | ExecutionException e) {
372 LOG.error("Caught exception", e);
373 fail("configNotification threw exception");