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