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.After;
27 import org.junit.jupiter.api.Assertions;
28 import org.junit.jupiter.api.Test;
29 import org.oransc.ric.portal.dashboard.DashboardConstants;
30 import org.oransc.ric.portal.dashboard.config.E2ManagerMockConfiguration;
31 import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
32 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
33 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
34 import org.oransc.ricplt.e2mgr.client.model.GetNodebResponse;
35 import org.oransc.ricplt.e2mgr.client.model.NodebIdentity;
36 import org.oransc.ricplt.e2mgr.client.model.ResetRequest;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.core.ParameterizedTypeReference;
40 import org.springframework.http.HttpEntity;
41 import org.springframework.http.HttpMethod;
42 import org.springframework.http.ResponseEntity;
44 public class E2ManagerControllerTest extends AbstractControllerTest {
46 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
48 private ResponseEntity<Void> reset() {
49 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
50 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX, "ignored",
51 E2ManagerController.RESET_METHOD);
52 logger.info("Invoking {}", uri);
53 ResetRequest reset = new ResetRequest();
54 HttpEntity<ResetRequest> entity = new HttpEntity<>(reset);
55 return testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity, Void.class);
59 public void resetTest() {
60 ResponseEntity<Void> voidResponse = reset();
61 logger.debug("resetTest: response {}", voidResponse);
62 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
66 public void versionTest() {
67 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
68 logger.info("Invoking {}", uri);
69 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
70 Assertions.assertFalse(st.getData().toString().isEmpty());
74 public void healthTest() {
75 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
76 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.HEALTH_METHOD);
77 logger.info("Invoking {}", uri);
78 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
79 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
83 public void ranDetailsTest() {
84 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
85 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.RAN_METHOD);
86 logger.info("Invoking {}", uri);
87 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
88 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
90 Assertions.assertFalse(response.getBody().isEmpty());
94 public void nodebListTest() {
95 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
96 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_LIST_METHOD);
97 logger.info("Invoking {}", uri);
98 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
99 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
101 Assertions.assertFalse(response.getBody().isEmpty());
105 public void nodebStatusTest() {
106 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
107 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX,
108 E2ManagerMockConfiguration.RAN_NAME_1);
109 logger.info("Invoking {}", uri);
110 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
111 Assertions.assertNotNull(response.getRanName());
114 // Aka big--button test, run this last
116 public void nodebShutdownPutTest() {
117 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
118 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_SHUTDOWN_METHOD);
119 logger.info("Invoking {}", uri);
120 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
121 logger.debug("nodebPutTest: response {}", voidResponse);
122 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());