2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 package org.oransc.ric.portal.dashboard.controller;
22 import java.lang.invoke.MethodHandles;
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.onap.portalsdk.core.restful.domain.EcompUser;
29 import org.oransc.ric.portal.dashboard.DashboardConstants;
30 import org.oransc.ric.portal.dashboard.config.WebSecurityMockConfiguration;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.http.HttpEntity;
34 import org.springframework.http.HttpHeaders;
35 import org.springframework.http.HttpMethod;
36 import org.springframework.http.ResponseEntity;
38 public class PortalRestCentralServiceTest extends AbstractControllerTest {
40 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
42 // paths are hardcoded here exactly like the EPSDK-FW library :(
45 public void getAnalyticsTest() {
46 // paths are hardcoded here exactly like the EPSDK-FW library :(
47 URI uri = buildUri(null, PortalApiConstants.API_PREFIX, "/analytics");
48 logger.info("Invoking {}", uri);
49 ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
50 // No Portal is available so this always fails
51 Assertions.assertTrue(response.getStatusCode().is4xxClientError());
55 public void getLoginPageTest() {
56 URI uri = buildUri(null, DashboardConstants.LOGIN_PAGE);
57 logger.info("Invoking {}", uri);
58 ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
59 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
60 Assertions.assertTrue(response.getBody().contains("Please log in"));
63 private HttpEntity<Object> getEntityWithHeaders(Object body) {
64 HttpHeaders headers = new HttpHeaders();
65 headers.set(WebSecurityMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
66 WebSecurityMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
67 headers.set(WebSecurityMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
68 WebSecurityMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
69 HttpEntity<Object> entity = new HttpEntity<>(body, headers);
74 public void createUserTest() {
75 final String loginId = "login1";
76 URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
77 logger.info("Invoking {}", create);
78 EcompUser user = new EcompUser();
79 user.setLoginId(loginId);
80 HttpEntity<Object> requestEntity = getEntityWithHeaders(user);
81 ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
82 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
86 public void updateUserTest() {
87 final String loginId = "login2";
88 URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
89 logger.info("Invoking {}", create);
90 EcompUser user = new EcompUser();
91 user.setLoginId(loginId);
92 HttpEntity<Object> requestEntity = getEntityWithHeaders(user);
94 ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
95 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
96 URI update = buildUri(null, PortalApiConstants.API_PREFIX, "user", loginId);
97 user.setEmail("user@company.org");
98 requestEntity = getEntityWithHeaders(user);
99 response = restTemplate.exchange(update, HttpMethod.POST, requestEntity, String.class);
100 Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());