f1e1524ecb1286e32f7afbc6ab5c37e916d30b06
[ccsdk/features.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.features.sdnr.northbound.ranSlice;
22
23
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;
29
30 import java.io.InputStream;
31 import java.net.URL;
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.controller.md.sal.binding.api.DataBroker;
46 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
47 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
48 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
49 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200806.*;
50 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200806.common.header.CommonHeaderBuilder;
51
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class RANSliceProviderTest {
56
57         Logger LOG = LoggerFactory.getLogger(RANSliceProvider.class);
58         private RANSliceProvider provider;
59
60       /**
61        * @throws java.lang.Exception
62        */
63       @Before
64       public void setUp() throws Exception {
65           DataBroker dataBroker = mock(DataBroker.class);
66           NotificationPublishService notifyService = mock(NotificationPublishService.class);
67           RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class);
68           BindingAwareBroker.RpcRegistration<RanSliceApiService> rpcRegistration = (BindingAwareBroker.RpcRegistration<RanSliceApiService>) mock(BindingAwareBroker.RpcRegistration.class);
69           when(rpcRegistry.addRpcImplementation(any(Class.class), any(RanSliceApiService.class))).thenReturn(rpcRegistration);
70
71
72           // Load svclogic.properties and get a SvcLogicStore
73           InputStream propStr = RANSliceProviderTest.class.getResourceAsStream("/svclogic.properties");
74           Properties svcprops = new Properties();
75           svcprops.load(propStr);
76
77           SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops);
78
79           assertNotNull(store);
80
81           URL graphUrl = RANSliceProviderTest.class.getClassLoader().getResource("graphs");
82           LOG.info("Graph URL:" + graphUrl);
83
84
85           if (graphUrl == null) {
86               fail("Cannot find graphs directory");
87           }
88
89           SvcLogicLoader loader = new SvcLogicLoader(graphUrl.getPath(), store);
90           loader.loadAndActivate();
91
92           // Create a ServiceLogicService
93           SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl(),
94                                 new SvcLogicClassResolver());
95
96           // Finally ready to create sliapiProvider
97           RANSliceClient client = new RANSliceClient(svc);
98           provider = new RANSliceProvider(dataBroker, notifyService, rpcRegistry, client);
99       }
100
101       /**
102        * @throws java.lang.Exception
103        */
104       @After
105       public void tearDown() throws Exception {
106           provider.close();
107       }
108
109
110         @Test
111         public void testConfigureNearRTRIC() {
112                 ConfigureNearRTRICInputBuilder builder = new ConfigureNearRTRICInputBuilder();
113
114                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
115                 hdrBuilder.setApiVer("1");
116                 hdrBuilder.setFlags(null);
117                 hdrBuilder.setOriginatorId("jUnit");
118                 hdrBuilder.setRequestId("123");
119                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
120                 builder.setCommonHeader(hdrBuilder.build());
121
122                 builder.setAction(Action.Reconfigure);
123
124                 try {
125                         ConfigureNearRTRICOutput results = provider.configureNearRTRIC(builder.build()).get().getResult();
126                         LOG.info("configureNearRTRIC returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
127                         assert(results.getStatus().getCode() == 400);
128                 } catch (InterruptedException | ExecutionException e) {
129                         LOG.error("Caught exception", e);
130                         fail("configureNearRTRIC threw exception");
131                 }
132
133         }
134
135
136     @Test
137         public void testInstantiateRANSlice() {
138                 InstantiateRANSliceInputBuilder builder = new InstantiateRANSliceInputBuilder();
139
140                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
141                 hdrBuilder.setApiVer("1");
142                 hdrBuilder.setFlags(null);
143                 hdrBuilder.setOriginatorId("jUnit");
144                 hdrBuilder.setRequestId("123");
145                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
146                 builder.setCommonHeader(hdrBuilder.build());
147
148                 builder.setAction(Action.Reconfigure);
149
150                 try {
151                         InstantiateRANSliceOutput results = provider.instantiateRANSlice(builder.build()).get().getResult();
152                         LOG.info("instantiateRANSlice returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
153                         assert(results.getStatus().getCode() == 400);
154                 } catch (InterruptedException | ExecutionException e) {
155                         LOG.error("Caught exception", e);
156                         fail("instantiateRANSlice threw exception");
157                 }
158
159         }
160
161
162     @Test
163         public void testConfigureRANSliceInstance() {
164                 ConfigureRANSliceInstanceInputBuilder builder = new ConfigureRANSliceInstanceInputBuilder();
165
166                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
167                 hdrBuilder.setApiVer("1");
168                 hdrBuilder.setFlags(null);
169                 hdrBuilder.setOriginatorId("jUnit");
170                 hdrBuilder.setRequestId("123");
171                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
172                 builder.setCommonHeader(hdrBuilder.build());
173
174                 builder.setAction(Action.Reconfigure);
175
176                 try {
177                         ConfigureRANSliceInstanceOutput results = provider.configureRANSliceInstance(builder.build()).get().getResult();
178                         LOG.info("configureRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
179                         assert(results.getStatus().getCode() == 400);
180                 } catch (InterruptedException | ExecutionException e) {
181                         LOG.error("Caught exception", e);
182                         fail("configureRANSliceInstance threw exception");
183                 }
184
185         }
186
187     @Test
188         public void testConfigureCU() {
189                 ConfigureCUInputBuilder builder = new ConfigureCUInputBuilder();
190
191                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
192                 hdrBuilder.setApiVer("1");
193                 hdrBuilder.setFlags(null);
194                 hdrBuilder.setOriginatorId("jUnit");
195                 hdrBuilder.setRequestId("123");
196                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
197                 builder.setCommonHeader(hdrBuilder.build());
198
199                 builder.setAction(Action.Reconfigure);
200
201                 try {
202                         ConfigureCUOutput results = provider.configureCU(builder.build()).get().getResult();
203                         LOG.info("configureCU returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
204                         assert(results.getStatus().getCode() == 400);
205                 } catch (InterruptedException | ExecutionException e) {
206                         LOG.error("Caught exception", e);
207                         fail("configureCU threw exception");
208                 }
209
210         }
211
212
213     @Test
214         public void testConfigureDU() {
215                 ConfigureDUInputBuilder builder = new ConfigureDUInputBuilder();
216
217                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
218                 hdrBuilder.setApiVer("1");
219                 hdrBuilder.setFlags(null);
220                 hdrBuilder.setOriginatorId("jUnit");
221                 hdrBuilder.setRequestId("123");
222                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
223                 builder.setCommonHeader(hdrBuilder.build());
224
225                 builder.setAction(Action.Reconfigure);
226
227                 try {
228                         ConfigureDUOutput results = provider.configureDU(builder.build()).get().getResult();
229                         LOG.info("configureDU returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
230                         assert(results.getStatus().getCode() == 400);
231                 } catch (InterruptedException | ExecutionException e) {
232                         LOG.error("Caught exception", e);
233                         fail("configureDU threw exception");
234                 }
235
236         }
237
238     @Test
239         public void testActivateRANSliceInstance() {
240                 ActivateRANSliceInstanceInputBuilder builder = new ActivateRANSliceInstanceInputBuilder();
241
242                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
243                 hdrBuilder.setApiVer("1");
244                 hdrBuilder.setFlags(null);
245                 hdrBuilder.setOriginatorId("jUnit");
246                 hdrBuilder.setRequestId("123");
247                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
248                 builder.setCommonHeader(hdrBuilder.build());
249
250                 builder.setAction(Action.Reconfigure);
251
252                 try {
253                         ActivateRANSliceInstanceOutput results = provider.activateRANSliceInstance(builder.build()).get().getResult();
254                         LOG.info("activateRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
255                         assert(results.getStatus().getCode() == 400);
256                 } catch (InterruptedException | ExecutionException e) {
257                         LOG.error("Caught exception", e);
258                         fail("activateRANSliceInstance threw exception");
259                 }
260
261         }
262
263
264     @Test
265         public void testDeactivateRANSliceInstance() {
266                 DeactivateRANSliceInstanceInputBuilder builder = new DeactivateRANSliceInstanceInputBuilder();
267
268                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
269                 hdrBuilder.setApiVer("1");
270                 hdrBuilder.setFlags(null);
271                 hdrBuilder.setOriginatorId("jUnit");
272                 hdrBuilder.setRequestId("123");
273                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
274                 builder.setCommonHeader(hdrBuilder.build());
275
276                 builder.setAction(Action.Reconfigure);
277
278                 try {
279                         DeactivateRANSliceInstanceOutput results = provider.deactivateRANSliceInstance(builder.build()).get().getResult();
280                         LOG.info("deactivateRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
281                         assert(results.getStatus().getCode() == 400);
282                 } catch (InterruptedException | ExecutionException e) {
283                         LOG.error("Caught exception", e);
284                         fail("deactivateRANSliceInstance threw exception");
285                 }
286
287         }
288
289     @Test
290         public void testTerminateRANSliceInstance() {
291                 TerminateRANSliceInstanceInputBuilder builder = new TerminateRANSliceInstanceInputBuilder();
292
293                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
294                 hdrBuilder.setApiVer("1");
295                 hdrBuilder.setFlags(null);
296                 hdrBuilder.setOriginatorId("jUnit");
297                 hdrBuilder.setRequestId("123");
298                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
299                 builder.setCommonHeader(hdrBuilder.build());
300
301                 builder.setAction(Action.Reconfigure);
302
303                 try {
304                         TerminateRANSliceInstanceOutput results = provider.terminateRANSliceInstance(builder.build()).get().getResult();
305                         LOG.info("terminateRANSliceInstance returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
306                         assert(results.getStatus().getCode() == 400);
307                 } catch (InterruptedException | ExecutionException e) {
308                         LOG.error("Caught exception", e);
309                         fail("terminateRANSliceInstance threw exception");
310                 }
311
312         }
313
314     @Test
315         public void testDetermineRANSliceResources() {
316                 DetermineRANSliceResourcesInputBuilder builder = new DetermineRANSliceResourcesInputBuilder();
317
318                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
319                 hdrBuilder.setApiVer("1");
320                 hdrBuilder.setFlags(null);
321                 hdrBuilder.setOriginatorId("jUnit");
322                 hdrBuilder.setRequestId("123");
323                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
324                 builder.setCommonHeader(hdrBuilder.build());
325
326                 builder.setAction(Action.Reconfigure);
327
328                 try {
329                         DetermineRANSliceResourcesOutput results = provider.determineRANSliceResources(builder.build()).get().getResult();
330                         LOG.info("determineRANSliceResources returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
331                         assert(results.getStatus().getCode() == 400);
332                 } catch (InterruptedException | ExecutionException e) {
333                         LOG.error("Caught exception", e);
334                         fail("determineRANSliceResources threw exception");
335                 }
336
337         }
338
339
340     @Test
341         public void testConfigNotification() {
342                 ConfigNotificationInputBuilder builder = new ConfigNotificationInputBuilder();
343
344                 CommonHeaderBuilder hdrBuilder = new CommonHeaderBuilder();
345                 hdrBuilder.setApiVer("1");
346                 hdrBuilder.setFlags(null);
347                 hdrBuilder.setOriginatorId("jUnit");
348                 hdrBuilder.setRequestId("123");
349                 hdrBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date())));
350                 builder.setCommonHeader(hdrBuilder.build());
351
352                 builder.setAction(Action.Reconfigure);
353
354                 try {
355                         ConfigNotificationOutput results = provider.configNotification(builder.build()).get().getResult();
356                         LOG.info("configNotification returned status {} : {}", results.getStatus().getCode(), results.getStatus().getMessage());
357                         assert(results.getStatus().getCode() == 400);
358                 } catch (InterruptedException | ExecutionException e) {
359                         LOG.error("Caught exception", e);
360                         fail("configNotification threw exception");
361                 }
362
363         }
364
365
366   }