f062e51b68830cdd181b14ce4946025bea58ee36
[ccsdk/features.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                      reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.ccsdk.features.sdnr.northbound.cmnotify;
23
24 import org.junit.Before;
25 import org.junit.Test;
26
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.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import static org.junit.Assert.*;
35 import static org.mockito.Mockito.mock;
36
37 import java.math.*;
38
39 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder;
40 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput;
41
42 import com.google.common.util.concurrent.ListenableFuture;
43
44
45
46 public class TestCMNotify {
47
48     private CMNotifyProvider cMNotifyProvider;
49     private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class);
50
51     @Before
52     public void setUp() throws Exception {
53         if (null == cMNotifyProvider) {
54             DataBroker dataBroker = mock(DataBroker.class);
55             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
56             RpcProviderService mockRpcRegistry = mock(RpcProviderService.class);
57             CMNotifyClient mockSliClient = mock(CMNotifyClient.class);
58             cMNotifyProvider = new CMNotifyProvider();
59             cMNotifyProvider.setDataBroker(dataBroker);
60             cMNotifyProvider.setNotificationPublishService(mockNotification);
61             cMNotifyProvider.setRpcProviderRegistry(mockRpcRegistry);
62             cMNotifyProvider.setClient(mockSliClient);
63         }
64     }
65
66     //Testcase should return error 503 when No service logic active for NbrlistChangeNotification
67     @Test
68     public void testNbrlistChangeNotification() {
69
70         NbrlistChangeNotificationInputBuilder inputBuilder = new NbrlistChangeNotificationInputBuilder();
71
72         inputBuilder.setFapServiceNumberOfEntriesChanged(new BigInteger("1"));
73
74         // TODO: currently initialize SvcLogicServiceClient is failing, need to fix
75         ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider
76                                                                           .nbrlistChangeNotification(inputBuilder.build());
77         RpcResult<NbrlistChangeNotificationOutput> rpcResult = null;
78         try {
79             rpcResult = future.get();
80         } catch (Exception e) {
81             fail("Error : " + e);
82         }
83         LOG.info("result: {}", rpcResult);
84         assertEquals("503", rpcResult.getResult().getResponseCode());
85     }
86
87     //Input parameter validation
88     @Test
89     public void testvValidation() {
90
91         ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider
92                                                                                       .nbrlistChangeNotification(null);
93         RpcResult<NbrlistChangeNotificationOutput> rpcResult = null;
94         try {
95             rpcResult = future.get();
96         } catch (Exception e) {
97             fail("Error : " + e);
98         }
99         LOG.info("result: {}", rpcResult);
100         assertEquals("Input is null", rpcResult.getResult().getResponseCode());
101     }
102 }