28de9da3e3d6adee952d3827918b759139dd3637
[portal/ric-dashboard.git] / dashboard / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / controller / E2ManagerControllerTest.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
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.List;
25
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;
43
44 public class E2ManagerControllerTest extends AbstractControllerTest {
45
46         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
47
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);
56         }
57
58         @Test
59         public void resetTest() {
60                 ResponseEntity<Void> voidResponse = reset();
61                 logger.debug("resetTest: response {}", voidResponse);
62                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
63         }
64
65         @Test
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());
71         }
72
73         @Test
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());
80         }
81
82         @Test
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>>() {
89                                 });
90                 Assertions.assertFalse(response.getBody().isEmpty());
91         }
92
93         @Test
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>>() {
100                                 });
101                 Assertions.assertFalse(response.getBody().isEmpty());
102         }
103
104         @Test
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());
112         }
113
114         // Aka big--button test, run this last
115         @After
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());
123         }
124
125 }