Reorganize dashboard into subfolders
[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.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;
43
44 public class E2ManagerControllerTest extends AbstractControllerTest {
45
46         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
47
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);
55         }
56
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);
65         }
66
67         @Test
68         public void endcSetupTest() {
69                 ResponseEntity<Void> voidResponse = endcSetup();
70                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
71                 reset();
72         }
73
74         @Test
75         public void resetTest() {
76                 ResponseEntity<Void> voidResponse = reset();
77                 logger.debug("resetTest: response {}", voidResponse);
78                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
79         }
80
81         @Test
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());
87         }
88
89         @Test
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());
96         }
97
98         @Test
99         public void ranDetailsTest() {
100                 endcSetup();
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>>() {
106                                 });
107                 Assertions.assertFalse(response.getBody().isEmpty());
108                 reset();
109         }
110
111         @Test
112         public void nodebListTest() {
113                 endcSetup();
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>>() {
119                                 });
120                 Assertions.assertFalse(response.getBody().isEmpty());
121                 reset();
122         }
123
124         @Test
125         public void nodebStatusTest() {
126                 endcSetup();
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());
133                 reset();
134         }
135
136         @Test
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,
144                                 Void.class);
145                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
146                 reset();
147         }
148
149         // Aka big--button test
150         @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());
158         }
159
160 }