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.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;
 
  52 import org.slf4j.Logger;
 
  53 import org.slf4j.LoggerFactory;
 
  55 public class RANSliceProviderTest {
 
  57         Logger LOG = LoggerFactory.getLogger(RANSliceProvider.class);
 
  58         private RANSliceProvider provider;
 
  61        * @throws java.lang.Exception
 
  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);
 
  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);
 
  77           SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops);
 
  81           URL graphUrl = RANSliceProviderTest.class.getClassLoader().getResource("graphs");
 
  82           LOG.info("Graph URL:" + graphUrl);
 
  85           if (graphUrl == null) {
 
  86               fail("Cannot find graphs directory");
 
  89           SvcLogicLoader loader = new SvcLogicLoader(graphUrl.getPath(), store);
 
  90           loader.loadAndActivate();
 
  92           // Create a ServiceLogicService
 
  93           SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl(),
 
  94                                 new SvcLogicClassResolver());
 
  96           // Finally ready to create sliapiProvider
 
  97           RANSliceClient client = new RANSliceClient(svc);
 
  98           provider = new RANSliceProvider(dataBroker, notifyService, rpcRegistry, client);
 
 102        * @throws java.lang.Exception
 
 105       public void tearDown() throws Exception {
 
 111         public void testConfigureNearRTRIC() {
 
 112                 ConfigureNearRTRICInputBuilder builder = new ConfigureNearRTRICInputBuilder();
 
 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());
 
 122                 builder.setAction(Action.Reconfigure);
 
 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");
 
 137         public void testInstantiateRANSlice() {
 
 138                 InstantiateRANSliceInputBuilder builder = new InstantiateRANSliceInputBuilder();
 
 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());
 
 148                 builder.setAction(Action.Reconfigure);
 
 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");
 
 163         public void testConfigureRANSliceInstance() {
 
 164                 ConfigureRANSliceInstanceInputBuilder builder = new ConfigureRANSliceInstanceInputBuilder();
 
 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());
 
 174                 builder.setAction(Action.Reconfigure);
 
 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");
 
 188         public void testConfigureCU() {
 
 189                 ConfigureCUInputBuilder builder = new ConfigureCUInputBuilder();
 
 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());
 
 199                 builder.setAction(Action.Reconfigure);
 
 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");
 
 214         public void testConfigureDU() {
 
 215                 ConfigureDUInputBuilder builder = new ConfigureDUInputBuilder();
 
 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());
 
 225                 builder.setAction(Action.Reconfigure);
 
 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");
 
 239         public void testActivateRANSliceInstance() {
 
 240                 ActivateRANSliceInstanceInputBuilder builder = new ActivateRANSliceInstanceInputBuilder();
 
 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());
 
 250                 builder.setAction(Action.Reconfigure);
 
 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");
 
 265         public void testDeactivateRANSliceInstance() {
 
 266                 DeactivateRANSliceInstanceInputBuilder builder = new DeactivateRANSliceInstanceInputBuilder();
 
 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());
 
 276                 builder.setAction(Action.Reconfigure);
 
 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");
 
 290         public void testTerminateRANSliceInstance() {
 
 291                 TerminateRANSliceInstanceInputBuilder builder = new TerminateRANSliceInstanceInputBuilder();
 
 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());
 
 301                 builder.setAction(Action.Reconfigure);
 
 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");
 
 315         public void testDetermineRANSliceResources() {
 
 316                 DetermineRANSliceResourcesInputBuilder builder = new DetermineRANSliceResourcesInputBuilder();
 
 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());
 
 326                 builder.setAction(Action.Reconfigure);
 
 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");
 
 341         public void testConfigNotification() {
 
 342                 ConfigNotificationInputBuilder builder = new ConfigNotificationInputBuilder();
 
 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());
 
 352                 builder.setAction(Action.Reconfigure);
 
 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");