Return response codes from policy controller
[nonrtric.git] / dashboard / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / PortalRestCentralServiceTest.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
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 package org.oransc.ric.portal.dashboard.controller;
21
22 import java.lang.invoke.MethodHandles;
23 import java.net.URI;
24 import org.junit.jupiter.api.Assertions;
25 import org.junit.jupiter.api.Test;
26 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.http.HttpMethod;
30 import org.springframework.http.ResponseEntity;
31
32 public class PortalRestCentralServiceTest extends AbstractControllerTest {
33
34     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
35
36     @Test
37     public void getAnalyticsTest() {
38         // paths are hardcoded here exactly like the EPSDK-FW library :(
39         URI uri = buildUri(null, PortalApiConstants.API_PREFIX, "/analytics");
40         logger.info("Invoking {}", uri);
41         ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
42         // No Portal is available so this always fails
43         Assertions.assertTrue(response.getStatusCode().is4xxClientError());
44     }
45
46     @Test
47     public void getErrorPageTest() {
48         // Send unauthorized request
49         URI uri = buildUri(null, "/favicon.ico");
50         logger.info("Invoking {}", uri);
51         ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
52         Assertions.assertTrue(response.getStatusCode().is4xxClientError());
53         Assertions.assertTrue(response.getBody().contains("Static error page"));
54     }
55
56     /*
57      * private HttpEntity<Object> getEntityWithHeaders(Object body) {
58      * HttpHeaders headers = new HttpHeaders();
59      * headers.set(PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
60      * PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
61      * headers.set(PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
62      * PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
63      * HttpEntity<Object> entity = new HttpEntity<>(body, headers);
64      * return entity;
65      * }
66      *
67      * private EcompUser createEcompUser(String loginId) {
68      * EcompUser user = new EcompUser();
69      * user.setLoginId(loginId);
70      * EcompRole role = new EcompRole();
71      * role.setRoleFunctions(Collections.EMPTY_SET);
72      * role.setId(1L);
73      * role.setName(DashboardConstants.ROLE_NAME_ADMIN);
74      * Set<EcompRole> roles = new HashSet<>();
75      * roles.add(role);
76      * user.setRoles(roles);
77      * return user;
78      * }
79      *
80      * @Test
81      *
82      * @Test
83      * public void createUserTest() {
84      * final String loginId = "login1";
85      * URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
86      * logger.info("Invoking {}", create);
87      * HttpEntity<Object> requestEntity = getEntityWithHeaders(createEcompUser(loginId));
88      * ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
89      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
90      * }
91      *
92      * @Test
93      * public void updateUserTest() {
94      * final String loginId = "login2";
95      * URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
96      * EcompUser user = createEcompUser(loginId);
97      * logger.info("Invoking {}", create);
98      * HttpEntity<Object> requestEntity = getEntityWithHeaders(user);
99      * // Create
100      * ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
101      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
102      * URI update = buildUri(null, PortalApiConstants.API_PREFIX, "user", loginId);
103      * user.setEmail("user@company.org");
104      * requestEntity = getEntityWithHeaders(user);
105      * response = restTemplate.exchange(update, HttpMethod.POST, requestEntity, String.class);
106      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
107      * }
108      */
109
110 }