blob: b8118d28cd0f44f4a274944df29d3dd04798a912 [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21
22
23package org.onap.osam.services;
24
25import com.google.common.collect.ImmutableMap;
26import jersey.repackaged.com.google.common.collect.ImmutableList;
27import org.onap.osam.aai.AaiClientInterface;
28import org.onap.osam.aai.AaiResponse;
29import org.onap.osam.aai.model.AaiNodeQueryResponse;
30import org.onap.osam.aai.model.ResourceType;
31import org.onap.osam.domain.mso.ModelInfo;
32import org.onap.osam.domain.mso.RequestStatus;
33import org.onap.osam.model.serviceInstantiation.ServiceInstantiation;
34import org.onap.osam.model.serviceInstantiation.VfModule;
35import org.onap.osam.model.serviceInstantiation.Vnf;
36import org.onap.osam.mso.RestObject;
37import org.onap.osam.mso.rest.AsyncRequestStatus;
38import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
39import org.togglz.core.manager.FeatureManager;
40
41import javax.inject.Inject;
42import java.util.*;
43
44import static org.mockito.Matchers.any;
45import static org.mockito.Mockito.when;
46
47public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests {
48
49 public static final String OWNING_ENTITY_ID = "038d99af-0427-42c2-9d15-971b99b9b489";
50 public static final String PACKET_CORE = "PACKET CORE";
51 public static final String PROJECT_NAME = "{some project name}";
52 public static final String SUBSCRIBER_ID = "{some subscriber id}";
53 public static final String SUBSCRIBER_NAME = "{some subscriber name}";
54 public static final String PRODUCT_FAMILY_ID = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
55 public static final String INSTANCE_NAME = "vPE_Service";
56 public static final String SUBSCRIPTION_SERVICE_TYPE = "VMX";
57 public static final String LCP_CLOUD_REGION_ID = "mdt1";
58 public static final String A6CA3EE0394ADE9403F075DB23167E = "88a6ca3ee0394ade9403f075db23167e";
59 public static final String TENANT_NAME = "USP-SIP-IC-24335-T-01";
60 public static final String AIC_ZONE_ID = "NFT1";
61 public static final String AIC_ZONE_NAME = "NFTJSSSS-NFT1";
62
63 protected HashMap<String, String> instanceParamsMapWithoutParams;
64 protected HashMap<String, String> vfModuleInstanceParamsMapWithParamsToRemove;
65 protected HashMap<String, String> vnfInstanceParamsMapWithParamsToRemove;
66
67 @Inject
68 protected FeatureManager featureManager;
69
70 @Inject
71 protected AaiClientInterface aaiClient;
72
73 public ServiceInstantiation generateMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
74 ModelInfo modelInfo = createModelInfo();
75
76 List<Map<String,String>> instanceParams = createInstanceParams();
77
78 return new ServiceInstantiation (
79 modelInfo,
80 AsyncInstantiationBusinessLogicTest.OWNING_ENTITY_ID,
81 AsyncInstantiationBusinessLogicTest.PACKET_CORE,
82 projectName,
83 AsyncInstantiationBusinessLogicTest.SUBSCRIBER_ID,
84 AsyncInstantiationBusinessLogicTest.SUBSCRIBER_NAME,
85 AsyncInstantiationBusinessLogicTest.PRODUCT_FAMILY_ID,
86 isUserProvidedNaming ? AsyncInstantiationBusinessLogicTest.INSTANCE_NAME : "" ,
87 isUserProvidedNaming,
88 AsyncInstantiationBusinessLogicTest.SUBSCRIPTION_SERVICE_TYPE,
89 AsyncInstantiationBusinessLogicTest.LCP_CLOUD_REGION_ID,
90 AsyncInstantiationBusinessLogicTest.A6CA3EE0394ADE9403F075DB23167E,
91 AsyncInstantiationBusinessLogicTest.TENANT_NAME,
92 AsyncInstantiationBusinessLogicTest.AIC_ZONE_ID,
93 AsyncInstantiationBusinessLogicTest.AIC_ZONE_NAME,
94 vnfs,
95 instanceParams,
96 isPause,
97 bulkSize,
98 rollbackOnFailure
99 );
100 }
101
102 private List<Map<String,String>> createInstanceParams() {
103 List<Map<String, String>> instanceParams = new ArrayList<>();
104 HashMap<String, String> map = new HashMap<>();
105 map.put("instanceParams_test1" , "some text");
106 map.put("instanceParams_test2" , "another text");
107 instanceParams.add(map);
108 return instanceParams;
109 }
110
111 private VfModule createVfModule(String modelName, String modelVersionId, String modelCustomizationId,
112 List<Map<String, String>> instanceParams, String instanceName, String volumeGroupInstanceName) {
113 ModelInfo vfModuleInfo = new ModelInfo();
114 vfModuleInfo.setModelType("vfModule");
115 vfModuleInfo.setModelName(modelName);
116 vfModuleInfo.setModelVersionId(modelVersionId);
117 vfModuleInfo.setModelCustomizationId(modelCustomizationId);
118 return new VfModule(vfModuleInfo , instanceName, volumeGroupInstanceName, instanceParams);
119 }
120
121 private ModelInfo createVnfModelInfo() {
122 ModelInfo vnfModelInfo = new ModelInfo();
123 vnfModelInfo.setModelType("vnf");
124 vnfModelInfo.setModelName("2016-73_MOW-AVPN-vPE-BV-L");
125 vnfModelInfo.setModelVersionId("7f40c192-f63c-463e-ba94-286933b895f8");
126 vnfModelInfo.setModelCustomizationName("2016-73_MOW-AVPN-vPE-BV-L 0");
127 vnfModelInfo.setModelCustomizationId("ab153b6e-c364-44c0-bef6-1f2982117f04");
128 return vnfModelInfo;
129 }
130
131 private ModelInfo createModelInfo() {
132 ModelInfo modelInfo = new ModelInfo();
133 modelInfo.setModelType("service");
134 modelInfo.setModelVersionId("3c40d244-808e-42ca-b09a-256d83d19d0a");
135 modelInfo.setModelVersion("10.0");
136 modelInfo.setModelInvariantId("5d48acb5-097d-4982-aeb2-f4a3bd87d31b");
137 modelInfo.setModelName("MOW AVPN vMX BV vPE 1 Service");
138 return modelInfo;
139 }
140
141 protected Map<String, Vnf> createVnfList(HashMap<String, String> vfModuleInstanceParamsMap, List vnfInstanceParams, boolean isUserProvidedNaming) {
142 Map<String, Vnf> vnfs = new HashMap<>();
143 ModelInfo vnfModelInfo = createVnfModelInfo();
144
145 Map<String, Map<String, VfModule>> vfModules = new HashMap<>();
146
147 List<Map<String, String>> instanceParams1 =ImmutableList.of((ImmutableMap.of("vmx_int_net_len", "24")));
148 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);
149 List<Map<String, String>> instanceParams2 = ImmutableList.of(vfModuleInstanceParamsMap);
150 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");
151
152 String vfModuleModelName = vfModule1.getModelInfo().getModelName();
153 vfModules.put(vfModuleModelName, new LinkedHashMap<>());
154
155 vfModules.get(vfModuleModelName).put(vfModule1.getInstanceName(),vfModule1);
156 vfModules.get(vfModuleModelName).put(vfModule2.getInstanceName(), vfModule2);
157
158 Vnf vnf = new Vnf(vnfModelInfo, "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "vmxnjr001", isUserProvidedNaming,
159 "platformName", "mdt1", "88a6ca3ee0394ade9403f075db23167e", vnfInstanceParams,"lineOfBusinessName" ,vfModules);
160
161 vnfs.put(vnf.getInstanceName(), vnf);
162 return vnfs;
163 }
164
165 protected void createInstanceParamsMaps() {
166 instanceParamsMapWithoutParams = new HashMap<>();
167 instanceParamsMapWithoutParams.put("availability_zone_0" , "mtpocdv-kvm-az01");
168 instanceParamsMapWithoutParams.put("vre_a_volume_size_0" , "100");
169
170 vfModuleInstanceParamsMapWithParamsToRemove = new HashMap<>();
171 vfModuleInstanceParamsMapWithParamsToRemove.put(IAsyncInstantiationBusinessLogic.PARAMS_TO_IGNORE.get(0), "should be removed");
172 vfModuleInstanceParamsMapWithParamsToRemove.put("availability_zone_0" , "mtpocdv-kvm-az01");
173 vfModuleInstanceParamsMapWithParamsToRemove.put("vre_a_volume_size_0" , "100");
174
175 vnfInstanceParamsMapWithParamsToRemove = new HashMap<>();
176 vnfInstanceParamsMapWithParamsToRemove.put(IAsyncInstantiationBusinessLogic.PARAMS_TO_IGNORE.get(1), "should be removed");
177 }
178
179 protected AsyncRequestStatus asyncRequestStatusResponse(String msoStatus) {
180 AsyncRequestStatus asyncRequestStatus = new AsyncRequestStatus(new AsyncRequestStatus.Request(new RequestStatus()));
181 asyncRequestStatus.request.requestStatus.setRequestState(msoStatus);
182 asyncRequestStatus.request.requestId = UUID.randomUUID().toString();
183 return asyncRequestStatus;
184 }
185
186 protected RestObject<AsyncRequestStatus> asyncRequestStatusResponseAsRestObject(String msoStatus) {
187 return asyncRequestStatusResponseAsRestObject(msoStatus, 200);
188 }
189
190 protected RestObject<AsyncRequestStatus> asyncRequestStatusResponseAsRestObject(String msoStatus, int httpStatusCode) {
191 RestObject<AsyncRequestStatus> restObject = new RestObject<>();
192 restObject.set(asyncRequestStatusResponse(msoStatus));
193 restObject.setStatusCode(httpStatusCode);
194 return restObject;
195 }
196
197 protected void mockAaiClientAnyNameFree() {
198 when(aaiClient.searchNodeTypeByName(any(), any())).thenReturn(aaiNodeQueryResponseNameFree());
199 }
200
201 protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() {
202 return new AaiResponse<>(new AaiNodeQueryResponse(null),"", 200);
203 }
204
205 protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryBadResponse() {
206 return new AaiResponse<>(null,"", 404);
207 }
208
209 protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameUsed(ResourceType type) {
210 AaiNodeQueryResponse mockAaiNodeQuery = new AaiNodeQueryResponse(ImmutableList.of(new AaiNodeQueryResponse.ResultData(type, "/some/mocked/link")));
211 return new AaiResponse<>(mockAaiNodeQuery,"", 200);
212 }
213}