597c75cef0bae8a105b447836eb91b14759754e2
[ccsdk/features.git] / sdnr / northbound / oofpcipoc / provider / src / test / java / org / onap / ccsdk / features / sdnr / northbound / oofpcipoc / TestOofpcipoc.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.oofpcipoc;
23
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import static org.junit.Assert.*;
32 import static org.mockito.Mockito.mock;
33
34 import java.math.*;
35
36 import org.opendaylight.mdsal.binding.api.DataBroker;
37 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
38 import org.opendaylight.mdsal.binding.api.RpcProviderService;
39
40 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev190308.ConfigurationPhyCellIdInputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev190308.ConfigurationPhyCellIdOutput;
42
43 import com.google.common.util.concurrent.ListenableFuture;
44
45
46
47 public class TestOofpcipoc {
48
49     private OofpcipocProvider oofpcipocProvider;
50     private static final Logger LOG = LoggerFactory.getLogger(OofpcipocProvider.class);
51
52     @Before
53     public void setUp() throws Exception {
54         if (null == oofpcipocProvider) {
55             DataBroker dataBroker = mock(DataBroker.class);
56             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
57             RpcProviderService mockRpcRegistry = mock(RpcProviderService.class);
58             OofpcipocClient mockSliClient = mock(OofpcipocClient.class);
59             oofpcipocProvider = new OofpcipocProvider();
60             oofpcipocProvider.setDataBroker(dataBroker);
61             oofpcipocProvider.setNotificationPublishService(mockNotification);
62             oofpcipocProvider.setRpcProviderService(mockRpcRegistry);
63             oofpcipocProvider.setClient(mockSliClient);
64         }
65     }
66
67     //Testcase should return error 503 when No service logic active for ConfigurationPhyCellId
68     @Test
69     public void testConfigurationPhyCellId() {
70
71         ConfigurationPhyCellIdInputBuilder inputBuilder = new ConfigurationPhyCellIdInputBuilder();
72
73         inputBuilder.setFapServiceNumberOfEntries(new BigInteger("1"));
74
75         // TODO: currently initialize SvcLogicServiceClient is failing, need to fix
76         ListenableFuture<RpcResult<ConfigurationPhyCellIdOutput>> future = oofpcipocProvider
77                                                                           .configurationPhyCellId(inputBuilder.build());
78         RpcResult<ConfigurationPhyCellIdOutput> rpcResult = null;
79         try {
80             rpcResult = future.get();
81         } catch (Exception e) {
82             fail("Error : " + e);
83         }
84         LOG.info("result: {}", rpcResult);
85         assertEquals("503", rpcResult.getResult().getResponseCode());
86     }
87
88     //Input parameter validation
89     @Test
90     public void testConfigurationPhyCellIdValidation() {
91
92         ListenableFuture<RpcResult<ConfigurationPhyCellIdOutput>> future = oofpcipocProvider
93                                                                                       .configurationPhyCellId(null);
94         RpcResult<ConfigurationPhyCellIdOutput> rpcResult = null;
95         try {
96             rpcResult = future.get();
97         } catch (Exception e) {
98             fail("Error : " + e);
99         }
100         LOG.info("result: {}", rpcResult);
101         assertEquals("Input is null", rpcResult.getResult().getResponseCode());
102     }
103 }