Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / EcompUserRestUtils.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 java.io.IOException;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
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;
39
40 import com.google.gson.Gson;
41
42 public class EcompUserRestUtils extends BaseRestUtils {
43
44         static Gson gson = new Gson();
45         private static Logger logger = LoggerFactory.getLogger(UserRestUtils.class.getName());
46
47         static String contentTypeHeaderData = "application/json";
48         static String acceptHeaderDate = "application/json";
49         static String ecompUsername = "12345";
50         static String ecompPassword = "12345";
51
52         public EcompUserRestUtils() {
53                 super();
54
55                 StartTest.enableLogger();
56         }
57
58         public static RestResponse pushUser(EcompUser ecompUser) throws IOException {
59                 Config config = Utils.getConfig();
60
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);
66
67                 String userBodyJson = gson.toJson(ecompUser);
68
69                 HttpRequest http = new HttpRequest();
70                 String url = String.format(Urls.ECOMP_PUSH_USER, config.getCatalogBeHost(), config.getCatalogBePort());
71
72                 logger.debug("Send POST request to create user: {}",url);
73                 logger.debug("User body: {}",userBodyJson);
74                 logger.debug("User headers: {}",headersMap);
75
76                 RestResponse sendPushUserResponse = http.httpSendPost(url, userBodyJson, headersMap);
77
78                 return sendPushUserResponse;
79         }
80
81         /*
82          * loginId - equals to userId
83          */
84         public static RestResponse editUser(String loginId, EcompUser ecompUser) throws IOException {
85                 Config config = Utils.getConfig();
86
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);
92
93                 String userBodyJson = gson.toJson(ecompUser);
94
95                 HttpRequest http = new HttpRequest();
96                 String url = String.format(Urls.ECOMP_EDIT_USER, config.getCatalogBeHost(), config.getCatalogBePort(), loginId);
97
98                 logger.debug("Send POST request to edit user: {}",url);
99                 logger.debug("User body: {}",userBodyJson);
100                 logger.debug("User headers: {}",headersMap);
101
102                 RestResponse sendEditUserResponse = http.httpSendPost(url, userBodyJson, headersMap);
103
104                 return sendEditUserResponse;
105         }
106
107         /*
108          * loginId - equals to userId
109          */
110         public static RestResponse getUser(String loginId) throws IOException {
111                 Config config = Utils.getConfig();
112
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);
118
119                 HttpRequest http = new HttpRequest();
120                 String url = String.format(Urls.ECOMP_GET_USER, config.getCatalogBeHost(), config.getCatalogBePort(), loginId);
121
122                 logger.debug("Send GET request to get user: {}",url);
123                 logger.debug("User headers: {}",headersMap);
124
125                 RestResponse sendGetUserRequest = http.httpSendGet(url, headersMap);
126
127                 return sendGetUserRequest;
128         }
129
130         public static RestResponse getAllUsers() throws IOException {
131                 Config config = Utils.getConfig();
132
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);
138
139                 HttpRequest http = new HttpRequest();
140                 String url = String.format(Urls.ECOMP_GET_ALL_USERS, config.getCatalogBeHost(), config.getCatalogBePort());
141
142                 logger.debug("Send POST request to get all users: {}",url);
143                 logger.debug("User headers: {}",headersMap);
144
145                 RestResponse sendGetAllUsersRequest = http.httpSendGet(url, headersMap);
146
147                 return sendGetAllUsersRequest;
148         }
149
150         public static RestResponse getAllAvailableRoles() throws IOException {
151                 Config config = Utils.getConfig();
152
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);
158
159                 HttpRequest http = new HttpRequest();
160                 String url = String.format(Urls.ECOMP_GET_ALL_AVAILABLE_ROLES, config.getCatalogBeHost(),
161                                 config.getCatalogBePort());
162
163                 logger.debug("Send GET request to get all available roles: {}",url);
164                 logger.debug("User headers: {}",headersMap);
165
166                 RestResponse sendUpdateUserRequest = http.httpSendGet(url, headersMap);
167
168                 return sendUpdateUserRequest;
169         }
170
171         /*
172          * loginId - equals to userId
173          */
174         public static RestResponse pushUserRoles(String loginId, List<EcompRole> roles) throws IOException {
175                 Config config = Utils.getConfig();
176
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);
182
183                 String roleBodyJson = gson.toJson(roles);
184
185                 HttpRequest http = new HttpRequest();
186                 String url = String.format(Urls.ECOMP_PUSH_USER_ROLES, config.getCatalogBeHost(), config.getCatalogBePort(),
187                                 loginId);
188
189                 logger.debug("Send POST request to push user role: {}",url);
190                 logger.debug("Roles body: {}",roleBodyJson);
191                 logger.debug("Request headers: {}",headersMap);
192
193                 RestResponse sendpushUserRolesResponse = http.httpSendPost(url, roleBodyJson, headersMap);
194
195                 return sendpushUserRolesResponse;
196         }
197
198         /*
199          * loginId - equals to userId
200          */
201         public static RestResponse getUserRoles(String loginId) throws IOException {
202                 Config config = Utils.getConfig();
203
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);
209
210                 HttpRequest http = new HttpRequest();
211                 String url = String.format(Urls.ECOMP_GET_USER_ROLES, config.getCatalogBeHost(), config.getCatalogBePort(),
212                                 loginId);
213
214                 logger.debug("Send GET request to get user roles: {}",url);
215                 logger.debug("User headers: {}",headersMap);
216
217                 RestResponse sendGetUserRolesRequest = http.httpSendGet(url, headersMap);
218
219                 return sendGetUserRolesRequest;
220         }
221
222         // TODO !!!!!!!!!!!!!!
223         /*
224          * Ask Eli if implementation of users is needed DELETE ECOMP USER
225          */
226
227         /*
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);
233          * 
234          * EcompRole roleToUpdate = new EcompRole(); roleToUpdate.setId(new
235          * Long(6)); roleToUpdate.setName("PRODUCT_STRATEGIST"); List<EcompRole>
236          * listOfRoles = new LinkedList<>(); listOfRoles.add(roleToUpdate);
237          * 
238          * try {
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(); } }
251          */
252 }