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