Add unit test for dmaap-listener
[ccsdk/sli/northbound.git] / asdcApi / provider / src / test / java / org / onap / sdnc / northbound / asdcapi / TestAsdcApiApi.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.sdnc.northbound.asdcapi;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiProvider;
27 import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiSliClient;
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.rev170201.VfLicenseModelUpdateInputBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateOutput;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 import static org.junit.Assert.*;
39 import static org.mockito.Mockito.mock;
40
41 public class TestAsdcApiApi extends AbstractConcurrentDataBrokerTest {
42
43     private AsdcApiProvider asdcApiProvider;
44     private static final Logger LOG = LoggerFactory.getLogger(AsdcApiProvider.class);
45
46     @Before
47     public void setUp() throws Exception {
48         if (null == asdcApiProvider) {
49             DataBroker dataBroker = getDataBroker();
50             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
51             RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class);
52             AsdcApiSliClient mockSliClient = mock(AsdcApiSliClient.class);
53             asdcApiProvider = new AsdcApiProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient);
54         }
55     }
56
57     //Testcase should return error 503 when No service logic active for ASDC-API.
58     @Test
59     public void testVfLicenseModelUpdate() {
60
61         VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder();
62
63         inputBuilder.setArtifactName("abc");
64         inputBuilder.setArtifactVersion("1");
65
66         // TODO: currently initialize SvcLogicServiceClient is failing, need to fix
67         java.util.concurrent.Future<RpcResult<VfLicenseModelUpdateOutput>> future = asdcApiProvider
68                                                                           .vfLicenseModelUpdate(inputBuilder.build());
69         RpcResult<VfLicenseModelUpdateOutput> rpcResult = null;
70         try {
71             rpcResult = future.get();
72         } catch (Exception e) {
73             fail("Error : " + e);
74         }
75         LOG.info("result: {}", rpcResult);
76         assertEquals("503", rpcResult.getResult().getAsdcApiResponseCode());
77     }
78
79     //Input parameter validation
80     @Test
81     public void testVfLicenseModelUpdateInputValidation() {
82
83         VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder();
84
85         inputBuilder.setArtifactName("abc");
86         inputBuilder.setArtifactVersion("1");
87
88         java.util.concurrent.Future<RpcResult<VfLicenseModelUpdateOutput>> future = asdcApiProvider
89                                                                                            .vfLicenseModelUpdate(null);
90         assertNull(future);
91     }
92
93     @Test(expected = IllegalArgumentException.class)
94     public void testVfLicenseModelUpdateValidation1() {
95
96         VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder();
97
98         java.util.concurrent.Future<RpcResult<VfLicenseModelUpdateOutput>> future = asdcApiProvider
99                 .vfLicenseModelUpdate(inputBuilder.build());
100         RpcResult<VfLicenseModelUpdateOutput> rpcResult = null;
101         try {
102             rpcResult = future.get();
103         } catch (Exception e) {
104             fail("Error : " + e);
105         }
106     }
107 }