ORAN CMNotify Karaf Feature Development
[ccsdk/features.git] / sdnr / northbound / CMNotify / provider / src / test / java / org / onap / ccsdk / features / sdnr / northbound / CMNotify / TestCMNotify.java
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.onap.ccsdk.features.sdnr.northbound.CMNotify.CMNotifyClient;
28 import org.onap.ccsdk.features.sdnr.northbound.CMNotify.CMNotifyProvider;
29
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
32 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
33 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
34
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 import static org.junit.Assert.*;
40 import static org.mockito.Mockito.mock;
41
42 import java.math.*;
43
44 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInput;
45 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder;
46 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput;
47 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutputBuilder;
48
49 import com.google.common.util.concurrent.ListenableFuture;
50
51
52
53 public class TestCMNotify extends AbstractConcurrentDataBrokerTest {
54
55     private CMNotifyProvider cMNotifyProvider;
56     private static final Logger LOG = LoggerFactory.getLogger(CMNotifyProvider.class);
57
58     @Before
59     public void setUp() throws Exception {
60         if (null == cMNotifyProvider) {
61             DataBroker dataBroker = getDataBroker();
62             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
63             RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class);
64             CMNotifyClient mockSliClient = mock(CMNotifyClient.class);
65             cMNotifyProvider = new CMNotifyProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient);
66         }
67     }
68
69     //Testcase should return error 503 when No service logic active for NbrlistChangeNotification
70     @Test
71     public void testNbrlistChangeNotification() {
72
73         NbrlistChangeNotificationInputBuilder inputBuilder = new NbrlistChangeNotificationInputBuilder();
74
75         inputBuilder.setFapServiceNumberOfEntriesChanged(new BigInteger("1"));
76
77         // TODO: currently initialize SvcLogicServiceClient is failing, need to fix
78         ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider
79                                                                           .nbrlistChangeNotification(inputBuilder.build());
80         RpcResult<NbrlistChangeNotificationOutput> rpcResult = null;
81         try {
82             rpcResult = future.get();
83         } catch (Exception e) {
84             fail("Error : " + e);
85         }
86         LOG.info("result: {}", rpcResult);
87         assertEquals("503", rpcResult.getResult().getResponseCode());
88     }
89
90     //Input parameter validation
91     @Test
92     public void testvValidation() {
93
94         ListenableFuture<RpcResult<NbrlistChangeNotificationOutput>> future = cMNotifyProvider
95                                                                                       .nbrlistChangeNotification(null);
96         RpcResult<NbrlistChangeNotificationOutput> rpcResult = null;
97         try {
98             rpcResult = future.get();
99         } catch (Exception e) {
100             fail("Error : " + e);
101         }
102         LOG.info("result: {}", rpcResult);
103         assertEquals("Input is null", rpcResult.getResult().getResponseCode());
104     }
105 }