f9c39b703f1cc85ab5bf200042c53eb6bfc88ac2
[ccsdk/sli.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.sdnc.northbound.dataChange;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.ccsdk.sli.northbound.DataChangeProvider;
27 import org.onap.ccsdk.sli.northbound.DataChangeClient;
28 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
29 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
30 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
31 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
32 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.datachange.rev150519.DataChangeNotificationInput;
33 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.datachange.rev150519.DataChangeNotificationInputBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.datachange.rev150519.DataChangeNotificationOutput;
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 public class TestDataChange extends AbstractConcurrentDataBrokerTest {
43
44     private DataChangeProvider dataChangeProvider;
45     private static final Logger LOG = LoggerFactory.getLogger(DataChangeProvider.class);
46
47     @Before
48     public void setUp() throws Exception {
49         if (null == dataChangeProvider) {
50             DataBroker dataBroker = getDataBroker();
51             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
52             RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class);
53             DataChangeClient mockSliClient = mock(DataChangeClient.class);
54             dataChangeProvider = new DataChangeProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient);
55         }
56     }
57
58     //Testcase should return error 503 when No service logic active for dataChange.
59     @Test
60     public void testDataChangeNotification() {
61
62         DataChangeNotificationInputBuilder inputBuilder = new DataChangeNotificationInputBuilder();
63
64         inputBuilder.setAaiEventId("1");
65
66
67         // TODO: currently initialize SvcLogicServiceClient is failing, need to fix
68         java.util.concurrent.Future<RpcResult<DataChangeNotificationOutput>> future = dataChangeProvider
69                                                                           .dataChangeNotification(inputBuilder.build());
70         RpcResult<DataChangeNotificationOutput> rpcResult = null;
71         try {
72             rpcResult = future.get();
73         } catch (Exception e) {
74             fail("Error : " + e);
75         }
76         LOG.info("result: {}", rpcResult);
77         assertEquals("503", rpcResult.getResult().getDataChangeResponseCode());
78     }
79
80     //Input parameter validation
81     @Test
82     public void testDataChangeNotificationInputValidation() {
83
84         java.util.concurrent.Future<RpcResult<DataChangeNotificationOutput>> future = dataChangeProvider
85                                                                                       .dataChangeNotification(null);
86         RpcResult<DataChangeNotificationOutput> rpcResult = null;
87         try {
88             rpcResult = future.get();
89         } catch (Exception e) {
90             fail("Error : " + e);
91         }
92         LOG.info("result: {}", rpcResult);
93         assertEquals("403", rpcResult.getResult().getDataChangeResponseCode());
94     }
95 }