eef172611a0b8ef813143f4c3c7183b5726c24de
[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 /*      private HttpEntity<Object> getEntityWithHeaders(Object body) {
57         HttpHeaders headers = new HttpHeaders();
58         headers.set(PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
59             PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
60         headers.set(PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
61             PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
62         HttpEntity<Object> entity = new HttpEntity<>(body, headers);
63         return entity;
64     }
65
66     private EcompUser createEcompUser(String loginId) {
67         EcompUser user = new EcompUser();
68         user.setLoginId(loginId);
69         EcompRole role = new EcompRole();
70         role.setRoleFunctions(Collections.EMPTY_SET);
71         role.setId(1L);
72         role.setName(DashboardConstants.ROLE_NAME_ADMIN);
73         Set<EcompRole> roles = new HashSet<>();
74         roles.add(role);
75         user.setRoles(roles);
76         return user;
77     }
78
79         @Test
80      * @Test
81      * public void createUserTest() {
82      * final String loginId = "login1";
83      * URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
84      * logger.info("Invoking {}", create);
85      * HttpEntity<Object> requestEntity = getEntityWithHeaders(createEcompUser(loginId));
86      * ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
87      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
88      * }
89      *
90      * @Test
91      * public void updateUserTest() {
92      * final String loginId = "login2";
93      * URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
94      * EcompUser user = createEcompUser(loginId);
95      * logger.info("Invoking {}", create);
96      * HttpEntity<Object> requestEntity = getEntityWithHeaders(user);
97      * // Create
98      * ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
99      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
100      * URI update = buildUri(null, PortalApiConstants.API_PREFIX, "user", loginId);
101      * user.setEmail("user@company.org");
102      * requestEntity = getEntityWithHeaders(user);
103      * response = restTemplate.exchange(update, HttpMethod.POST, requestEntity, String.class);
104      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
105      * }
106      */
107
108 }