1 package org.openecomp.sdc.ci.tests.utils.general;
3 import com.aventstack.extentreports.Status;
4 import org.json.JSONObject;
5 import org.openecomp.sdc.be.model.User;
6 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
7 import org.openecomp.sdc.ci.tests.api.Urls;
8 import org.openecomp.sdc.ci.tests.config.Config;
9 import org.openecomp.sdc.ci.tests.datatypes.AmdocsLicenseMembers;
10 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
11 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
12 import org.openecomp.sdc.ci.tests.utils.Utils;
13 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
15 import java.util.Arrays;
18 import static org.testng.AssertJUnit.assertEquals;
20 public class VendorLicenseModelRestUtils {
22 public static void updateVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user, Boolean isVlmUpdated) throws Exception {
24 // create major method
25 RestResponse creationMethodVendorLicense = creationMethodVendorLicense(amdocsLicenseMembers, user);
26 assertEquals("did not succeed to create method for vendor license", 200, creationMethodVendorLicense.getErrorCode().intValue());
27 amdocsLicenseMembers.setVersion(ResponseParser.getValueFromJsonResponse(creationMethodVendorLicense.getResponse(), "id"));
30 // TODO update vlm do nothing
32 RestResponse commitVendorLicense = commitVendorLicense(amdocsLicenseMembers, user);
33 assertEquals("did not succeed to commit vendor license", 200, commitVendorLicense.getErrorCode().intValue());
37 RestResponse submitVendorLicense = submitVendorLicense(amdocsLicenseMembers, user);
38 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
40 if(ComponentBaseTest.getExtendTest() != null){
41 ComponentBaseTest.getExtendTest().log(Status.INFO, "Succeeded in updating the vendor license");
45 private static RestResponse getVLMComponentByVersion(String vlmId, String vlmVersion, User user) throws Exception{
46 Config config = Utils.getConfig();
47 String url = String.format(Urls.GET_VLM_COMPONENT_BY_VERSION, config.getOnboardingBeHost(),config.getOnboardingBePort(), vlmId,vlmVersion);
48 String userId = user.getUserId();
50 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
52 HttpRequest http = new HttpRequest();
53 RestResponse response = http.httpSendGet(url, headersMap);
57 public static boolean validateVlmExist(String vlmId, String vlmVersion, User user) throws Exception {
58 RestResponse restResponse = getVLMComponentByVersion(vlmId, vlmVersion, user);
59 assertEquals(String.format("VLM version not updated, reponse code message: %s", restResponse.getResponse()),restResponse.getErrorCode().intValue(),200);
60 return (restResponse.getErrorCode()==200);
63 public static AmdocsLicenseMembers createVendorLicense(User user) throws Exception {
65 AmdocsLicenseMembers amdocsLicenseMembers;
66 // ComponentBaseTest.getExtendTest().log(Status.INFO, "Starting to create the vendor license");
67 String vendorLicenseName = "ciLicense" + OnboardingUtils.getShortUUID();
68 RestResponse vendorLicenseResponse = createVendorLicenseModels_1(vendorLicenseName, user);
69 assertEquals("did not succeed to create vendor license model", 200, vendorLicenseResponse.getErrorCode().intValue());
70 String vendorId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "itemId");
71 String versionId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "version:id");
73 RestResponse vendorKeyGroupsResponse = createVendorKeyGroups_2(vendorId, versionId, user);
74 assertEquals("did not succeed to create vendor key groups", 200, vendorKeyGroupsResponse.getErrorCode().intValue());
75 String keyGroupId = ResponseParser.getValueFromJsonResponse(vendorKeyGroupsResponse.getResponse(), "value");
77 RestResponse vendorEntitlementPool = createVendorEntitlementPool_3(vendorId, versionId, user);
78 assertEquals("did not succeed to create vendor entitlement pool", 200, vendorEntitlementPool.getErrorCode().intValue());
79 String entitlementPoolId = ResponseParser.getValueFromJsonResponse(vendorEntitlementPool.getResponse(), "value");
81 RestResponse vendorLicenseFeatureGroups = createVendorLicenseFeatureGroups_4(vendorId, versionId, keyGroupId, entitlementPoolId, user);
82 assertEquals("did not succeed to create vendor license feature groups", 200, vendorLicenseFeatureGroups.getErrorCode().intValue());
83 String featureGroupId = ResponseParser.getValueFromJsonResponse(vendorLicenseFeatureGroups.getResponse(), "value");
85 RestResponse vendorLicenseAgreement = createVendorLicenseAgreement_5(vendorId, versionId, featureGroupId, user);
86 assertEquals("did not succeed to create vendor license agreement", 200, vendorLicenseAgreement.getErrorCode().intValue());
87 String vendorLicenseAgreementId = ResponseParser.getValueFromJsonResponse(vendorLicenseAgreement.getResponse(), "value");
89 // RestResponse checkinVendorLicense = OnboardingUtils.checkinVendorLicense(vendorId, user, versionId);
90 // assertEquals("did not succeed to checkin vendor license", 200, checkinVendorLicense.getErrorCode().intValue());
92 amdocsLicenseMembers = new AmdocsLicenseMembers(vendorId, vendorLicenseName, vendorLicenseAgreementId, featureGroupId);
93 amdocsLicenseMembers.setVersion(versionId); // Once object created and submitted, his initial version is 1.0
95 RestResponse submitVendorLicense = submitVendorLicense(amdocsLicenseMembers, user);
96 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
98 // ComponentBaseTest.getExtendTest().log(Status.INFO, "Succeeded in creating the vendor license");
100 return amdocsLicenseMembers;
103 private static RestResponse actionOnComponent(String vspid, String body, String onboardComponent, User user, String componentVersion) throws Exception {
104 Config config = Utils.getConfig();
105 String url = String.format(Urls.ACTION_ON_COMPONENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vspid, componentVersion);
106 String userId = user.getUserId();
107 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
109 HttpRequest http = new HttpRequest();
110 RestResponse response = http.httpSendPut(url, body, headersMap);
114 private static RestResponse createMethodVendorLicense(String vendorId, String body, String onboardComponent, User user, String componentVersion) throws Exception {
115 Config config = Utils.getConfig();
116 String url = String.format(Urls.CREATE_METHOD, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vendorId, componentVersion);
117 String userId = user.getUserId();
118 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
120 HttpRequest http = new HttpRequest();
121 RestResponse response = http.httpSendPost(url, body, headersMap);
125 public static RestResponse submitVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user) throws Exception {
126 return actionOnComponent(amdocsLicenseMembers.getVendorId(), "{\"action\":\"Submit\"}", "vendor-license-models", user, amdocsLicenseMembers.getVersion());
130 * @param amdocsLicenseMembers
133 * checkOut exist VLM method
136 public static RestResponse creationMethodVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user) throws Exception {
137 String messageBody = "{\"description\":\"2.0\",\"creationMethod\":\"major\"}";
138 return createMethodVendorLicense(amdocsLicenseMembers.getVendorId(), messageBody, "items", user, amdocsLicenseMembers.getVersion());
141 public static RestResponse commitVendorLicense(AmdocsLicenseMembers amdocsLicenseMembers, User user) throws Exception {
142 String messageBody = "{\"action\":\"Commit\",\"commitRequest\":{\"message\":\"commit\"}}";
143 return actionOnComponent(amdocsLicenseMembers.getVendorId(), messageBody, "items", user, amdocsLicenseMembers.getVersion());
146 public static RestResponse createVendorLicenseModels_1(String name, User user) throws Exception {
147 Config config = Utils.getConfig();
148 String url = String.format(Urls.CREATE_VENDOR_LISENCE_MODELS, config.getOnboardingBeHost(), config.getOnboardingBePort());
149 String userId = user.getUserId();
151 JSONObject jObject = new JSONObject();
152 jObject.put("vendorName", name);
153 jObject.put("description", "new vendor license model");
154 jObject.put("iconRef", "icon");
156 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
158 HttpRequest http = new HttpRequest();
159 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
164 public static RestResponse createVendorLicenseAgreement_5(String vspid, String versionId, String featureGroupId, User user)
166 Config config = Utils.getConfig();
167 String url = String.format(Urls.CREATE_VENDOR_LISENCE_AGREEMENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
168 String userId = user.getUserId();
170 JSONObject licenseTermpObject = new JSONObject();
171 licenseTermpObject.put("choice", "Fixed_Term");
172 licenseTermpObject.put("other", "");
174 JSONObject jObjectBody = new JSONObject();
175 jObjectBody.put("name", "abc");
176 jObjectBody.put("description", "new vendor license agreement");
177 jObjectBody.put("requirementsAndConstrains", "abc");
178 jObjectBody.put("licenseTerm", licenseTermpObject);
179 jObjectBody.put("addedFeatureGroupsIds", Arrays.asList(featureGroupId).toArray());
181 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
183 HttpRequest http = new HttpRequest();
184 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
188 public static RestResponse createVendorLicenseFeatureGroups_4(String vspid, String versionId, String licenseKeyGroupId,
189 String entitlementPoolId, User user) throws Exception {
190 Config config = Utils.getConfig();
191 String url = String.format(Urls.CREATE_VENDOR_LISENCE_FEATURE_GROUPS, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
192 String userId = user.getUserId();
194 JSONObject jObject = new JSONObject();
195 jObject.put("name", "xyz");
196 jObject.put("description", "new vendor license feature groups");
197 jObject.put("partNumber", "123abc456");
198 jObject.put("manufacturerReferenceNumber", "5");
199 jObject.put("addedLicenseKeyGroupsIds", Arrays.asList(licenseKeyGroupId).toArray());
200 jObject.put("addedEntitlementPoolsIds", Arrays.asList(entitlementPoolId).toArray());
202 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
204 HttpRequest http = new HttpRequest();
205 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
210 public static RestResponse createVendorEntitlementPool_3(String vspid, String versionId, User user) throws Exception {
211 Config config = Utils.getConfig();
212 String url = String.format(Urls.CREATE_VENDOR_LISENCE_ENTITLEMENT_POOL, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
213 String userId = user.getUserId();
215 JSONObject jEntitlementMetricObject = new JSONObject();
216 jEntitlementMetricObject.put("choice", "CPU");
217 jEntitlementMetricObject.put("other", "");
219 JSONObject jAggregationFunctionObject = new JSONObject();
220 jAggregationFunctionObject.put("choice", "Peak");
221 jAggregationFunctionObject.put("other", "");
223 JSONObject jOperationalScope = new JSONObject();
224 jOperationalScope.put("choices", Arrays.asList("Availability_Zone").toArray());
225 jOperationalScope.put("other", "");
227 JSONObject jTimeObject = new JSONObject();
228 jTimeObject.put("choice", "Hour");
229 jTimeObject.put("other", "");
231 JSONObject jObjectBody = new JSONObject();
232 jObjectBody.put("name", "def"+ OnboardingUtils.getShortUUID());
233 jObjectBody.put("description", "new vendor license entitlement pool");
234 jObjectBody.put("thresholdValue", "23");
235 jObjectBody.put("thresholdUnits", "Absolute");
236 jObjectBody.put("entitlementMetric", jEntitlementMetricObject);
237 jObjectBody.put("increments", "abcd");
238 jObjectBody.put("aggregationFunction", jAggregationFunctionObject);
239 jObjectBody.put("operationalScope", jOperationalScope);
240 jObjectBody.put("time", jTimeObject);
241 jObjectBody.put("manufacturerReferenceNumber", "123aaa");
243 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
245 HttpRequest http = new HttpRequest();
246 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
250 public static RestResponse createVendorKeyGroups_2(String vspid, String versionId, User user) throws Exception {
251 Config config = Utils.getConfig();
252 String url = String.format(Urls.CREATE_VENDOR_LISENCE_KEY_GROUPS, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid, versionId);
253 String userId = user.getUserId();
255 JSONObject jOperationalScope = new JSONObject();
256 jOperationalScope.put("choices", Arrays.asList("Tenant").toArray());
257 jOperationalScope.put("other", "");
259 JSONObject jObjectBody = new JSONObject();
260 jObjectBody.put("name", "keyGroup" + OnboardingUtils.getShortUUID());
261 jObjectBody.put("description", "new vendor license key group");
262 jObjectBody.put("operationalScope", jOperationalScope);
263 jObjectBody.put("type", "Universal");
265 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
267 HttpRequest http = new HttpRequest();
268 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
272 public static RestResponse validateUpload(String vspid, User user, String vspVersion) throws Exception {
274 Config config = Utils.getConfig();
275 String url = String.format(Urls.VALIDATE_UPLOAD, config.getOnboardingBeHost(), config.getOnboardingBePort(), vspid,vspVersion);
276 String userId = user.getUserId();
278 Map<String, String> headersMap = OnboardingUtils.prepareHeadersMap(userId);
279 HttpRequest http = new HttpRequest();
280 RestResponse response = http.httpSendPut(url, body, headersMap);