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;
24 import java.util.HashMap;
25 import java.util.List;
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.Test;
30 import org.oransc.ric.portal.dashboard.DashboardConstants;
31 import org.oransc.ric.portal.dashboard.model.DashboardUser;
32 import org.oransc.ric.portal.dashboard.model.ErrorTransport;
33 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.core.ParameterizedTypeReference;
37 import org.springframework.http.HttpMethod;
38 import org.springframework.http.ResponseEntity;
40 public class AdminControllerTest extends AbstractControllerTest {
42 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
45 public void versionTest() {
46 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.VERSION_METHOD);
47 logger.info("Invoking {}", uri);
48 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
49 Assertions.assertFalse(st.getData().toString().isEmpty());
53 public void healthTest() {
54 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.HEALTH_METHOD);
55 logger.info("Invoking {}", uri);
56 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
57 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
61 public void getUsersTest() {
62 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.USER_METHOD);
63 logger.info("Invoking {}", uri);
64 ResponseEntity<List<DashboardUser>> response = testRestTemplateAdminRole().exchange(uri, HttpMethod.GET, null,
65 new ParameterizedTypeReference<List<DashboardUser>>() {
67 Assertions.assertFalse(response.getBody().isEmpty());
71 public void getUsersTestRoleAuthFail() {
72 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.USER_METHOD);
73 logger.info("Invoking {}", uri);
74 ResponseEntity<String> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET, null,
76 Assertions.assertTrue(response.getStatusCode().is4xxClientError());
80 public void getxAppMetricsUrlTest() {
81 Map<String, String> metricsQueryParms = new HashMap<String, String>();
82 metricsQueryParms.put("app", DashboardConstants.APP_NAME_AC);
83 URI uri = buildUri(metricsQueryParms, AdminController.CONTROLLER_PATH, AdminController.XAPPMETRICS_METHOD);
84 logger.debug("Invoking {}", uri);
85 ResponseEntity<SuccessTransport> successResponse = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
86 null, SuccessTransport.class);
87 Assertions.assertFalse(successResponse.getBody().getData().toString().isEmpty());
88 Assertions.assertTrue(successResponse.getStatusCode().is2xxSuccessful());
92 public void getxAppMetricsUrlTestFail() {
93 Map<String, String> metricsQueryParms = new HashMap<String, String>();
94 // Providing a bogus value for application name in query parameter to test
96 metricsQueryParms.put("app", "ABCD");
97 URI uri = buildUri(metricsQueryParms, AdminController.CONTROLLER_PATH, AdminController.XAPPMETRICS_METHOD);
98 logger.debug("Invoking {}", uri);
99 ResponseEntity<ErrorTransport> errorResponse = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
100 null, ErrorTransport.class);
101 logger.debug("{}", errorResponse.getBody().getError().toString());
102 Assertions.assertTrue(errorResponse.getStatusCode().is4xxClientError());