2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.rest;
25 import org.openecomp.sdc.be.model.User;
26 import org.openecomp.sdc.ci.tests.api.Urls;
27 import org.openecomp.sdc.ci.tests.config.Config;
28 import org.openecomp.sdc.ci.tests.datatypes.ResourceExternalReqDetails;
29 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
30 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
32 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
33 import org.openecomp.sdc.ci.tests.utils.Utils;
34 import org.openecomp.sdc.common.util.GeneralUtility;
36 import com.google.gson.Gson;
38 public class ResourceRestUtilsExternalAPI extends BaseRestUtils {
40 public static RestResponse createResource(ResourceExternalReqDetails resourceDetails, User sdncModifierDetails)
43 Config config = Utils.getConfig();
44 String url = String.format(Urls.POST_EXTERNAL_API_CREATE_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort());
46 String userId = sdncModifierDetails.getUserId();
47 Map<String, String> headersMap = prepareHeadersMap(userId);
49 Gson gson = new Gson();
50 String userBodyJson = gson.toJson(resourceDetails);
51 String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(userBodyJson);
52 headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), calculateMD5);
53 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
54 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
55 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
57 HttpRequest http = new HttpRequest();
58 RestResponse createResourceResponse = http.httpSendPost(url, userBodyJson, headersMap);
60 return createResourceResponse;