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;
45 import java.util.concurrent.Future;
48 public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
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);
57 protected DataBrokerUtil db;
58 protected VNFSDNSvcLogicServiceClientMockUtil svcClient;
62 public void setUp() throws Exception {
63 svcClient = new VNFSDNSvcLogicServiceClientMockUtil(mockVNFSDNSvcLogicServiceClient);
64 dataBroker = getDataBroker();
65 db = new DataBrokerUtil(dataBroker);
67 vnfapiProvider = new VnfApiProvider(
69 mockNotificationPublishService,
70 mockRpcProviderRegistry,
71 mockVNFSDNSvcLogicServiceClient
73 } catch (Exception e) {
74 LOG.error("Caught exception on setUp", e);
80 public static PropBuilder prop(){
81 return (new PropBuilder());
85 public void vnfInstanceTopologyOperationInputIsNull() throws Exception {
86 VnfInstanceTopologyOperationInput input = null;
87 VnfInstanceTopologyOperationOutput result = vnfapiProvider
88 .vnfInstanceTopologyOperation(input)
92 checkVnfInstanceTopologyOperationOutput(result);
97 public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationIsNull() throws Exception {
98 VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
99 builder.setVnfInstanceRequestInformation(null);
101 VnfInstanceTopologyOperationInput input = builder.build();
102 VnfInstanceTopologyOperationOutput result = vnfapiProvider
103 .vnfInstanceTopologyOperation(input)
107 checkVnfInstanceTopologyOperationOutput(result);
111 public void vnfInstanceTopologyOperationInput_getVnfInstanceRequestInformationVnfInstanceIdIsNull() throws Exception {
112 VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
113 builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
114 .setVnfInstanceId(null)
117 VnfInstanceTopologyOperationInput input = builder.build();
118 VnfInstanceTopologyOperationOutput result = vnfapiProvider
119 .vnfInstanceTopologyOperation(input)
123 checkVnfInstanceTopologyOperationOutput(result);
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";
131 Assert.assertEquals(result.getResponseCode(), expectedResponseCode );
132 Assert.assertEquals(result.getResponseMessage(), expectedResponseMessage);
133 Assert.assertEquals(result.getAckFinalIndicator(), expectedAckFinalIndicator);