re base code
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / ComponentRestUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.utils.rest;
22
23 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
24 import org.openecomp.sdc.be.model.CapReqDef;
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.ComponentReqDetails;
29 import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
30 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
31 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
33 import org.openecomp.sdc.ci.tests.utils.Utils;
34
35 import java.io.IOException;
36
37 public class ComponentRestUtils extends BaseRestUtils {
38         public static RestResponse getComponentRequirmentsCapabilities(User sdncModifierDetails,
39                         ComponentReqDetails componentReqDetails) throws IOException {
40                 Config config = Utils.getConfig();
41                 ComponentTypeEnum componentType = null;
42                 if (componentReqDetails instanceof ResourceReqDetails) {
43                         componentType = ComponentTypeEnum.RESOURCE;
44                 } else if (componentReqDetails instanceof ServiceReqDetails) {
45                         componentType = ComponentTypeEnum.SERVICE;
46                 } else if (componentReqDetails instanceof ProductReqDetails) {
47                         componentType = ComponentTypeEnum.PRODUCT;
48                 }
49                 String url = String.format(Urls.GET_COMPONENT_REQUIRMENTS_CAPABILITIES, config.getCatalogBeHost(),
50                                 config.getCatalogBePort(), ComponentTypeEnum.findParamByType(componentType),
51                                 componentReqDetails.getUniqueId());
52                 return sendGet(url, sdncModifierDetails.getUserId());
53         }
54
55         public static CapReqDef getAndParseComponentRequirmentsCapabilities(User user, ComponentReqDetails componentDetails)
56                         throws IOException {
57                 RestResponse getComponentReqCap = getComponentRequirmentsCapabilities(user, componentDetails);
58                 ResourceRestUtils.checkSuccess(getComponentReqCap);
59                 CapReqDef capReqDef = ResponseParser.parseToObject(getComponentReqCap.getResponse(), CapReqDef.class);
60                 return capReqDef;
61         }
62 }