2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.northbound.cmnotify;
24 import org.junit.Before;
25 import org.junit.Test;
27 import org.opendaylight.mdsal.binding.api.DataBroker;
28 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
29 import org.opendaylight.mdsal.binding.api.RpcProviderService;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.opendaylight.yangtools.yang.common.Uint64;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import static org.junit.Assert.*;
36 import static org.mockito.Mockito.mock;
40 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput;
43 import com.google.common.util.concurrent.ListenableFuture;
47 public class TestCMNotify {
49 private CMNotifyProvider cMNotifyProvider;
50 private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class);
53 public void setUp() throws Exception {
54 if (null == cMNotifyProvider) {
55 DataBroker dataBroker = mock(DataBroker.class);
56 NotificationPublishService mockNotification = mock(NotificationPublishService.class);
57 RpcProviderService mockRpcRegistry = mock(RpcProviderService.class);
58 CMNotifyClient mockSliClient = mock(CMNotifyClient.class);
59 cMNotifyProvider = new CMNotifyProvider();
60 cMNotifyProvider.setDataBroker(dataBroker);
61 cMNotifyProvider.setNotificationPublishService(mockNotification);
62 cMNotifyProvider.setRpcProviderRegistry(mockRpcRegistry);
63 cMNotifyProvider.setClient(mockSliClient);
67 //Testcase should return error 503 when No service logic active for NbrlistChangeNotification
69 public void testNbrlistChangeNotification() {
71 NbrlistChangeNotificationInputBuilder inputBuilder = new NbrlistChangeNotificationInputBuilder();
73 inputBuilder.setFapServiceNumberOfEntriesChanged(Uint64.valueOf("1"));
75 // TODO: currently initialize SvcLogicServiceClient is failing, need to fix
76 ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider
77 .nbrlistChangeNotification(inputBuilder.build());
78 RpcResult<NbrlistChangeNotificationOutput> rpcResult = null;
80 rpcResult = future.get();
81 } catch (Exception e) {
84 LOG.info("result: {}", rpcResult);
85 assertEquals("503", rpcResult.getResult().getResponseCode());
88 //Input parameter validation
90 public void testvValidation() {
92 ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider
93 .nbrlistChangeNotification(null);
94 RpcResult<NbrlistChangeNotificationOutput> rpcResult = null;
96 rpcResult = future.get();
97 } catch (Exception e) {
100 LOG.info("result: {}", rpcResult);
101 assertEquals("Input is null", rpcResult.getResult().getResponseCode());