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.Test;
28 import org.oransc.ric.e2mgr.client.model.GetNodebResponse;
29 import org.oransc.ric.e2mgr.client.model.NodebIdentity;
30 import org.oransc.ric.e2mgr.client.model.ResetRequest;
31 import org.oransc.ric.e2mgr.client.model.SetupRequest;
32 import org.oransc.ric.portal.dashboard.DashboardConstants;
33 import org.oransc.ric.portal.dashboard.config.E2ManagerMockConfiguration;
34 import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
35 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
36 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
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> endcSetup() {
49 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
50 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.ENDC_SETUP_METHOD);
51 logger.info("Invoking {}", uri);
52 SetupRequest setup = new SetupRequest().ranName(E2ManagerMockConfiguration.RAN_NAME_1);
53 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
54 return testRestTemplateAdminRole().exchange(uri, HttpMethod.POST, entity, Void.class);
57 private ResponseEntity<Void> reset() {
58 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
59 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX, "ignored",
60 E2ManagerController.RESET_METHOD);
61 logger.info("Invoking {}", uri);
62 ResetRequest reset = new ResetRequest();
63 HttpEntity<ResetRequest> entity = new HttpEntity<>(reset);
64 return testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity, Void.class);
68 public void endcSetupTest() {
69 ResponseEntity<Void> voidResponse = endcSetup();
70 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
75 public void resetTest() {
76 ResponseEntity<Void> voidResponse = reset();
77 logger.debug("resetTest: response {}", voidResponse);
78 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
82 public void versionTest() {
83 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
84 logger.info("Invoking {}", uri);
85 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
86 Assertions.assertFalse(st.getData().toString().isEmpty());
90 public void healthTest() {
91 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
92 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.HEALTH_METHOD);
93 logger.info("Invoking {}", uri);
94 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
95 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
99 public void ranDetailsTest() {
101 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
102 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.RAN_METHOD);
103 logger.info("Invoking {}", uri);
104 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
105 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
107 Assertions.assertFalse(response.getBody().isEmpty());
112 public void nodebListTest() {
114 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
115 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_LIST_METHOD);
116 logger.info("Invoking {}", uri);
117 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
118 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
120 Assertions.assertFalse(response.getBody().isEmpty());
125 public void nodebStatusTest() {
127 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
128 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX,
129 E2ManagerMockConfiguration.RAN_NAME_1);
130 logger.info("Invoking {}", uri);
131 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
132 Assertions.assertNotNull(response.getRanName());
137 public void x2SetupTest() {
138 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
139 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.X2_SETUP_METHOD);
140 logger.info("Invoking {}", uri);
141 SetupRequest setup = new SetupRequest().ranName(E2ManagerMockConfiguration.RAN_NAME_1);
142 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
143 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.POST, entity,
145 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
149 // Aka big--button test
151 public void nodebShutdownPutTest() {
152 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
153 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_SHUTDOWN_METHOD);
154 logger.info("Invoking {}", uri);
155 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
156 logger.debug("nodebPutTest: response {}", voidResponse);
157 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());