2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.sdnc.vnfapi;
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 import java.util.concurrent.Future;
47 public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
49 protected VnfApiProvider vnfapiProvider;
50 protected DataBroker dataBroker;
51 protected @Mock NotificationPublishService mockNotificationPublishService;
52 protected @Mock RpcProviderRegistry mockRpcProviderRegistry;
53 protected @Mock VNFSDNSvcLogicServiceClient mockVNFSDNSvcLogicServiceClient;
54 protected static final Logger LOG = LoggerFactory.getLogger(VnfApiProvider.class);
56 protected DataBrokerUtil db;
57 protected VNFSDNSvcLogicServiceClientMockUtil svcClient;
61 public void setUp() throws Exception {
62 svcClient = new VNFSDNSvcLogicServiceClientMockUtil(mockVNFSDNSvcLogicServiceClient);
63 dataBroker = getDataBroker();
64 db = new DataBrokerUtil(dataBroker);
66 vnfapiProvider = new VnfApiProvider(
68 mockNotificationPublishService,
69 mockRpcProviderRegistry,
70 mockVNFSDNSvcLogicServiceClient
72 } catch (Exception e) {
73 LOG.error("Caught exception on setUp", e);
79 public static PropBuilder prop(){
80 return (new PropBuilder());
84 public void vnfInstanceTopologyOperationInputIsNull() throws Exception {
85 VnfInstanceTopologyOperationInput input = null;
86 VnfInstanceTopologyOperationOutput result = vnfapiProvider
87 .vnfInstanceTopologyOperation(input)
91 checkVnfInstanceTopologyOperationOutput(result);
96 public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationIsNull() throws Exception {
97 VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
98 builder.setVnfInstanceRequestInformation(null);
100 VnfInstanceTopologyOperationInput input = builder.build();
101 VnfInstanceTopologyOperationOutput result = vnfapiProvider
102 .vnfInstanceTopologyOperation(input)
106 checkVnfInstanceTopologyOperationOutput(result);
110 public void vnfInstanceTopologyOperationInput_getVnfInstanceRequestInformationVnfInstanceIdIsNull() throws Exception {
111 VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
112 builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
113 .setVnfInstanceId(null)
116 VnfInstanceTopologyOperationInput input = builder.build();
117 VnfInstanceTopologyOperationOutput result = vnfapiProvider
118 .vnfInstanceTopologyOperation(input)
122 checkVnfInstanceTopologyOperationOutput(result);
126 public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationVnfInstanceIdIsZero() throws Exception {
127 VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
128 builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
129 .setVnfInstanceId("")
132 VnfInstanceTopologyOperationInput input = builder.build();
133 VnfInstanceTopologyOperationOutput result = vnfapiProvider
134 .vnfInstanceTopologyOperation(input)
138 checkVnfInstanceTopologyOperationOutput(result);
141 private void checkVnfInstanceTopologyOperationOutput(VnfInstanceTopologyOperationOutput result) {
142 String expectedResponseCode = "403";
143 String expectedResponseMessage = "invalid input, null or empty vnf-instance-id";
144 String expectedAckFinalIndicator = "Y";
146 Assert.assertEquals(result.getResponseCode(), expectedResponseCode );
147 Assert.assertEquals(result.getResponseMessage(), expectedResponseMessage);
148 Assert.assertEquals(result.getAckFinalIndicator(), expectedAckFinalIndicator);