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