72c244d57cba6b47e54aed162106ae670d80f624
[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 import java.util.concurrent.Future;
45
46
47 public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
48
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);
55
56     protected DataBrokerUtil db;
57     protected VNFSDNSvcLogicServiceClientMockUtil svcClient;
58
59
60     @Before
61     public void setUp() throws Exception {
62         svcClient = new VNFSDNSvcLogicServiceClientMockUtil(mockVNFSDNSvcLogicServiceClient);
63         dataBroker = getDataBroker();
64         db = new DataBrokerUtil(dataBroker);
65          try {
66             vnfapiProvider = new VnfApiProvider(
67                     dataBroker,
68                     mockNotificationPublishService,
69                     mockRpcProviderRegistry,
70                     mockVNFSDNSvcLogicServiceClient
71             );
72         } catch (Exception e) {
73             LOG.error("Caught exception on setUp", e);
74             throw e;
75         }
76     }
77
78
79     public static PropBuilder prop(){
80         return (new PropBuilder());
81     }
82
83     @Test
84     public void vnfInstanceTopologyOperationInputIsNull() throws Exception {
85         VnfInstanceTopologyOperationInput input = null;
86         VnfInstanceTopologyOperationOutput result = vnfapiProvider
87                 .vnfInstanceTopologyOperation(input)
88                 .get()
89                 .getResult();
90
91         checkVnfInstanceTopologyOperationOutput(result);
92     }
93
94
95     @Test
96     public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationIsNull() throws Exception {
97         VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
98         builder.setVnfInstanceRequestInformation(null);
99
100         VnfInstanceTopologyOperationInput input = builder.build();
101         VnfInstanceTopologyOperationOutput result = vnfapiProvider
102                 .vnfInstanceTopologyOperation(input)
103                 .get()
104                 .getResult();
105
106         checkVnfInstanceTopologyOperationOutput(result);
107     }
108
109     @Test
110     public void vnfInstanceTopologyOperationInput_getVnfInstanceRequestInformationVnfInstanceIdIsNull() throws Exception {
111         VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
112         builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
113             .setVnfInstanceId(null)
114              .build());
115
116         VnfInstanceTopologyOperationInput input = builder.build();
117         VnfInstanceTopologyOperationOutput result = vnfapiProvider
118                 .vnfInstanceTopologyOperation(input)
119                 .get()
120                 .getResult();
121
122         checkVnfInstanceTopologyOperationOutput(result);
123     }
124
125     @Test
126     public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationVnfInstanceIdIsZero() throws Exception {
127         VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
128         builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
129                 .setVnfInstanceId("")
130                 .build());
131
132         VnfInstanceTopologyOperationInput input = builder.build();
133         VnfInstanceTopologyOperationOutput result = vnfapiProvider
134                 .vnfInstanceTopologyOperation(input)
135                 .get()
136                 .getResult();
137
138         checkVnfInstanceTopologyOperationOutput(result);
139     }
140
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";
145
146         Assert.assertEquals(result.getResponseCode(), expectedResponseCode );
147         Assert.assertEquals(result.getResponseMessage(), expectedResponseMessage);
148         Assert.assertEquals(result.getAckFinalIndicator(), expectedAckFinalIndicator);
149     }
150  }