Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / CatalogRestUtils.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.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Optional;
29
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.enums.UserRoleEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
35 import org.openecomp.sdc.ci.tests.utils.Utils;
36
37 public class CatalogRestUtils extends BaseRestUtils {
38
39         public static RestResponse getAbstractResources() throws IOException {
40
41                 Config config = Utils.getConfig();
42                 String url = String.format(Urls.GET_ALL_ABSTRACT_RESOURCES, config.getCatalogBeHost(),
43                                 config.getCatalogBePort());
44
45                 return sendGet(url, UserRoleEnum.DESIGNER.getUserId());
46         }
47
48         public static RestResponse getCatalog() throws IOException {
49                 return getCatalog(UserRoleEnum.DESIGNER.getUserId());
50         }
51
52         public static RestResponse getCatalog(String userId) throws IOException {
53                 Config config = Utils.getConfig();
54                 String url = String.format(Urls.GET_CATALOG_DATA, config.getCatalogBeHost(), config.getCatalogBePort());
55                 return sendGet(url, userId);
56         }
57
58         public static RestResponse getCatalog(String userId, List<String> excludeList) throws IOException {
59                 Config config = Utils.getConfig();
60                 String url = String.format(Urls.GET_CATALOG_DATA, config.getCatalogBeHost(), config.getCatalogBePort());
61                 StringBuilder sb = new StringBuilder();
62                 sb.append(url).append("?");
63                 Optional.ofNullable(excludeList).orElse(Collections.emptyList()).forEach(type -> sb.append("excludeTypes="+type+"&"));
64                 return sendGet(sb.toString(), userId);
65         }
66
67         public static RestResponse getAllCategoriesTowardsCatalogBe() throws IOException {
68
69                 Config config = Utils.getConfig();
70                 String url = String.format(Urls.GET_ALL_CATEGORIES, config.getCatalogBeHost(), config.getCatalogBePort(),
71                                 BaseRestUtils.RESOURCE_COMPONENT_TYPE);
72
73                 return sendGet(url, UserRoleEnum.DESIGNER.getUserId());
74         }
75
76         public static RestResponse getAllCategoriesTowardsCatalogFeWithUuid(String uuid) throws IOException {
77
78                 Config config = Utils.getConfig();
79                 String url = String.format(Urls.GET_ALL_CATEGORIES_FE, config.getCatalogFeHost(), config.getCatalogFePort(),
80                                 BaseRestUtils.RESOURCE_COMPONENT_TYPE);
81
82                 Map<String, String> additionalHeaders = new HashMap<String, String>();
83                 additionalHeaders.put(HttpHeaderEnum.X_ECOMP_REQUEST_ID_HEADER.getValue(), uuid);
84
85                 return sendGet(url, UserRoleEnum.DESIGNER.getUserId(), additionalHeaders);
86         }
87 }