2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.utils.general;
23 import com.aventstack.extentreports.Status;
24 import org.json.JSONObject;
25 import org.openecomp.sdc.be.model.User;
26 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
27 import org.openecomp.sdc.ci.tests.api.Urls;
28 import org.openecomp.sdc.ci.tests.config.Config;
29 import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
30 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.utils.Utils;
33 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
35 import java.util.Arrays;
38 import static org.testng.AssertJUnit.assertEquals;
40 public class VendorLicenseModelRestUtils {
42 public static void updateVendorLicense(VendorLicenseModel vendorLicenseModel, User user, Boolean isVlmUpdated) throws Exception {
44 // create major method
45 RestResponse creationMethodVendorLicense = creationMethodVendorLicense(vendorLicenseModel, user);
46 assertEquals("did not succeed to create method for vendor license", 200, creationMethodVendorLicense.getErrorCode().intValue());
48 .setVersion(ResponseParser.getValueFromJsonResponse(creationMethodVendorLicense.getResponse(), "id"));
51 // TODO update vlm do nothing
53 RestResponse commitVendorLicense = commitVendorLicense(vendorLicenseModel, user);
54 assertEquals("did not succeed to commit vendor license", 200, commitVendorLicense.getErrorCode().intValue());
58 RestResponse submitVendorLicense = submitVendorLicense(vendorLicenseModel, user);
59 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
61 if(ComponentBaseTest.getExtendTest() != null){
62 ComponentBaseTest.getExtendTest().log(Status.INFO, "Succeeded in updating the vendor license");
66 private static RestResponse getVLMComponentByVersion(String vlmId, String vlmVersion, User user) throws Exception{
67 Config config = Utils.getConfig();
68 String url = String.format(Urls.GET_VLM_COMPONENT_BY_VERSION, config.getOnboardingBeHost(),config.getOnboardingBePort(), vlmId,vlmVersion);
69 String userId = user.getUserId();
71 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
73 HttpRequest http = new HttpRequest();
74 RestResponse response = http.httpSendGet(url, headersMap);
78 public static boolean validateVlmExist(String vlmId, String vlmVersion, User user) throws Exception {
79 RestResponse restResponse = getVLMComponentByVersion(vlmId, vlmVersion, user);
80 assertEquals(String.format("VLM version not updated, reponse code message: %s", restResponse.getResponse()),restResponse.getErrorCode().intValue(),200);
81 return (restResponse.getErrorCode()==200);
84 public static VendorLicenseModel createVendorLicense(User user) throws Exception {
86 VendorLicenseModel vendorLicenseModel;
87 // ComponentBaseTest.getExtendTest().log(Status.INFO, "Starting to create the vendor license");
88 String vendorLicenseName = "ciLicense" + OnboardingUtils.getShortUUID();
89 RestResponse vendorLicenseResponse = createVendorLicenseModels_1(vendorLicenseName, user);
90 assertEquals("did not succeed to create vendor license model", 200, vendorLicenseResponse.getErrorCode().intValue());
91 String vendorId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "itemId");
92 String versionId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "version:id");
94 RestResponse vendorKeyGroupsResponse = createVendorKeyGroups_2(vendorId, versionId, user);
95 assertEquals("did not succeed to create vendor key groups", 200, vendorKeyGroupsResponse.getErrorCode().intValue());
96 String keyGroupId = ResponseParser.getValueFromJsonResponse(vendorKeyGroupsResponse.getResponse(), "value");
98 RestResponse vendorEntitlementPool = createVendorEntitlementPool_3(vendorId, versionId, user);
99 assertEquals("did not succeed to create vendor entitlement pool", 200, vendorEntitlementPool.getErrorCode().intValue());
100 String entitlementPoolId = ResponseParser.getValueFromJsonResponse(vendorEntitlementPool.getResponse(), "value");
102 RestResponse vendorLicenseFeatureGroups = createVendorLicenseFeatureGroups_4(vendorId, versionId, keyGroupId, entitlementPoolId, user);
103 assertEquals("did not succeed to create vendor license feature groups", 200, vendorLicenseFeatureGroups.getErrorCode().intValue());
104 String featureGroupId = ResponseParser.getValueFromJsonResponse(vendorLicenseFeatureGroups.getResponse(), "value");
106 RestResponse vendorLicenseAgreement = createVendorLicenseAgreement_5(vendorId, versionId, featureGroupId, user);
107 assertEquals("did not succeed to create vendor license agreement", 200, vendorLicenseAgreement.getErrorCode().intValue());
108 String vendorLicenseAgreementId = ResponseParser.getValueFromJsonResponse(vendorLicenseAgreement.getResponse(), "value");
110 // RestResponse checkinVendorLicense = OnboardingUtils.checkinVendorLicense(vendorId, user, versionId);
111 // assertEquals("did not succeed to checkin vendor license", 200, checkinVendorLicense.getErrorCode().intValue());
113 vendorLicenseModel = new VendorLicenseModel(vendorId, vendorLicenseName, vendorLicenseAgreementId, featureGroupId);
114 vendorLicenseModel.setVersion(versionId); // Once object created and submitted, his initial version is 1.0
116 RestResponse submitVendorLicense = submitVendorLicense(vendorLicenseModel, user);
117 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
119 // ComponentBaseTest.getExtendTest().log(Status.INFO, "Succeeded in creating the vendor license");
121 return vendorLicenseModel;
124 private static RestResponse actionOnComponent(String vspid, String body, String onboardComponent, User user, String componentVersion) throws Exception {
125 Config config = Utils.getConfig();
126 String url = String.format(Urls.ACTION_ON_COMPONENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vspid, componentVersion);
127 String userId = user.getUserId();
128 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
130 HttpRequest http = new HttpRequest();
131 RestResponse response = http.httpSendPut(url, body, headersMap);
135 private static RestResponse createMethodVendorLicense(String vendorId, String body, String onboardComponent, User user, String componentVersion) throws Exception {
136 Config config = Utils.getConfig();
137 String url = String.format(Urls.CREATE_METHOD, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vendorId, componentVersion);
138 String userId = user.getUserId();
139 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
141 HttpRequest http = new HttpRequest();
142 RestResponse response = http.httpSendPost(url, body, headersMap);
146 public static RestResponse submitVendorLicense(VendorLicenseModel vendorLicenseModel, User user) throws Exception {
147 return actionOnComponent(vendorLicenseModel.getVendorId(), "{\"action\":\"Submit\"}", "vendor-license-models", user, vendorLicenseModel
152 * @param vendorLicenseModel
155 * checkOut exist VLM method
158 public static RestResponse creationMethodVendorLicense(VendorLicenseModel vendorLicenseModel, User user) throws Exception {
159 String messageBody = "{\"description\":\"2.0\",\"creationMethod\":\"major\"}";
160 return createMethodVendorLicense(vendorLicenseModel.getVendorId(), messageBody, "items", user, vendorLicenseModel
164 public static RestResponse commitVendorLicense(VendorLicenseModel vendorLicenseModel, User user) throws Exception {
165 String messageBody = "{\"action\":\"Commit\",\"commitRequest\":{\"message\":\"commit\"}}";
166 return actionOnComponent(vendorLicenseModel.getVendorId(), messageBody, "items", user, vendorLicenseModel.getVersion());
169 public static RestResponse createVendorLicenseModels_1(String name, User user) throws Exception {
170 Config config = Utils.getConfig();
171 String url = String.format(Urls.CREATE_VENDOR_LISENCE_MODELS, config.getOnboardingBeHost(), config.getOnboardingBePort());
172 String userId = user.getUserId();
174 JSONObject jObject = new JSONObject();
175 jObject.put("vendorName", name);
176 jObject.put("description", "new vendor license model");
177 jObject.put("iconRef", "icon");
179 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
181 HttpRequest http = new HttpRequest();
182 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
187 public static RestResponse createVendorLicenseAgreement_5(String vspid, String versionId, String featureGroupId, User user)
189 Config config = Utils.getConfig();
190 String url = String.format(Urls.CREATE_VENDOR_LISENCE_AGREEMENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
191 String userId = user.getUserId();
193 JSONObject licenseTermpObject = new JSONObject();
194 licenseTermpObject.put("choice", "Fixed_Term");
195 licenseTermpObject.put("other", "");
197 JSONObject jObjectBody = new JSONObject();
198 jObjectBody.put("name", "abc");
199 jObjectBody.put("description", "new vendor license agreement");
200 jObjectBody.put("requirementsAndConstrains", "abc");
201 jObjectBody.put("licenseTerm", licenseTermpObject);
202 jObjectBody.put("addedFeatureGroupsIds", Arrays.asList(featureGroupId).toArray());
204 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
206 HttpRequest http = new HttpRequest();
207 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
211 public static RestResponse createVendorLicenseFeatureGroups_4(String vspid, String versionId, String licenseKeyGroupId,
212 String entitlementPoolId, User user) throws Exception {
213 Config config = Utils.getConfig();
214 String url = String.format(Urls.CREATE_VENDOR_LISENCE_FEATURE_GROUPS, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
215 String userId = user.getUserId();
217 JSONObject jObject = new JSONObject();
218 jObject.put("name", "xyz");
219 jObject.put("description", "new vendor license feature groups");
220 jObject.put("partNumber", "123abc456");
221 // jObject.put("manufacturerReferenceNumber", "5");
222 jObject.put("addedLicenseKeyGroupsIds", Arrays.asList(licenseKeyGroupId).toArray());
223 jObject.put("addedEntitlementPoolsIds", Arrays.asList(entitlementPoolId).toArray());
225 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
227 HttpRequest http = new HttpRequest();
228 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
233 public static RestResponse createVendorEntitlementPool_3(String vspid, String versionId, User user) throws Exception {
234 Config config = Utils.getConfig();
235 String url = String.format(Urls.CREATE_VENDOR_LISENCE_ENTITLEMENT_POOL, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
236 String userId = user.getUserId();
238 JSONObject jEntitlementMetricObject = new JSONObject();
239 jEntitlementMetricObject.put("choice", "CPU");
240 jEntitlementMetricObject.put("other", "");
242 JSONObject jAggregationFunctionObject = new JSONObject();
243 jAggregationFunctionObject.put("choice", "Peak");
244 jAggregationFunctionObject.put("other", "");
246 JSONObject jOperationalScope = new JSONObject();
247 jOperationalScope.put("choices", Arrays.asList("Availability_Zone").toArray());
248 jOperationalScope.put("other", "");
250 JSONObject jTimeObject = new JSONObject();
251 jTimeObject.put("choice", "Hour");
252 jTimeObject.put("other", "");
254 JSONObject jObjectBody = new JSONObject();
255 jObjectBody.put("name", "def"+ OnboardingUtils.getShortUUID());
256 jObjectBody.put("description", "new vendor license entitlement pool");
257 jObjectBody.put("thresholdValue", "23");
258 jObjectBody.put("thresholdUnits", "Absolute");
259 jObjectBody.put("entitlementMetric", jEntitlementMetricObject);
260 jObjectBody.put("increments", "abcd");
261 jObjectBody.put("aggregationFunction", jAggregationFunctionObject);
262 jObjectBody.put("operationalScope", jOperationalScope);
263 jObjectBody.put("time", jTimeObject);
264 jObjectBody.put("manufacturerReferenceNumber", "123aaa");
266 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
268 HttpRequest http = new HttpRequest();
269 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
273 public static RestResponse createVendorKeyGroups_2(String vspid, String versionId, User user) throws Exception {
274 Config config = Utils.getConfig();
275 String url = String.format(Urls.CREATE_VENDOR_LISENCE_KEY_GROUPS, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
276 String userId = user.getUserId();
278 JSONObject jOperationalScope = new JSONObject();
279 jOperationalScope.put("choices", Arrays.asList("Tenant").toArray());
280 jOperationalScope.put("other", "");
282 JSONObject jObjectBody = new JSONObject();
283 jObjectBody.put("name", "keyGroup" + OnboardingUtils.getShortUUID());
284 jObjectBody.put("description", "new vendor license key group");
285 jObjectBody.put("operationalScope", jOperationalScope);
286 jObjectBody.put("type", "Universal");
288 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
290 HttpRequest http = new HttpRequest();
291 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
295 public static RestResponse validateUpload(String vspid, User user, String vspVersion) throws Exception {
297 Config config = Utils.getConfig();
298 String url = String.format(Urls.VALIDATE_UPLOAD, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid,vspVersion);
299 String userId = user.getUserId();
301 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
302 HttpRequest http = new HttpRequest();
303 RestResponse response = http.httpSendPut(url, body, headersMap);