Add tests to VnfApiProvider part 1
[sdnc/northbound.git] / vnfapi / provider / src / test / java / org / onap / sdnc / vnfapi / VnfApiProviderTest.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.vnfapi;
23
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.onap.sdnc.vnfapi.util.DataBrokerUtil;
30 import org.onap.sdnc.vnfapi.util.PropBuilder;
31 import org.onap.sdnc.vnfapi.util.VNFSDNSvcLogicServiceClientMockUtil;
32 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
33 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
34 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
35 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationInput;
40 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationOutput;
41 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationInputBuilder;
42 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.request.information.VnfInstanceRequestInformation;
43 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.request.information.VnfInstanceRequestInformationBuilder;
44
45 import java.util.concurrent.Future;
46
47
48 public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
49
50     protected VnfApiProvider vnfapiProvider;
51     protected DataBroker dataBroker;
52     protected @Mock NotificationPublishService mockNotificationPublishService;
53     protected @Mock RpcProviderRegistry mockRpcProviderRegistry;
54     protected @Mock VNFSDNSvcLogicServiceClient mockVNFSDNSvcLogicServiceClient;
55     protected static final Logger LOG = LoggerFactory.getLogger(VnfApiProvider.class);
56
57     protected DataBrokerUtil db;
58     protected VNFSDNSvcLogicServiceClientMockUtil svcClient;
59
60
61     @Before
62     public void setUp() throws Exception {
63         svcClient = new VNFSDNSvcLogicServiceClientMockUtil(mockVNFSDNSvcLogicServiceClient);
64         dataBroker = getDataBroker();
65         db = new DataBrokerUtil(dataBroker);
66          try {
67             vnfapiProvider = new VnfApiProvider(
68                     dataBroker,
69                     mockNotificationPublishService,
70                     mockRpcProviderRegistry,
71                     mockVNFSDNSvcLogicServiceClient
72             );
73         } catch (Exception e) {
74             LOG.error("Caught exception on setUp", e);
75             throw e;
76         }
77     }
78
79
80     public static PropBuilder prop(){
81         return (new PropBuilder());
82     }
83
84     @Test
85     public void vnfInstanceTopologyOperationInputIsNull() throws Exception {
86         VnfInstanceTopologyOperationInput input = null;
87         VnfInstanceTopologyOperationOutput result = vnfapiProvider
88                 .vnfInstanceTopologyOperation(input)
89                 .get()
90                 .getResult();
91
92         checkVnfInstanceTopologyOperationOutput(result);
93     }
94
95
96     @Test
97     public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationIsNull() throws Exception {
98         VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
99         builder.setVnfInstanceRequestInformation(null);
100
101         VnfInstanceTopologyOperationInput input = builder.build();
102         VnfInstanceTopologyOperationOutput result = vnfapiProvider
103                 .vnfInstanceTopologyOperation(input)
104                 .get()
105                 .getResult();
106
107         checkVnfInstanceTopologyOperationOutput(result);
108     }
109
110     @Test
111     public void vnfInstanceTopologyOperationInput_getVnfInstanceRequestInformationVnfInstanceIdIsNull() throws Exception {
112         VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
113         builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
114             .setVnfInstanceId(null)
115              .build());
116
117         VnfInstanceTopologyOperationInput input = builder.build();
118         VnfInstanceTopologyOperationOutput result = vnfapiProvider
119                 .vnfInstanceTopologyOperation(input)
120                 .get()
121                 .getResult();
122
123         checkVnfInstanceTopologyOperationOutput(result);
124     }
125
126     private void checkVnfInstanceTopologyOperationOutput(VnfInstanceTopologyOperationOutput result) {
127         String expectedResponseCode = "403";
128         String expectedResponseMessage = "invalid input, null or empty vnf-instance-id";
129         String expectedAckFinalIndicator = "Y";
130
131         Assert.assertEquals(result.getResponseCode(), expectedResponseCode );
132         Assert.assertEquals(result.getResponseMessage(), expectedResponseMessage);
133         Assert.assertEquals(result.getAckFinalIndicator(), expectedAckFinalIndicator);
134     }
135  }