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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/*-
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. 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.sdc.backend.ci.tests.utils.general;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.backend.ci.tests.datatypes.*;
import org.onap.sdc.backend.ci.tests.datatypes.enums.ErrorInfo;
import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
import org.onap.sdc.backend.ci.tests.utils.validation.ErrorValidationUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Product;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.onap.sdc.backend.ci.tests.datatypes.expected.ExpectedProductAudit;
import org.onap.sdc.backend.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
import org.onap.sdc.backend.ci.tests.datatypes.expected.ExpectedUserCRUDAudit;
import org.openecomp.sdc.common.api.Constants;
import static org.onap.sdc.backend.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_CREATED;
import static org.onap.sdc.backend.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_SUCCESS;
public class Convertor {
// ***** resource *****
public static ResourceRespJavaObject constructFieldsForRespValidation(ResourceReqDetails resourceDetails,
String resourceVersion) {
return convertToRespObject(resourceDetails, resourceVersion, UserRoleEnum.ADMIN.getUserId(),
UserRoleEnum.ADMIN.getUserName());
}
public static ResourceRespJavaObject constructFieldsForRespValidation(ResourceReqDetails resourceDetails) {
return convertToRespObject(resourceDetails, resourceDetails.getVersion(), UserRoleEnum.ADMIN.getUserId(),
UserRoleEnum.ADMIN.getUserName());
}
public static ResourceRespJavaObject constructFieldsForRespValidation(ResourceReqDetails resourceDetails,
String resourceVersion, User user) {
return convertToRespObject(resourceDetails, resourceVersion, user.getUserId(), user.getFullName());
}
private static ResourceRespJavaObject convertToRespObject(ResourceReqDetails resourceDetails,
String resourceVersion, String userId, String userName) {
ResourceRespJavaObject resourceRespJavaObject = new ResourceRespJavaObject();
resourceRespJavaObject.setUniqueId(resourceDetails.getUniqueId());
resourceRespJavaObject.setName(resourceDetails.getName());
resourceRespJavaObject.setCreatorUserId(resourceDetails.getCreatorUserId());
resourceRespJavaObject.setCreatorFullName(resourceDetails.getCreatorFullName());
resourceRespJavaObject.setLastUpdaterUserId(userId);
resourceRespJavaObject.setLastUpdaterFullName(userName);
resourceRespJavaObject.setDescription(resourceDetails.getDescription());
resourceRespJavaObject.setIcon(resourceDetails.getIcon());
resourceRespJavaObject.setTags(resourceDetails.getTags());
resourceRespJavaObject.setIsHighestVersion("true");
resourceRespJavaObject.setCategories(resourceDetails.getCategories());
resourceRespJavaObject.setLifecycleState(
resourceDetails.getLifecycleState() != null ? resourceDetails.getLifecycleState().toString()
: LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.toString());
// resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
resourceRespJavaObject.setDerivedFrom(resourceDetails.getDerivedFrom());
resourceRespJavaObject.setVendorName(resourceDetails.getVendorName());
resourceRespJavaObject.setVendorRelease(resourceDetails.getVendorRelease());
resourceRespJavaObject.setContactId(resourceDetails.getContactId());
resourceRespJavaObject.setAbstractt("false");
resourceRespJavaObject.setVersion(resourceVersion);
resourceRespJavaObject.setCost(resourceDetails.getCost());
resourceRespJavaObject.setLicenseType(resourceDetails.getLicenseType());
resourceRespJavaObject.setResourceType(resourceDetails.getResourceType());
return resourceRespJavaObject;
}
// ********** service **************
// public static ServiceRespJavaObject
// constructFieldsForRespValidation(ServiceReqDetails serviceDetails, String
// serviceVersion, User user) {
// return convertToRespObject(serviceDetails, serviceVersion,
// user.getUserId(), user.getFullName());
//
// }
//
// private static ServiceRespJavaObject
// convertToRespObject(ServiceReqDetails serviceDetails, String
// serviceVersion, String userId, String userName) {
// ServiceRespJavaObject serviceRespJavaObject = new
// ServiceRespJavaObject();
//
// serviceRespJavaObject.setUniqueId(serviceDetails.getUniqueId());
// serviceRespJavaObject.setName(serviceDetails.getName());
// serviceRespJavaObject.setCreatorUserId(userId);
// serviceRespJavaObject.setCreatorFullName(userName);
// serviceRespJavaObject.setLastUpdaterUserId(userId);
// serviceRespJavaObject.setLastUpdaterFullName(userName);
// serviceRespJavaObject.setDescription(serviceDetails.getDescription());
// serviceRespJavaObject.setIcon(serviceDetails.getIcon());
// serviceRespJavaObject.setCategory(serviceDetails.getCategory());
// serviceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
// serviceRespJavaObject.setContactId(serviceDetails.getContactId());
// serviceRespJavaObject.setVersion(serviceVersion);
//
// return serviceRespJavaObject;
// }
// ********** product **************
public static Product constructFieldsForRespValidation(ProductReqDetails productDetails, String productVersion,
User user) {
return convertToRespObject(productDetails, productVersion, user.getUserId(), user.getFullName());
}
private static Product convertToRespObject(ProductReqDetails productDetails, String productVersion, String userId,
String userName) {
Product expectedProduct = new Product();
expectedProduct.setUniqueId(productDetails.getUniqueId());
expectedProduct.setName(productDetails.getName());
expectedProduct.setFullName(productDetails.getFullName());
expectedProduct.setCreatorUserId(productDetails.getCreatorUserId());
expectedProduct.setCreatorFullName(productDetails.getCreatorFullName());
expectedProduct.setLastUpdaterUserId(userId);
expectedProduct.setLastUpdaterFullName(userName);
expectedProduct.setDescription(productDetails.getDescription());
// expectedProduct.setIcon(resourceDetails.getIcon());
expectedProduct.setTags(productDetails.getTags());
expectedProduct.setHighestVersion(true);
List<CategoryDefinition> categories = productDetails.getCategories();
if (categories == null) {
categories = new ArrayList<>();
}
expectedProduct.setCategories(categories);
expectedProduct.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
expectedProduct.setVersion(productVersion);
expectedProduct.setContacts(productDetails.getContacts());
return expectedProduct;
}
// ***** audit *****
public static ExpectedResourceAuditJavaObject constructFieldsForAuditValidation(ResourceReqDetails resourceDetails,
String resourceVersion) {
return convertToAuditObject(resourceDetails, resourceVersion, UserRoleEnum.ADMIN.getUserId(),
UserRoleEnum.ADMIN.getUserName());
}
public static ExpectedResourceAuditJavaObject constructFieldsForAuditValidation(
ResourceReqDetails resourceDetails) {
return convertToAuditObject(resourceDetails, resourceDetails.getVersion(), UserRoleEnum.ADMIN.getUserId(),
UserRoleEnum.ADMIN.getUserName());
}
public static ExpectedResourceAuditJavaObject constructFieldsForAuditValidation(ResourceReqDetails resourceDetails,
String resourceVersion, User user) {
return convertToAuditObject(resourceDetails, resourceVersion, user.getUserId(), user.getFullName());
}
private static ExpectedResourceAuditJavaObject convertToAuditObject(ResourceReqDetails resourceDetails,
String resourceVersion, String userId, String userName) {
ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
expectedResourceAuditJavaObject.setAction("Checkout");
expectedResourceAuditJavaObject.setModifierName(userName);
expectedResourceAuditJavaObject.setModifierUid(userId);
expectedResourceAuditJavaObject.setStatus("200.0");
expectedResourceAuditJavaObject.setDesc("OK");
expectedResourceAuditJavaObject.setResourceName(resourceDetails.getName());
expectedResourceAuditJavaObject.setResourceType("Resource");
expectedResourceAuditJavaObject.setPrevVersion(String.valueOf(Float.parseFloat(resourceVersion) - 0.1f));
expectedResourceAuditJavaObject.setCurrVersion(resourceVersion);
expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
expectedResourceAuditJavaObject.setComment(null);
return expectedResourceAuditJavaObject;
}
public static ExpectedProductAudit constructFieldsForAuditValidation(Product productDetails, String action,
User user, ActionStatus actionStatus, String prevVersion, String currVersion, LifecycleStateEnum prevState,
LifecycleStateEnum currState, String uuid, String... errorMessageParams) throws FileNotFoundException {
ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(actionStatus.name());
return convertToAuditObject(productDetails, action, user, errorInfo, prevVersion, currVersion, prevState,
currState, uuid, errorMessageParams);
}
private static ExpectedProductAudit convertToAuditObject(Product productDetails, String action, User user,
ErrorInfo errorInfo, String prevVersion, String currVersion, LifecycleStateEnum prevState,
LifecycleStateEnum currState, String uuid, String... errorMessageParams) {
ExpectedProductAudit expectedProductAudit = new ExpectedProductAudit();
expectedProductAudit.setACTION(action);
String userUserId = user.getUserId();
String userFullName;
if (StringUtils.isEmpty(user.getFirstName()) && StringUtils.isEmpty(user.getLastName())) {
userFullName = "";
} else {
userFullName = user.getFullName();
}
if (StringUtils.isEmpty(userUserId)) {
userUserId = "UNKNOWN";
}
expectedProductAudit.setMODIFIER(
!StringUtils.isEmpty(userFullName) ? userFullName + "(" + userUserId + ")" : "(" + userUserId + ")");
expectedProductAudit.setSTATUS(Integer.toString(errorInfo.getCode()));
expectedProductAudit.setDESC(errorInfo.getAuditDesc((Object[]) (errorMessageParams)));
expectedProductAudit
.setRESOURCE_NAME(productDetails != null ? productDetails.getName() : Constants.EMPTY_STRING);
expectedProductAudit.setRESOURCE_TYPE("Product");
expectedProductAudit.setPREV_VERSION(prevVersion);
expectedProductAudit.setCURR_VERSION(currVersion);
expectedProductAudit.setPREV_STATE(prevState != null ? prevState.name() : Constants.EMPTY_STRING);
expectedProductAudit.setCURR_STATE(currState != null ? currState.name() : Constants.EMPTY_STRING);
expectedProductAudit.setSERVICE_INSTANCE_ID(uuid);
return expectedProductAudit;
}
////////////////
// Convertor.constructFieldsForAuditValidationSuccess(addUser,
//////////////// sdncAdminUser, mechIdUser, null, STATUS_CODE_CREATED);
public static ExpectedUserCRUDAudit constructFieldsForAuditValidation(String action, User userModifier,
ActionStatus actionStatus, User userAfter, User userBefore, Object... variables) throws Exception {
ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(actionStatus.name());
ExpectedUserCRUDAudit expectedAddUserAuditJavaObject = new ExpectedUserCRUDAudit();
expectedAddUserAuditJavaObject.setAction(action);
expectedAddUserAuditJavaObject.setModifier(
userModifier.getFirstName() != null ? userModifier.getFullName() + "(" + userModifier.getUserId() + ")"
: "(" + userModifier.getUserId() + ")");
String status = Integer.toString(errorInfo.getCode());
expectedAddUserAuditJavaObject.setStatus(status);
if (errorInfo.getCode() == STATUS_CODE_SUCCESS || errorInfo.getCode() == STATUS_CODE_CREATED) {
expectedAddUserAuditJavaObject.setDesc("OK");
} else {
expectedAddUserAuditJavaObject.setDesc(errorInfo.getAuditDesc(variables));
}
expectedAddUserAuditJavaObject.setUserBefore(userBefore != null
? userBefore.getUserId() + ", " + userBefore.getFirstName() + " " + userBefore.getLastName() + ", "
+ userBefore.getEmail() + ", " + userBefore.getRole()
: Constants.EMPTY_STRING);
expectedAddUserAuditJavaObject.setUserAfter(userAfter != null
? userAfter.getUserId() + ", " + userAfter.getFirstName() + " " + userAfter.getLastName() + ", "
+ userAfter.getEmail() + ", " + userAfter.getRole()
: Constants.EMPTY_STRING);
return expectedAddUserAuditJavaObject;
}
// For RESOURCE and SERVICE same Audit
public static ExpectedResourceAuditJavaObject constructFieldsForAuditValidation(
ComponentReqDetails componentDetails, String action, User userModifier, ActionStatus actionStatus,
String currVersion, String prevVersion, String curState, String prevState, String uuid, String comment,
Object... variables) throws Exception {
ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(actionStatus.name());
ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
expectedResourceAuditJavaObject.setAction(action);
expectedResourceAuditJavaObject.setMODIFIER(
userModifier.getFirstName() != null ? userModifier.getFullName() + "(" + userModifier.getUserId() + ")"
: "(" + userModifier.getUserId() + ")");
String status = Integer.toString(errorInfo.getCode());
expectedResourceAuditJavaObject.setStatus(status);
if (errorInfo.getCode() == STATUS_CODE_SUCCESS || errorInfo.getCode() == STATUS_CODE_CREATED) {
expectedResourceAuditJavaObject.setDesc("OK");
} else {
expectedResourceAuditJavaObject.setDesc(errorInfo.getAuditDesc(variables));
}
expectedResourceAuditJavaObject.setCurrState(curState);
expectedResourceAuditJavaObject.setPrevState(prevState);
expectedResourceAuditJavaObject.setCurrVersion(currVersion);
expectedResourceAuditJavaObject.setPrevVersion(prevVersion);
expectedResourceAuditJavaObject.setComment(comment);
expectedResourceAuditJavaObject.setSERVICE_INSTANCE_ID(uuid);
if (componentDetails instanceof ServiceReqDetails) {
expectedResourceAuditJavaObject.setResourceName(((ServiceReqDetails) componentDetails).getName());
expectedResourceAuditJavaObject.setResourceType("Service");
}
if (componentDetails instanceof ResourceReqDetails) {
expectedResourceAuditJavaObject.setResourceName(((ResourceReqDetails) componentDetails).getName());
expectedResourceAuditJavaObject.setResourceType("Resource");
}
return expectedResourceAuditJavaObject;
}
// Distribution Service Audit
public static ExpectedResourceAuditJavaObject constructFieldsForDistributionAuditValidation(
ComponentReqDetails componentDetails, String action, User userModifier, ActionStatus actionStatus,
String currVersion, String distCurrStatus, String distProvStatus, String curState, String uuid,
String comment, Object... variables) throws Exception {
ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(actionStatus.name());
ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
expectedResourceAuditJavaObject.setAction(action);
expectedResourceAuditJavaObject.setMODIFIER(
userModifier.getFirstName() != null ? userModifier.getFullName() + "(" + userModifier.getUserId() + ")"
: "(" + userModifier.getUserId() + ")");
String status = Integer.toString(errorInfo.getCode());
expectedResourceAuditJavaObject.setStatus(status);
if (errorInfo.getCode() == STATUS_CODE_SUCCESS || errorInfo.getCode() == STATUS_CODE_CREATED) {
expectedResourceAuditJavaObject.setDesc("OK");
} else {
expectedResourceAuditJavaObject.setDesc(errorInfo.getAuditDesc(variables));
}
expectedResourceAuditJavaObject.setCurrState(curState);
expectedResourceAuditJavaObject.setCurrVersion(currVersion);
expectedResourceAuditJavaObject.setDcurrStatus(distCurrStatus);
expectedResourceAuditJavaObject.setDprevStatus(distProvStatus);
expectedResourceAuditJavaObject.setComment(comment);
expectedResourceAuditJavaObject.setSERVICE_INSTANCE_ID(uuid);
if (componentDetails instanceof ServiceReqDetails) {
expectedResourceAuditJavaObject.setResourceName(((ServiceReqDetails) componentDetails).getName());
expectedResourceAuditJavaObject.setResourceType("Service");
}
return expectedResourceAuditJavaObject;
}
}
|