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 java.io.IOException;
24 import java.util.HashMap;
25 import java.util.List;
28 import org.openecomp.portalsdk.core.restful.domain.EcompRole;
29 import org.openecomp.portalsdk.core.restful.domain.EcompUser;
30 import org.openecomp.sdc.ci.tests.api.Urls;
31 import org.openecomp.sdc.ci.tests.config.Config;
32 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
34 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
35 import org.openecomp.sdc.ci.tests.run.StartTest;
36 import org.openecomp.sdc.ci.tests.utils.Utils;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 import com.google.gson.Gson;
42 public class EcompUserRestUtils extends BaseRestUtils {
44 static Gson gson = new Gson();
45 private static Logger logger = LoggerFactory.getLogger(UserRestUtils.class.getName());
47 static String contentTypeHeaderData = "application/json";
48 static String acceptHeaderDate = "application/json";
49 static String ecompUsername = "12345";
50 static String ecompPassword = "12345";
52 public EcompUserRestUtils() {
55 StartTest.enableLogger();
58 public static RestResponse pushUser(EcompUser ecompUser) throws IOException {
59 Config config = Utils.getConfig();
61 Map<String, String> headersMap = new HashMap<String, String>();
62 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
63 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
64 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
65 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
67 String userBodyJson = gson.toJson(ecompUser);
69 HttpRequest http = new HttpRequest();
70 String url = String.format(Urls.ECOMP_PUSH_USER, config.getCatalogBeHost(), config.getCatalogBePort());
72 logger.debug("Send POST request to create user: {}",url);
73 logger.debug("User body: {}",userBodyJson);
74 logger.debug("User headers: {}",headersMap);
76 RestResponse sendPushUserResponse = http.httpSendPost(url, userBodyJson, headersMap);
78 return sendPushUserResponse;
82 * loginId - equals to userId
84 public static RestResponse editUser(String loginId, EcompUser ecompUser) throws IOException {
85 Config config = Utils.getConfig();
87 Map<String, String> headersMap = new HashMap<String, String>();
88 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
89 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
90 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
91 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
93 String userBodyJson = gson.toJson(ecompUser);
95 HttpRequest http = new HttpRequest();
96 String url = String.format(Urls.ECOMP_EDIT_USER, config.getCatalogBeHost(), config.getCatalogBePort(), loginId);
98 logger.debug("Send POST request to edit user: {}",url);
99 logger.debug("User body: {}",userBodyJson);
100 logger.debug("User headers: {}",headersMap);
102 RestResponse sendEditUserResponse = http.httpSendPost(url, userBodyJson, headersMap);
104 return sendEditUserResponse;
108 * loginId - equals to userId
110 public static RestResponse getUser(String loginId) throws IOException {
111 Config config = Utils.getConfig();
113 Map<String, String> headersMap = new HashMap<String, String>();
114 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
115 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
116 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
117 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
119 HttpRequest http = new HttpRequest();
120 String url = String.format(Urls.ECOMP_GET_USER, config.getCatalogBeHost(), config.getCatalogBePort(), loginId);
122 logger.debug("Send GET request to get user: {}",url);
123 logger.debug("User headers: {}",headersMap);
125 RestResponse sendGetUserRequest = http.httpSendGet(url, headersMap);
127 return sendGetUserRequest;
130 public static RestResponse getAllUsers() throws IOException {
131 Config config = Utils.getConfig();
133 Map<String, String> headersMap = new HashMap<String, String>();
134 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
135 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
136 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
137 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
139 HttpRequest http = new HttpRequest();
140 String url = String.format(Urls.ECOMP_GET_ALL_USERS, config.getCatalogBeHost(), config.getCatalogBePort());
142 logger.debug("Send POST request to get all users: {}",url);
143 logger.debug("User headers: {}",headersMap);
145 RestResponse sendGetAllUsersRequest = http.httpSendGet(url, headersMap);
147 return sendGetAllUsersRequest;
150 public static RestResponse getAllAvailableRoles() throws IOException {
151 Config config = Utils.getConfig();
153 Map<String, String> headersMap = new HashMap<String, String>();
154 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
155 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
156 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
157 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
159 HttpRequest http = new HttpRequest();
160 String url = String.format(Urls.ECOMP_GET_ALL_AVAILABLE_ROLES, config.getCatalogBeHost(),
161 config.getCatalogBePort());
163 logger.debug("Send GET request to get all available roles: {}",url);
164 logger.debug("User headers: {}",headersMap);
166 RestResponse sendUpdateUserRequest = http.httpSendGet(url, headersMap);
168 return sendUpdateUserRequest;
172 * loginId - equals to userId
174 public static RestResponse pushUserRoles(String loginId, List<EcompRole> roles) throws IOException {
175 Config config = Utils.getConfig();
177 Map<String, String> headersMap = new HashMap<String, String>();
178 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
179 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
180 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
181 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
183 String roleBodyJson = gson.toJson(roles);
185 HttpRequest http = new HttpRequest();
186 String url = String.format(Urls.ECOMP_PUSH_USER_ROLES, config.getCatalogBeHost(), config.getCatalogBePort(),
189 logger.debug("Send POST request to push user role: {}",url);
190 logger.debug("Roles body: {}",roleBodyJson);
191 logger.debug("Request headers: {}",headersMap);
193 RestResponse sendpushUserRolesResponse = http.httpSendPost(url, roleBodyJson, headersMap);
195 return sendpushUserRolesResponse;
199 * loginId - equals to userId
201 public static RestResponse getUserRoles(String loginId) throws IOException {
202 Config config = Utils.getConfig();
204 Map<String, String> headersMap = new HashMap<String, String>();
205 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
206 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
207 headersMap.put(HttpHeaderEnum.ECOMP_USERNAME.getValue(), ecompUsername);
208 headersMap.put(HttpHeaderEnum.ECOMP_PASSWORD.getValue(), ecompPassword);
210 HttpRequest http = new HttpRequest();
211 String url = String.format(Urls.ECOMP_GET_USER_ROLES, config.getCatalogBeHost(), config.getCatalogBePort(),
214 logger.debug("Send GET request to get user roles: {}",url);
215 logger.debug("User headers: {}",headersMap);
217 RestResponse sendGetUserRolesRequest = http.httpSendGet(url, headersMap);
219 return sendGetUserRolesRequest;
222 // TODO !!!!!!!!!!!!!!
224 * Ask Eli if implementation of users is needed DELETE ECOMP USER
228 * public static void main(String[] args) { EcompUser ecompUser = new
229 * EcompUser(); ecompUser.setFirstName("Test");
230 * ecompUser.setLastName("Testovich");
231 * ecompUser.setEmail("ttes@intl.sdc.com"); ecompUser.setLoginId("tt0004");
232 * ecompUser.setActive(true);
234 * EcompRole roleToUpdate = new EcompRole(); roleToUpdate.setId(new
235 * Long(6)); roleToUpdate.setName("PRODUCT_STRATEGIST"); List<EcompRole>
236 * listOfRoles = new LinkedList<>(); listOfRoles.add(roleToUpdate);
239 * System.out.println("\n-----------------------------\n Testing pushUser");
240 * System.out.println(pushUser(ecompUser));
241 * System.out.println("\n-----------------------------\n Testing editUser");
242 * System.out.println("\n-----------------------------\n Testing getUser");
243 * // System.out.println(getUser(ecompUser.getLoginId())); System.out.
244 * println("\n-----------------------------\n Testing getAllUsers"); //
245 * System.out.println(getAllUsers()); System.out.
246 * println("\n-----------------------------\n Testing getAllAvailableRoles"
247 * ); // System.out.println(getAllAvailableRoles().toString()); System.out.
248 * println("\n-----------------------------\n Testing pushUserRoles"); //
249 * println("\n-----------------------------\n Testing getUserRoles"); //
250 * TODO Auto-generated catch block e.printStackTrace(); } }