ORAN CMNotify Karaf Feature Development
[ccsdk/features.git] / sdnr / northbound / CMNotify / provider / src / test / java / org / onap / ccsdk / features / sdnr / northbound / CMNotify / CMNotifyClientTest.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 static org.junit.Assert.*;
25 import static org.mockito.Mockito.*;
26
27 import java.util.Properties;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
33 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
34
35 import org.onap.ccsdk.features.sdnr.northbound.CMNotify.CMNotifyClient;
36
37 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInput;
38 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationInputBuilder;
39 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutput;
40 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev200224.NbrlistChangeNotificationOutputBuilder;
41
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 public class CMNotifyClientTest {
46
47         SvcLogicService mockSvcLogicService;
48         String module = "test-module";
49         String rpc = "test-rpc";
50         String version = "test-version";
51         String mode = "test-mode";
52         Properties localProp = new Properties();
53
54         @Before
55         public void setUp() throws Exception {
56                 mockSvcLogicService = mock(SvcLogicService.class);
57                 when(mockSvcLogicService.hasGraph(module, rpc, version, mode)).thenReturn(true);
58         }
59
60         @Test
61         public void testCMNotifyClientConstructor() {
62                 CMNotifyClient CMNotifyClient = new CMNotifyClient(mockSvcLogicService);
63                 assertNotNull(CMNotifyClient);
64         }
65
66         @Test
67         public void testHasGraph() throws SvcLogicException {
68                 CMNotifyClient CMNotifyClient = new CMNotifyClient(mockSvcLogicService);
69                 boolean result = CMNotifyClient.hasGraph(module, rpc, version, mode);
70                 assertTrue(result);
71         }
72
73         @Test
74         public void testExecuteSvcLogicStatusFailure() throws SvcLogicException {
75                 NbrlistChangeNotificationOutputBuilder serviceData = mock(NbrlistChangeNotificationOutputBuilder.class);
76                 Properties parms = mock(Properties.class);
77                 SvcLogicService svcLogicService = mock(SvcLogicService.class);
78                 Properties properties = new Properties();
79                 properties.setProperty("SvcLogic.status", "failure");
80                 when(svcLogicService.execute(module, rpc, version, mode, properties)).thenReturn(properties);
81                 CMNotifyClient sliClient = new CMNotifyClient(svcLogicService);
82                 Properties prop = sliClient.execute(module, rpc, version, mode, serviceData, properties);
83                 assertTrue(prop != null);
84         }
85 }