Added oparent to sdc main
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / InterfaceOperationsRestUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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 com.google.gson.Gson;
24 import java.io.IOException;
25 import java.util.Map;
26 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
27 import org.openecomp.sdc.be.model.Component;
28 import org.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.ci.tests.api.Urls;
30 import org.openecomp.sdc.ci.tests.config.Config;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.utils.Utils;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class InterfaceOperationsRestUtils extends BaseRestUtils {
37
38     @SuppressWarnings("unused")
39     private static Logger logger = LoggerFactory.getLogger(InterfaceOperationsRestUtils.class.getName());
40
41     public static RestResponse addInterfaceOperations(Component component, Map<String, Object> interfaceDefinitionMap,
42             User user) throws IOException {
43         Config config = Utils.getConfig();
44         String url = String.format(Urls.ADD_INTERFACE_OPERATIONS, config.getCatalogBeHost(), config.getCatalogBePort(),
45                 ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId());
46         String jsonBody = new Gson().toJson(interfaceDefinitionMap);
47         return sendPost(url, jsonBody, user.getUserId(), acceptHeaderData);
48     }
49
50     public static RestResponse updateInterfaceOperations(Component component,
51             Map<String, Object> interfaceDefinitionMap, User user) throws IOException {
52         Config config = Utils.getConfig();
53         String url =
54                 String.format(Urls.UPDATE_INTERFACE_OPERATIONS, config.getCatalogBeHost(), config.getCatalogBePort(),
55                         ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId());
56         String jsonBody = new Gson().toJson(interfaceDefinitionMap);
57         return sendPut(url, jsonBody, user.getUserId(), acceptHeaderData);
58     }
59
60     public static RestResponse getInterfaceOperations(Component component, String interfaceId, String operationIds,
61             User user) throws IOException {
62         Config config = Utils.getConfig();
63         String url = String.format(Urls.GET_INTERFACE_OPERATIONS, config.getCatalogBeHost(), config.getCatalogBePort(),
64                 ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId(), interfaceId,
65                 operationIds);
66         return sendGet(url, user.getUserId());
67     }
68
69     public static RestResponse deleteInterfaceOperations(Component component, String interfaceId, String operationIds,
70             User user) throws IOException {
71         Config config = Utils.getConfig();
72         String url =
73                 String.format(Urls.DELETE_INTERFACE_OPERATIONS, config.getCatalogBeHost(), config.getCatalogBePort(),
74                         ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId(),
75                         interfaceId, operationIds);
76         return sendDelete(url, user.getUserId());
77     }
78
79 }