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.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.config.E2ManagerMockConfiguration;
33 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
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.HttpEntity;
39 import org.springframework.http.HttpMethod;
40 import org.springframework.http.ResponseEntity;
42 public class E2ManagerControllerTest extends AbstractControllerTest {
44 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
46 private ResponseEntity<Void> endcSetup() {
47 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.ENDC_SETUP_METHOD);
48 logger.info("Invoking {}", uri);
49 SetupRequest setup = new SetupRequest().ranName(E2ManagerMockConfiguration.MOCK_RAN_NAME);
50 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
51 return testRestTemplateAdminRole().exchange(uri, HttpMethod.POST, entity, Void.class);
54 private ResponseEntity<Void> reset() {
55 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.RESET_METHOD, "ignored");
56 logger.info("Invoking {}", uri);
57 ResetRequest reset = new ResetRequest();
58 HttpEntity<ResetRequest> entity = new HttpEntity<>(reset);
59 return testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity, Void.class);
63 public void versionTest() {
64 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.VERSION_METHOD);
65 logger.info("Invoking {}", uri);
66 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
67 Assertions.assertFalse(st.getData().toString().isEmpty());
71 public void healthTest() {
72 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.HEALTH_METHOD);
73 logger.info("Invoking {}", uri);
74 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
75 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
79 public void ranDetailsTest() {
81 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.RAN_METHOD);
82 logger.info("Invoking {}", uri);
83 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
84 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
86 Assertions.assertFalse(response.getBody().isEmpty());
91 public void nodebListTest() {
93 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_LIST_METHOD);
94 logger.info("Invoking {}", uri);
95 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
96 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
98 Assertions.assertFalse(response.getBody().isEmpty());
103 public void nodebStatusTest() {
105 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_SHUTDOWN_METHOD,
106 E2ManagerMockConfiguration.MOCK_RAN_NAME);
107 logger.info("Invoking {}", uri);
108 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
109 Assertions.assertNotNull(response.getRanName());
114 public void endcSetupTest() {
115 ResponseEntity<Void> voidResponse = endcSetup();
116 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
121 public void x2SetupTest() {
122 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.X2_SETUP_METHOD);
123 logger.info("Invoking {}", uri);
124 SetupRequest setup = new SetupRequest().ranName(E2ManagerMockConfiguration.MOCK_RAN_NAME);
125 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
126 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.POST, entity,
128 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
132 // Aka big--button test
134 public void nodebShutdownPutTest() {
135 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_SHUTDOWN_METHOD);
136 logger.info("Invoking {}", uri);
137 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
138 logger.debug("nodebPutTest: response {}", voidResponse);
139 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
143 public void resetTest() {
144 ResponseEntity<Void> voidResponse = reset();
145 logger.debug("resetTest: response {}", voidResponse);
146 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());