Correct spelling mistake in name of component
[portal/nonrtric-controlpanel.git] / webapp-backend / src / test / java / org / oransc / portal / nonrtric / controlpanel / controller / PortalRestCentralServiceTest.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
6  * Modifications Copyright (C) 2020 Nordix Foundation
7  * %%
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ========================LICENSE_END===================================
20  */
21 package org.oransc.portal.nonrtric.controlpanel.controller;
22
23 import java.lang.invoke.MethodHandles;
24 import java.net.URI;
25
26 import org.junit.jupiter.api.Assertions;
27 import org.junit.jupiter.api.Test;
28 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.http.HttpMethod;
32 import org.springframework.http.ResponseEntity;
33
34 public class PortalRestCentralServiceTest extends AbstractControllerTest {
35
36     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
37
38     @Test
39     public void getAnalyticsTest() {
40         // paths are hardcoded here exactly like the EPSDK-FW library :(
41         URI uri = buildUri(null, PortalApiConstants.API_PREFIX, "/analytics");
42         logger.info("Invoking {}", uri);
43         ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
44         // No Portal is available so this always fails
45         Assertions.assertTrue(response.getStatusCode().is4xxClientError());
46     }
47
48     @Test
49     public void getErrorPageTest() {
50         // Send unauthorized request
51         URI uri = buildUri(null, "/favicon.ico");
52         logger.info("Invoking {}", uri);
53         ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
54         Assertions.assertTrue(response.getStatusCode().is4xxClientError());
55         Assertions.assertTrue(response.getBody().contains("Static error page"));
56     }
57
58     /*
59      * private HttpEntity<Object> getEntityWithHeaders(Object body) {
60      * HttpHeaders headers = new HttpHeaders();
61      * headers.set(PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
62      * PortalApIMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
63      * headers.set(PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
64      * PortalApIMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
65      * HttpEntity<Object> entity = new HttpEntity<>(body, headers);
66      * return entity;
67      * }
68      *
69      * private EcompUser createEcompUser(String loginId) {
70      * EcompUser user = new EcompUser();
71      * user.setLoginId(loginId);
72      * EcompRole role = new EcompRole();
73      * role.setRoleFunctions(Collections.EMPTY_SET);
74      * role.setId(1L);
75      * role.setName(ControlPanelConstants.ROLE_NAME_ADMIN);
76      * Set<EcompRole> roles = new HashSet<>();
77      * roles.add(role);
78      * user.setRoles(roles);
79      * return user;
80      * }
81      *
82      * @Test
83      *
84      * @Test
85      * public void createUserTest() {
86      * final String loginId = "login1";
87      * URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
88      * logger.info("Invoking {}", create);
89      * HttpEntity<Object> requestEntity = getEntityWithHeaders(createEcompUser(loginId));
90      * ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
91      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
92      * }
93      *
94      * @Test
95      * public void updateUserTest() {
96      * final String loginId = "login2";
97      * URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
98      * EcompUser user = createEcompUser(loginId);
99      * logger.info("Invoking {}", create);
100      * HttpEntity<Object> requestEntity = getEntityWithHeaders(user);
101      * // Create
102      * ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
103      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
104      * URI update = buildUri(null, PortalApiConstants.API_PREFIX, "user", loginId);
105      * user.setEmail("user@company.org");
106      * requestEntity = getEntityWithHeaders(user);
107      * response = restTemplate.exchange(update, HttpMethod.POST, requestEntity, String.class);
108      * Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
109      * }
110      */
111
112 }