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