2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.svnfm.simulator.services;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
32 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
33 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum;
34 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo;
35 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoResourceHandle;
36 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo;
37 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
38 import org.onap.so.svnfm.simulator.model.Vnfds;
39 import org.onap.so.svnfm.simulator.model.Vnfds.Vnfc;
40 import org.onap.so.svnfm.simulator.model.Vnfds.Vnfd;
41 import org.onap.so.svnfm.simulator.config.ApplicationConfig;
42 import org.onap.so.svnfm.simulator.model.VnfOperation;
44 public class TerminateOperationProgressorTest {
46 private static final String VNFD_ID = "vnfdId";
47 private static final String VNFC_TYPE = "COMPUTE";
48 private static final String VDU_ID = "vduId";
49 private static final String VNF_INSTANCE_ID = "vnfInstanceId";
52 private SvnfmService svnfmService;
54 private TerminateOperationProgressor testedObject;
58 svnfmService = mock(SvnfmService.class);
59 VnfOperation vnfOperation = new VnfOperation();
60 vnfOperation.setVnfInstanceId(VNF_INSTANCE_ID);
61 vnfOperation.setOperation(OperationEnum.OPERATE);
62 testedObject = new TerminateOperationProgressor(vnfOperation, svnfmService, null, new ApplicationConfig(),
63 createVnfds(), createSubscriptionService());
67 public void test_getAddResources_usingValidVnfdId_returnsEmptyList() {
68 List<GrantsAddResources> results = testedObject.getAddResources(VNFD_ID);
69 assertThat(results.isEmpty());
73 public void test_getRemoveResources_usingValidVnfdId_retrievesGrantsAddResourcesSuccessfully() {
75 InlineResponse201 inlineResponse201 = createInlineResponse201();
76 InlineResponse201InstantiatedVnfInfo inlineResponse201InstantiatedVnfInfo =
77 setupInlineResponseInstantiatedVnfInfo();
78 inlineResponse201.setInstantiatedVnfInfo(inlineResponse201InstantiatedVnfInfo);
80 when(svnfmService.getVnf(VNF_INSTANCE_ID)).thenReturn(inlineResponse201);
83 List<GrantsAddResources> result = testedObject.getRemoveResources(VNFD_ID);
86 assertThat(result).hasSize(1);
87 GrantsAddResources grantsAddResourcesResult = result.get(0);
88 assertThat(grantsAddResourcesResult.getType()).hasToString(VNFC_TYPE);
89 assertThat(grantsAddResourcesResult.getVduId()).isEqualTo(VDU_ID);
93 public void test_getVnfcChangeType_isEnumRemoved() {
94 assertThat(testedObject.getVnfcChangeType().getValue()).isEqualTo("REMOVED");
97 private Vnfds createVnfds() {
98 Vnfd vnfd = new Vnfd();
99 vnfd.setVnfdId(VNFD_ID);
100 List<Vnfc> vnfcList = new ArrayList<>();
101 vnfcList.add(createVnfc());
102 vnfd.setVnfcList(vnfcList);
103 List<Vnfd> vnfdList = new ArrayList<>();
106 Vnfds vnfds = new Vnfds();
107 vnfds.setVnfdList(vnfdList);
111 private Vnfc createVnfc() {
112 Vnfc vnfc = new Vnfc();
113 String vnfcId = "vnfcId";
114 vnfc.setVnfcId(vnfcId);
115 vnfc.setType(VNFC_TYPE);
116 String resourceTemplateId = "resTempId";
117 vnfc.setResourceTemplateId(resourceTemplateId);
118 vnfc.setVduId(VDU_ID);
119 String resourceDefinitionId = "resourceDefinitionId";
120 vnfc.setGrantResourceId(resourceDefinitionId);
124 private SubscriptionService createSubscriptionService() {
125 SubscriptionService subscriptionService = new SubscriptionService();
126 LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest();
127 String callbackUri = "/lcn/uriest";
128 lccnSubscriptionRequest.setCallbackUri(callbackUri);
129 subscriptionService.registerSubscription(lccnSubscriptionRequest);
130 return subscriptionService;
133 private InlineResponse201 createInlineResponse201() {
134 InlineResponse201 inlineResponse201 = new InlineResponse201();
135 inlineResponse201.setVnfdId(VNFD_ID);
136 return inlineResponse201;
139 private InlineResponse201InstantiatedVnfInfo setupInlineResponseInstantiatedVnfInfo() {
140 InlineResponse201InstantiatedVnfInfo inlineResponse201InstantiatedVnfInfo =
141 new InlineResponse201InstantiatedVnfInfo();
142 List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> resultList = new ArrayList<>();
143 InlineResponse201InstantiatedVnfInfoVnfcResourceInfo resourceInfo =
144 new InlineResponse201InstantiatedVnfInfoVnfcResourceInfo();
145 String resourceInfoId = "resourceInfoId";
146 resourceInfo.setId(resourceInfoId);
147 resourceInfo.setVduId((VDU_ID));
148 InlineResponse201InstantiatedVnfInfoResourceHandle resourceHandle =
149 new InlineResponse201InstantiatedVnfInfoResourceHandle();
150 resourceInfo.setComputeResource(resourceHandle);
151 resultList.add(resourceInfo);
152 inlineResponse201InstantiatedVnfInfo.setVnfcResourceInfo(resultList);
153 String flavourId = "flavourId";
154 inlineResponse201InstantiatedVnfInfo.setFlavourId(flavourId);
155 return inlineResponse201InstantiatedVnfInfo;