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