2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
6 * Modifications Copyright (C) 2020 Nordix Foundation
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.oransc.portal.nonrtric.controlpanel.controller;
23 import java.lang.invoke.MethodHandles;
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;
34 public class PortalRestCentralServiceTest extends AbstractControllerTest {
36 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
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());
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"));
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);
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);
75 * role.setName(ControlPanelConstants.ROLE_NAME_ADMIN);
76 * Set<EcompRole> roles = new HashSet<>();
78 * user.setRoles(roles);
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());
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);
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());