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 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;
38 * RestUtils for inputs
43 public class InputsRestUtils extends BaseRestUtils {
45 @SuppressWarnings("unused")
46 private static Logger logger = LoggerFactory.getLogger(InputsRestUtils.class.getName());
49 * Add inputs to service
54 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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);
65 * Get all Component inputs
68 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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());
79 * Get all inputs of component instance
81 * @param parentComponent
82 * @param componentInstance
83 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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());
94 * Delete input from component
96 * @param parentComponent
98 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
101 public static RestResponse deleteInputFromComponent(Component parentComponent, String inputId) throws Exception {
102 return deleteInputFromComponent(ComponentTypeEnum.findParamByType(parentComponent.getComponentType()), parentComponent.getUniqueId(), inputId);
106 * Delete input from component
108 * @param componentType
110 * @param inputUniqueId
111 * @return {@link org.openecomp.sdc.ci.tests.datatypes.http.RestResponse}
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());