re base code
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / InputsRestUtils.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 com.google.gson.Gson;
24 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
25 import org.openecomp.sdc.be.model.Component;
26 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
27 import org.openecomp.sdc.be.model.ComponentInstance;
28 import org.openecomp.sdc.ci.tests.api.Urls;
29 import org.openecomp.sdc.ci.tests.config.Config;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
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.general.ElementFactory;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 /**
38  * RestUtils for inputs
39  * 
40  * @author il0695
41  *
42  */
43 public class InputsRestUtils extends BaseRestUtils {
44
45         @SuppressWarnings("unused")
46         private static Logger logger = LoggerFactory.getLogger(InputsRestUtils.class.getName());
47         
48         /**
49          * Add inputs to service
50          * 
51          * @param component
52          * @param inputs
53          * @param userRole
54          * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
55          * @throws Exception
56          */
57         public static RestResponse addInput(Component component, ComponentInstInputsMap inputs, UserRoleEnum userRole) throws Exception {
58                 Config config = Utils.getConfig();
59                 String url = String.format(Urls.ADD_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(), ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUniqueId());
60                 String json = new Gson().toJson(inputs);
61                 return sendPost(url, json, userRole.getUserId(), acceptHeaderData);
62         }
63
64         /**
65          * Get all Component inputs
66          * 
67          * @param component
68          * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
69          * @throws Exception
70          */
71         public static RestResponse getComponentInputs(Component component) throws Exception {
72                 Config config = Utils.getConfig();
73                 //services/{componentId}/inputs
74                 String url = String.format(Urls.GET_COMPONENT_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(), component.getUniqueId());           
75                 return sendGet(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
76         }
77         
78         /**
79          * Get all inputs of component instance
80          * 
81          * @param parentComponent
82          * @param componentInstance
83          * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
84          * @throws Exception
85          */
86         public static RestResponse getComponentInstanceInputs(Component parentComponent, ComponentInstance componentInstance) throws Exception {
87                 Config config = Utils.getConfig();
88                 //{componentType}/{componentId}/componentInstances/{instanceId}/{originComonentUid}/inputs              
89                 String url = String.format(Urls.GET_COMPONENT_INSTANCE_INPUTS, config.getCatalogBeHost(), config.getCatalogBePort(), ComponentTypeEnum.findParamByType(parentComponent.getComponentType()), parentComponent.getUniqueId(), componentInstance.getUniqueId(), componentInstance.getComponentUid());
90                 return sendGet(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
91         }
92         
93         /**
94          * Delete input from component
95          * 
96          * @param parentComponent
97          * @param inputId
98          * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
99          * @throws Exception
100          */
101         public static RestResponse deleteInputFromComponent(Component parentComponent, String inputId) throws Exception {
102                 return deleteInputFromComponent(ComponentTypeEnum.findParamByType(parentComponent.getComponentType()), parentComponent.getUniqueId(), inputId);
103         }
104
105         /**
106          * Delete input from component
107          * 
108          * @param componentType
109          * @param componentId
110          * @param inputUniqueId
111          * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
112          * @throws Exception
113          */
114         public static RestResponse deleteInputFromComponent(String componentType, String componentId, String inputUniqueId) throws Exception {
115                 Config config = Utils.getConfig();
116                 //{componentType}/{componentId}/delete/{inputId}/input
117                 String url = String.format(Urls.DELETE_INPUT_BY_ID, config.getCatalogBeHost(), config.getCatalogBePort(), componentType, componentId, inputUniqueId);
118                 return sendDelete(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId());
119         }
120         
121 }