Show AC app data visualization in new metrics tab
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / AdminControllerTest.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
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.IDashboardResponse;
34 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.core.ParameterizedTypeReference;
38 import org.springframework.http.HttpMethod;
39 import org.springframework.http.ResponseEntity;
40
41 public class AdminControllerTest extends AbstractControllerTest {
42
43         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
44
45         @Test
46         public void versionTest() {
47                 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.VERSION_METHOD);
48                 logger.info("Invoking {}", uri);
49                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
50                 Assertions.assertFalse(st.getData().toString().isEmpty());
51         }
52
53         @Test
54         public void healthTest() {
55                 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.HEALTH_METHOD);
56                 logger.info("Invoking {}", uri);
57                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
58                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
59         }
60
61         @Test
62         public void getUsersTest() {
63                 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.USER_METHOD);
64                 logger.info("Invoking {}", uri);
65                 ResponseEntity<List<DashboardUser>> response = testRestTemplateAdminRole().exchange(uri, HttpMethod.GET, null,
66                                 new ParameterizedTypeReference<List<DashboardUser>>() {
67                                 });
68                 Assertions.assertFalse(response.getBody().isEmpty());
69         }
70
71         @Test
72         public void getUsersTestRoleAuthFail() {
73                 URI uri = buildUri(null, AdminController.CONTROLLER_PATH, AdminController.USER_METHOD);
74                 logger.info("Invoking {}", uri);
75                 ResponseEntity<String> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET, null,
76                                 String.class);
77                 Assertions.assertTrue(response.getStatusCode().is4xxClientError());
78         }
79
80         @Test
81         public void getxAppMetricsUrlTest() {
82                 Map<String, String> metricsQueryParms = new HashMap<String, String>();
83                 metricsQueryParms.put("app", DashboardConstants.APP_NAME_AC);
84                 URI uri = buildUri(metricsQueryParms, AdminController.CONTROLLER_PATH, AdminController.XAPPMETRICS_METHOD);
85                 logger.debug("Invoking {}", uri);
86                 ResponseEntity<SuccessTransport> successResponse = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET, null,
87                                 SuccessTransport.class);
88                 Assertions.assertFalse(successResponse.getBody().getData().toString().isEmpty());
89                 Assertions.assertTrue(successResponse.getStatusCode().is2xxSuccessful());
90         }
91
92         @Test
93         public void getxAppMetricsUrlTestFail() {
94                 Map<String, String> metricsQueryParms = new HashMap<String, String>(); 
95                 //Providing a bogus value for application name in query parameter to test failure 
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, null,
100                                 ErrorTransport.class);
101                 logger.debug("{}", errorResponse.getBody().getError().toString());
102                 Assertions.assertTrue(errorResponse.getStatusCode().is4xxClientError());
103         }
104
105 }