2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Nokia. All rights 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
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.vid.services;
24 import com.google.common.collect.ImmutableMap;
25 import io.joshworks.restclient.http.HttpResponse;
26 import jersey.repackaged.com.google.common.collect.ImmutableList;
27 import org.apache.http.HttpStatus;
28 import org.apache.http.HttpVersion;
29 import org.apache.http.entity.StringEntity;
30 import org.apache.http.impl.DefaultHttpResponseFactory;
31 import org.apache.http.message.BasicStatusLine;
32 import org.onap.vid.aai.AaiOverTLSClientInterface;
33 import org.onap.vid.aai.AaiResponse;
34 import org.onap.vid.aai.model.AaiNodeQueryResponse;
35 import org.onap.vid.aai.model.ResourceType;
36 import org.onap.vid.domain.mso.ModelInfo;
37 import org.onap.vid.domain.mso.RequestStatus;
38 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
39 import org.onap.vid.model.serviceInstantiation.VfModule;
40 import org.onap.vid.model.serviceInstantiation.Vnf;
41 import org.onap.vid.mso.RestObject;
42 import org.onap.vid.mso.rest.AsyncRequestStatus;
43 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
44 import org.togglz.core.manager.FeatureManager;
46 import javax.inject.Inject;
47 import java.io.UnsupportedEncodingException;
50 import static org.mockito.ArgumentMatchers.any;
51 import static org.mockito.Mockito.when;
53 public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests {
55 public static final String OWNING_ENTITY_ID = "038d99af-0427-42c2-9d15-971b99b9b489";
56 public static final String PACKET_CORE = "PACKET CORE";
57 public static final String PROJECT_NAME = "{some project name}";
58 public static final String SUBSCRIBER_ID = "{some subscriber id}";
59 public static final String SUBSCRIBER_NAME = "{some subscriber name}";
60 public static final String PRODUCT_FAMILY_ID = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
61 public static final String INSTANCE_NAME = "vPE_Service";
62 public static final String SUBSCRIPTION_SERVICE_TYPE = "VMX";
63 public static final String LCP_CLOUD_REGION_ID = "mdt1";
64 public static final String A6CA3EE0394ADE9403F075DB23167E = "88a6ca3ee0394ade9403f075db23167e";
65 public static final String TENANT_NAME = "USP-SIP-IC-24335-T-01";
66 public static final String AIC_ZONE_ID = "NFT1";
67 public static final String AIC_ZONE_NAME = "NFTJSSSS-NFT1";
69 protected HashMap<String, String> instanceParamsMapWithoutParams;
70 protected HashMap<String, String> vfModuleInstanceParamsMapWithParamsToRemove;
71 protected HashMap<String, String> vnfInstanceParamsMapWithParamsToRemove;
74 protected FeatureManager featureManager;
77 protected AaiOverTLSClientInterface aaiClient;
79 public ServiceInstantiation generateMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
80 ModelInfo modelInfo = createModelInfo();
82 List<Map<String,String>> instanceParams = createInstanceParams();
84 return new ServiceInstantiation (
86 AsyncInstantiationBusinessLogicTest.OWNING_ENTITY_ID,
87 AsyncInstantiationBusinessLogicTest.PACKET_CORE,
89 AsyncInstantiationBusinessLogicTest.SUBSCRIBER_ID,
90 AsyncInstantiationBusinessLogicTest.SUBSCRIBER_NAME,
91 AsyncInstantiationBusinessLogicTest.PRODUCT_FAMILY_ID,
92 isUserProvidedNaming ? AsyncInstantiationBusinessLogicTest.INSTANCE_NAME : "" ,
94 AsyncInstantiationBusinessLogicTest.SUBSCRIPTION_SERVICE_TYPE,
95 AsyncInstantiationBusinessLogicTest.LCP_CLOUD_REGION_ID,
96 AsyncInstantiationBusinessLogicTest.A6CA3EE0394ADE9403F075DB23167E,
97 AsyncInstantiationBusinessLogicTest.TENANT_NAME,
98 AsyncInstantiationBusinessLogicTest.AIC_ZONE_ID,
99 AsyncInstantiationBusinessLogicTest.AIC_ZONE_NAME,
108 private List<Map<String,String>> createInstanceParams() {
109 List<Map<String, String>> instanceParams = new ArrayList<>();
110 HashMap<String, String> map = new HashMap<>();
111 map.put("instanceParams_test1" , "some text");
112 map.put("instanceParams_test2" , "another text");
113 instanceParams.add(map);
114 return instanceParams;
117 private VfModule createVfModule(String modelName, String modelVersionId, String modelCustomizationId,
118 List<Map<String, String>> instanceParams, String instanceName, String volumeGroupInstanceName) {
119 ModelInfo vfModuleInfo = new ModelInfo();
120 vfModuleInfo.setModelType("vfModule");
121 vfModuleInfo.setModelName(modelName);
122 vfModuleInfo.setModelVersionId(modelVersionId);
123 vfModuleInfo.setModelCustomizationId(modelCustomizationId);
124 return new VfModule(vfModuleInfo , instanceName, volumeGroupInstanceName, instanceParams);
127 private ModelInfo createVnfModelInfo() {
128 ModelInfo vnfModelInfo = new ModelInfo();
129 vnfModelInfo.setModelType("vnf");
130 vnfModelInfo.setModelName("2016-73_MOW-AVPN-vPE-BV-L");
131 vnfModelInfo.setModelVersionId("7f40c192-f63c-463e-ba94-286933b895f8");
132 vnfModelInfo.setModelCustomizationName("2016-73_MOW-AVPN-vPE-BV-L 0");
133 vnfModelInfo.setModelCustomizationId("ab153b6e-c364-44c0-bef6-1f2982117f04");
137 private ModelInfo createModelInfo() {
138 ModelInfo modelInfo = new ModelInfo();
139 modelInfo.setModelType("service");
140 modelInfo.setModelVersionId("3c40d244-808e-42ca-b09a-256d83d19d0a");
141 modelInfo.setModelVersion("10.0");
142 modelInfo.setModelInvariantId("5d48acb5-097d-4982-aeb2-f4a3bd87d31b");
143 modelInfo.setModelName("MOW AVPN vMX BV vPE 1 Service");
147 protected Map<String, Vnf> createVnfList(HashMap<String, String> vfModuleInstanceParamsMap, List vnfInstanceParams, boolean isUserProvidedNaming) {
148 Map<String, Vnf> vnfs = new HashMap<>();
149 ModelInfo vnfModelInfo = createVnfModelInfo();
151 Map<String, Map<String, VfModule>> vfModules = new HashMap<>();
153 List<Map<String, String>> instanceParams1 =ImmutableList.of((ImmutableMap.of("vmx_int_net_len", "24")));
154 VfModule vfModule1 = createVfModule("201673MowAvpnVpeBvL..AVPN_base_vPE_BV..module-0", "4c75f813-fa91-45a4-89d0-790ff5f1ae79", "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", instanceParams1, "vmxnjr001_AVPN_base_vPE_BV_base", null);
155 List<Map<String, String>> instanceParams2 = ImmutableList.of(vfModuleInstanceParamsMap);
156 VfModule vfModule2 = createVfModule("201673MowAvpnVpeBvL..AVPN_vRE_BV..module-1", "56e2b103-637c-4d1a-adc8-3a7f4a6c3240", "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", instanceParams2, "vmxnjr001_AVPN_base_vRE_BV_expansion", "myVgName");
158 String vfModuleModelName = vfModule1.getModelInfo().getModelName();
159 vfModules.put(vfModuleModelName, new LinkedHashMap<>());
161 vfModules.get(vfModuleModelName).put(vfModule1.getInstanceName(),vfModule1);
162 vfModules.get(vfModuleModelName).put(vfModule2.getInstanceName(), vfModule2);
164 Vnf vnf = new Vnf(vnfModelInfo, "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "vmxnjr001", isUserProvidedNaming,
165 "platformName", "mdt1", "88a6ca3ee0394ade9403f075db23167e", vnfInstanceParams,"lineOfBusinessName" ,vfModules);
167 vnfs.put(vnf.getInstanceName(), vnf);
171 protected void createInstanceParamsMaps() {
172 instanceParamsMapWithoutParams = new HashMap<>();
173 instanceParamsMapWithoutParams.put("availability_zone_0" , "mtpocdv-kvm-az01");
174 instanceParamsMapWithoutParams.put("vre_a_volume_size_0" , "100");
176 vfModuleInstanceParamsMapWithParamsToRemove = new HashMap<>();
177 vfModuleInstanceParamsMapWithParamsToRemove.put(AsyncInstantiationBusinessLogic.PARAMS_TO_IGNORE.get(0), "should be removed");
178 vfModuleInstanceParamsMapWithParamsToRemove.put("availability_zone_0" , "mtpocdv-kvm-az01");
179 vfModuleInstanceParamsMapWithParamsToRemove.put("vre_a_volume_size_0" , "100");
181 vnfInstanceParamsMapWithParamsToRemove = new HashMap<>();
182 vnfInstanceParamsMapWithParamsToRemove.put(AsyncInstantiationBusinessLogic.PARAMS_TO_IGNORE.get(1), "should be removed");
185 protected AsyncRequestStatus asyncRequestStatusResponse(String msoStatus) {
186 AsyncRequestStatus asyncRequestStatus = new AsyncRequestStatus(new AsyncRequestStatus.Request(new RequestStatus()));
187 asyncRequestStatus.request.requestStatus.setRequestState(msoStatus);
188 asyncRequestStatus.request.requestId = UUID.randomUUID().toString();
189 return asyncRequestStatus;
192 protected RestObject<AsyncRequestStatus> asyncRequestStatusResponseAsRestObject(String msoStatus) {
193 return asyncRequestStatusResponseAsRestObject(msoStatus, 200);
196 protected RestObject<AsyncRequestStatus> asyncRequestStatusResponseAsRestObject(String msoStatus, int httpStatusCode) {
197 RestObject<AsyncRequestStatus> restObject = new RestObject<>();
198 restObject.set(asyncRequestStatusResponse(msoStatus));
199 restObject.setStatusCode(httpStatusCode);
203 protected void mockAaiClientAnyNameFree() throws UnsupportedEncodingException {
204 when(aaiClient.searchNodeTypeByName(any(), any())).thenReturn(aaiNodeQueryResponseNameFree());
207 protected HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() throws UnsupportedEncodingException {
208 org.apache.http.HttpResponse response = new DefaultHttpResponseFactory().newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
209 response.setEntity(new StringEntity(""));
211 return HttpResponse.fallback(new AaiNodeQueryResponse(null));
214 protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryBadResponse() {
215 return new AaiResponse<>(null,"", 404);
218 protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameUsed(ResourceType type) {
219 AaiNodeQueryResponse mockAaiNodeQuery = new AaiNodeQueryResponse(ImmutableList.of(new AaiNodeQueryResponse.ResultData(type, "/some/mocked/link")));
220 return new AaiResponse<>(mockAaiNodeQuery,"", 200);