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;
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;
36 import com.google.gson.Gson;
39 * RestUtils for inputs
44 public class InputsRestUtils extends BaseRestUtils {
46 @SuppressWarnings("unused")
47 private static Logger logger = LoggerFactory.getLogger(InputsRestUtils.class.getName());
50 * Add inputs to service
55 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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);
66 * Get all Component inputs
69 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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());
80 * Get all inputs of component instance
82 * @param parentComponent
83 * @param componentInstance
84 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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());
95 * Delete input from component
97 * @param parentComponent
99 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
102 public static RestResponse deleteInputFromComponent(Component parentComponent, String inputId) throws Exception {
103 return deleteInputFromComponent(ComponentTypeEnum.findParamByType(parentComponent.getComponentType()), parentComponent.getUniqueId(), inputId);
107 * Delete input from component
109 * @param componentType
111 * @param inputUniqueId
112 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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());