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.AmdocsLicenseMembers;
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(AmdocsLicenseMembers amdocsLicenseMembers, User user, Boolean isVlmUpdated) throws Exception {
44 // create major method
45 RestResponse creationMethodVendorLicense = creationMethodVendorLicense(amdocsLicenseMembers, user);
46 assertEquals("did not succeed to create method for vendor license", 200, creationMethodVendorLicense.getErrorCode().intValue());
47 amdocsLicenseMembers.setVersion(ResponseParser.getValueFromJsonResponse(creationMethodVendorLicense.getResponse(), "id"));
50 // TODO update vlm do nothing
52 RestResponse commitVendorLicense = commitVendorLicense(amdocsLicenseMembers, user);
53 assertEquals("did not succeed to commit vendor license", 200, commitVendorLicense.getErrorCode().intValue());
57 RestResponse submitVendorLicense = submitVendorLicense(amdocsLicenseMembers, user);
58 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
60 if(ComponentBaseTest.getExtendTest() != null){
61 ComponentBaseTest.getExtendTest().log(Status.INFO, "Succeeded in updating the vendor license");
65 private static RestResponse getVLMComponentByVersion(String vlmId, String vlmVersion, User user) throws Exception{
66 Config config = Utils.getConfig();
67 String url = String.format(Urls.GET_VLM_COMPONENT_BY_VERSION, config.getOnboardingBeHost(),config.getOnboardingBePort(), vlmId,vlmVersion);
68 String userId = user.getUserId();
70 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
72 HttpRequest http = new HttpRequest();
73 RestResponse response = http.httpSendGet(url, headersMap);
77 public static boolean validateVlmExist(String vlmId, String vlmVersion, User user) throws Exception {
78 RestResponse restResponse = getVLMComponentByVersion(vlmId, vlmVersion, user);
79 assertEquals(String.format("VLM version not updated, reponse code message: %s", restResponse.getResponse()),restResponse.getErrorCode().intValue(),200);
80 return (restResponse.getErrorCode()==200);
83 public static AmdocsLicenseMembers createVendorLicense(User user) throws Exception {
85 AmdocsLicenseMembers amdocsLicenseMembers;
86 // ComponentBaseTest.getExtendTest().log(Status.INFO, "Starting to create the vendor license");
87 String vendorLicenseName = "ciLicense" + OnboardingUtils.getShortUUID();
88 RestResponse vendorLicenseResponse = createVendorLicenseModels_1(vendorLicenseName, user);
89 assertEquals("did not succeed to create vendor license model", 200, vendorLicenseResponse.getErrorCode().intValue());
90 String vendorId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "itemId");
91 String versionId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "version:id");
93 RestResponse vendorKeyGroupsResponse = createVendorKeyGroups_2(vendorId, versionId, user);
94 assertEquals("did not succeed to create vendor key groups", 200, vendorKeyGroupsResponse.getErrorCode().intValue());
95 String keyGroupId = ResponseParser.getValueFromJsonResponse(vendorKeyGroupsResponse.getResponse(), "value");
97 RestResponse vendorEntitlementPool = createVendorEntitlementPool_3(vendorId, versionId, user);
98 assertEquals("did not succeed to create vendor entitlement pool", 200, vendorEntitlementPool.getErrorCode().intValue());
99 String entitlementPoolId = ResponseParser.getValueFromJsonResponse(vendorEntitlementPool.getResponse(), "value");
101 RestResponse vendorLicenseFeatureGroups = createVendorLicenseFeatureGroups_4(vendorId, versionId, keyGroupId, entitlementPoolId, user);
102 assertEquals("did not succeed to create vendor license feature groups", 200, vendorLicenseFeatureGroups.getErrorCode().intValue());
103 String featureGroupId = ResponseParser.getValueFromJsonResponse(vendorLicenseFeatureGroups.getResponse(), "value");
105 RestResponse vendorLicenseAgreement = createVendorLicenseAgreement_5(vendorId, versionId, featureGroupId, user);
106 assertEquals("did not succeed to create vendor license agreement", 200, vendorLicenseAgreement.getErrorCode().intValue());
107 String vendorLicenseAgreementId = ResponseParser.getValueFromJsonResponse(vendorLicenseAgreement.getResponse(), "value");
109 // RestResponse checkinVendorLicense = OnboardingUtils.checkinVendorLicense(vendorId, user, versionId);
110 // assertEquals("did not succeed to checkin vendor license", 200, checkinVendorLicense.getErrorCode().intValue());
112 amdocsLicenseMembers = new AmdocsLicenseMembers(vendorId, vendorLicenseName, vendorLicenseAgreementId, featureGroupId);
113 amdocsLicenseMembers.setVersion(versionId); // Once object created and submitted, his initial version is 1.0
115 RestResponse submitVendorLicense = submitVendorLicense(amdocsLicenseMembers, user);
116 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
118 // ComponentBaseTest.getExtendTest().log(Status.INFO, "Succeeded in creating the vendor license");
120 return amdocsLicenseMembers;
123 private static RestResponse actionOnComponent(String vspid, String body, String onboardComponent, User user, String componentVersion) throws Exception {
124 Config config = Utils.getConfig();
125 String url = String.format(Urls.ACTION_ON_COMPONENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vspid, componentVersion);
126 String userId = user.getUserId();
127 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
129 HttpRequest http = new HttpRequest();
130 RestResponse response = http.httpSendPut(url, body, headersMap);
134 private static RestResponse createMethodVendorLicense(String vendorId, String body, String onboardComponent, User user, String componentVersion) throws Exception {
135 Config config = Utils.getConfig();
136 String url = String.format(Urls.CREATE_METHOD, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vendorId, componentVersion);
137 String userId = user.getUserId();
138 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
140 HttpRequest http = new HttpRequest();
141 RestResponse response = http.httpSendPost(url, body, headersMap);
145 public static RestResponse submitVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user) throws Exception {
146 return actionOnComponent(amdocsLicenseMembers.getVendorId(), "{\"action\":\"Submit\"}", "vendor-license-models", user, amdocsLicenseMembers.getVersion());
150 * @param amdocsLicenseMembers
153 * checkOut exist VLM method
156 public static RestResponse creationMethodVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user) throws Exception {
157 String messageBody = "{\"description\":\"2.0\",\"creationMethod\":\"major\"}";
158 return createMethodVendorLicense(amdocsLicenseMembers.getVendorId(), messageBody, "items", user, amdocsLicenseMembers.getVersion());
161 public static RestResponse commitVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user) throws Exception {
162 String messageBody = "{\"action\":\"Commit\",\"commitRequest\":{\"message\":\"commit\"}}";
163 return actionOnComponent(amdocsLicenseMembers.getVendorId(), messageBody, "items", user, amdocsLicenseMembers.getVersion());
166 public static RestResponse createVendorLicenseModels_1(String name, User user) throws Exception {
167 Config config = Utils.getConfig();
168 String url = String.format(Urls.CREATE_VENDOR_LISENCE_MODELS, config.getOnboardingBeHost(), config.getOnboardingBePort());
169 String userId = user.getUserId();
171 JSONObject jObject = new JSONObject();
172 jObject.put("vendorName", name);
173 jObject.put("description", "new vendor license model");
174 jObject.put("iconRef", "icon");
176 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
178 HttpRequest http = new HttpRequest();
179 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
184 public static RestResponse createVendorLicenseAgreement_5(String vspid, String versionId, String featureGroupId, User user)
186 Config config = Utils.getConfig();
187 String url = String.format(Urls.CREATE_VENDOR_LISENCE_AGREEMENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
188 String userId = user.getUserId();
190 JSONObject licenseTermpObject = new JSONObject();
191 licenseTermpObject.put("choice", "Fixed_Term");
192 licenseTermpObject.put("other", "");
194 JSONObject jObjectBody = new JSONObject();
195 jObjectBody.put("name", "abc");
196 jObjectBody.put("description", "new vendor license agreement");
197 jObjectBody.put("requirementsAndConstrains", "abc");
198 jObjectBody.put("licenseTerm", licenseTermpObject);
199 jObjectBody.put("addedFeatureGroupsIds", Arrays.asList(featureGroupId).toArray());
201 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
203 HttpRequest http = new HttpRequest();
204 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
208 public static RestResponse createVendorLicenseFeatureGroups_4(String vspid, String versionId, String licenseKeyGroupId,
209 String entitlementPoolId, User user) throws Exception {
210 Config config = Utils.getConfig();
211 String url = String.format(Urls.CREATE_VENDOR_LISENCE_FEATURE_GROUPS, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
212 String userId = user.getUserId();
214 JSONObject jObject = new JSONObject();
215 jObject.put("name", "xyz");
216 jObject.put("description", "new vendor license feature groups");
217 jObject.put("partNumber", "123abc456");
218 // jObject.put("manufacturerReferenceNumber", "5");
219 jObject.put("addedLicenseKeyGroupsIds", Arrays.asList(licenseKeyGroupId).toArray());
220 jObject.put("addedEntitlementPoolsIds", Arrays.asList(entitlementPoolId).toArray());
222 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
224 HttpRequest http = new HttpRequest();
225 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
230 public static RestResponse createVendorEntitlementPool_3(String vspid, String versionId, User user) throws Exception {
231 Config config = Utils.getConfig();
232 String url = String.format(Urls.CREATE_VENDOR_LISENCE_ENTITLEMENT_POOL, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
233 String userId = user.getUserId();
235 JSONObject jEntitlementMetricObject = new JSONObject();
236 jEntitlementMetricObject.put("choice", "CPU");
237 jEntitlementMetricObject.put("other", "");
239 JSONObject jAggregationFunctionObject = new JSONObject();
240 jAggregationFunctionObject.put("choice", "Peak");
241 jAggregationFunctionObject.put("other", "");
243 JSONObject jOperationalScope = new JSONObject();
244 jOperationalScope.put("choices", Arrays.asList("Availability_Zone").toArray());
245 jOperationalScope.put("other", "");
247 JSONObject jTimeObject = new JSONObject();
248 jTimeObject.put("choice", "Hour");
249 jTimeObject.put("other", "");
251 JSONObject jObjectBody = new JSONObject();
252 jObjectBody.put("name", "def"+ OnboardingUtils.getShortUUID());
253 jObjectBody.put("description", "new vendor license entitlement pool");
254 jObjectBody.put("thresholdValue", "23");
255 jObjectBody.put("thresholdUnits", "Absolute");
256 jObjectBody.put("entitlementMetric", jEntitlementMetricObject);
257 jObjectBody.put("increments", "abcd");
258 jObjectBody.put("aggregationFunction", jAggregationFunctionObject);
259 jObjectBody.put("operationalScope", jOperationalScope);
260 jObjectBody.put("time", jTimeObject);
261 jObjectBody.put("manufacturerReferenceNumber", "123aaa");
263 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
265 HttpRequest http = new HttpRequest();
266 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
270 public static RestResponse createVendorKeyGroups_2(String vspid, String versionId, User user) throws Exception {
271 Config config = Utils.getConfig();
272 String url = String.format(Urls.CREATE_VENDOR_LISENCE_KEY_GROUPS, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
273 String userId = user.getUserId();
275 JSONObject jOperationalScope = new JSONObject();
276 jOperationalScope.put("choices", Arrays.asList("Tenant").toArray());
277 jOperationalScope.put("other", "");
279 JSONObject jObjectBody = new JSONObject();
280 jObjectBody.put("name", "keyGroup" + OnboardingUtils.getShortUUID());
281 jObjectBody.put("description", "new vendor license key group");
282 jObjectBody.put("operationalScope", jOperationalScope);
283 jObjectBody.put("type", "Universal");
285 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
287 HttpRequest http = new HttpRequest();
288 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
292 public static RestResponse validateUpload(String vspid, User user, String vspVersion) throws Exception {
294 Config config = Utils.getConfig();
295 String url = String.format(Urls.VALIDATE_UPLOAD, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid,vspVersion);
296 String userId = user.getUserId();
298 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
299 HttpRequest http = new HttpRequest();
300 RestResponse response = http.httpSendPut(url, body, headersMap);