2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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.List;
26 import org.junit.jupiter.api.Assertions;
27 import org.junit.jupiter.api.MethodOrderer;
28 import org.junit.jupiter.api.Order;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.TestMethodOrder;
31 import org.oransc.ric.portal.dashboard.DashboardConstants;
32 import org.oransc.ric.portal.dashboard.config.E2ManagerMockConfiguration;
33 import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
34 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
35 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
36 import org.oransc.ricplt.e2mgr.client.model.GetNodebResponse;
37 import org.oransc.ricplt.e2mgr.client.model.NodebIdentity;
38 import org.oransc.ricplt.e2mgr.client.model.ResetRequest;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.core.ParameterizedTypeReference;
42 import org.springframework.http.HttpEntity;
43 import org.springframework.http.HttpMethod;
44 import org.springframework.http.ResponseEntity;
46 @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
47 public class E2ManagerControllerTest extends AbstractControllerTest {
49 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
53 public void versionTest() {
54 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
55 logger.info("Invoking {}", uri);
56 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
57 Assertions.assertFalse(st.getData().toString().isEmpty());
62 public void healthTest() {
63 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
64 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.HEALTH_METHOD);
65 logger.info("Invoking {}", uri);
66 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
67 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
72 public void ranDetailsTest() {
73 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
74 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.RAN_METHOD);
75 logger.info("Invoking {}", uri);
76 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
77 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
79 Assertions.assertFalse(response.getBody().isEmpty());
84 public void nodebListTest() {
85 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
86 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_LIST_METHOD);
87 logger.info("Invoking {}", uri);
88 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
89 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
91 Assertions.assertFalse(response.getBody().isEmpty());
96 public void nodebStatusTest() {
97 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
98 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX,
99 E2ManagerMockConfiguration.RAN_NAME_1);
100 logger.info("Invoking {}", uri);
101 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
102 Assertions.assertNotNull(response.getRanName());
105 // This empties the list of RAN elements
108 public void resetTest() {
109 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
110 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX, "ignored",
111 E2ManagerController.RESET_METHOD);
112 logger.info("Invoking {}", uri);
113 ResetRequest reset = new ResetRequest();
114 HttpEntity<ResetRequest> entity = new HttpEntity<>(reset);
115 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity, Void.class);
116 logger.debug("resetTest: response {}", voidResponse);
117 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
120 // Aka big--button test, run this last
123 public void nodebShutdownPutTest() {
124 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
125 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_SHUTDOWN_METHOD);
126 logger.info("Invoking {}", uri);
127 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
128 logger.debug("nodebPutTest: response {}", voidResponse);
129 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());