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.junit.runner.RunWith;
28 import org.mockito.runners.MockitoJUnitRunner;
29 import org.onap.sdnc.vnfapi.util.PropBuilder;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationInput;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationOutput;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.sdnc.request.header.SdncRequestHeader.SvcAction;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.model.infrastructure.VnfList;
36 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import static org.onap.sdnc.vnfapi.util.MDSALUtil.build;
39 import static org.onap.sdnc.vnfapi.util.MDSALUtil.exec;
40 import static org.onap.sdnc.vnfapi.util.MDSALUtil.sdncRequestHeader;
41 import static org.onap.sdnc.vnfapi.util.MDSALUtil.serviceData;
42 import static org.onap.sdnc.vnfapi.util.MDSALUtil.serviceInformation;
43 import static org.onap.sdnc.vnfapi.util.MDSALUtil.vnfInformation;
44 import static org.onap.sdnc.vnfapi.util.MDSALUtil.vnfList;
45 import static org.onap.sdnc.vnfapi.util.MDSALUtil.vnfRequestInformation;
46 import static org.onap.sdnc.vnfapi.util.MDSALUtil.vnfTopologyOperationInput;
47 import static org.onap.sdnc.vnfapi.util.MDSALUtil.vnfTopologyOperationOutput;
51 * This class test the VnfTopologyOperation mdsal RPC.
53 @RunWith(MockitoJUnitRunner.class)
54 public class VnfTopologyOperationRPCTest extends VnfApiProviderTest {
57 final String SVC_OPERATION = "vnf-topology-operation";
61 public void setUp() throws Exception {
63 svcClient.setScvOperation(SVC_OPERATION);
68 * Verify VnfTopologyOperation RPC executes Delete VNFList entry
69 * {@link VnfTopologyOperationOutput} and persisted the expected {@link VnfList} in the {@link DataBroker}
72 public void testVnfTopologyOperationRPC_Delete_VNFList_Entry_Success() throws Exception {
75 //mock svcClient to perform a successful execution with the expected parameters
76 svcClient.mockHasGraph(true);
77 PropBuilder svcResultProp = svcClient.createExecuteOKResult();
78 svcClient.mockExecute(svcResultProp);
80 // create the VnfTopologyOperationInput from the template
81 VnfTopologyOperationInput vnfTopologyOperationInput = createVTOI();
83 //persist a vnfList entry in the dataBroker
84 persistVnfListBroker(vnfTopologyOperationInput);
86 //execute the mdsal exec
87 VnfTopologyOperationOutput actualVnfTopologyOperationOutput = exec(
88 vnfapiProvider::vnfTopologyOperation
89 , vnfTopologyOperationInput
90 , RpcResult::getResult
94 //verify the returned VnfTopologyOperationOutput
95 VnfTopologyOperationOutput expectedVnfTopologyOperationOutput = createExpectedVTOO(svcResultProp,vnfTopologyOperationInput);
96 Assert.assertEquals(expectedVnfTopologyOperationOutput,actualVnfTopologyOperationOutput);
99 //verify the persisted VnfList
100 VnfList actualVnfList = db.read(vnfTopologyOperationInput.getVnfRequestInformation().getVnfId(), LogicalDatastoreType.CONFIGURATION);
101 VnfList expectedVnfList = null;
102 Assert.assertEquals(expectedVnfList,actualVnfList);
108 public VnfTopologyOperationInput createVTOI(){
109 return build(vnfTopologyOperationInput()
110 .setServiceInformation(
111 build(serviceInformation()
112 .setServiceId("serviceId: xyz")
113 .setServiceInstanceId("serviceInstanceId: xyz")
114 .setServiceType("serviceType: xyz")
115 .setSubscriberName("subscriberName: xyz")
118 .setVnfRequestInformation(
119 build(vnfRequestInformation()
120 .setVnfId("vnfId: xyz")
121 .setVnfName("vnfName: xyz")//defect if missing
122 .setVnfType("vnfType: xyz")//defect if missing
127 .setSdncRequestHeader(
128 build(sdncRequestHeader()
129 .setSvcAction(SvcAction.Delete)
138 private VnfList persistVnfListBroker(
139 VnfTopologyOperationInput vnfTopologyOperationInput
141 VnfList service = build(
143 .setVnfId(vnfTopologyOperationInput.getVnfRequestInformation().getVnfId())
146 .setVnfId(vnfTopologyOperationInput.getVnfRequestInformation().getVnfId())
150 db.write(true,service, LogicalDatastoreType.CONFIGURATION);
158 private VnfTopologyOperationOutput createExpectedVTOO(PropBuilder expectedSvcResultProp,VnfTopologyOperationInput expectedVnfTopologyOperationInput){
160 vnfTopologyOperationOutput()
161 .setSvcRequestId(expectedVnfTopologyOperationInput.getSdncRequestHeader().getSvcRequestId())
162 .setResponseCode(expectedSvcResultProp.get(svcClient.errorCode))
163 .setAckFinalIndicator(expectedSvcResultProp.get(svcClient.ackFinal))
164 .setResponseMessage(expectedSvcResultProp.get(svcClient.errorMessage))
165 .setVnfInformation(build(vnfInformation()
166 .setVnfId(expectedVnfTopologyOperationInput.getVnfRequestInformation().getVnfId())