Extend Mock E2Mgr configuration to save state
[portal/ric-dashboard.git] / 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 and Nokia
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.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;
41
42 public class E2ManagerControllerTest extends AbstractControllerTest {
43
44         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
45
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);
52         }
53
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);
60         }
61
62         @Test
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());
68         }
69
70         @Test
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());
76         }
77
78         @Test
79         public void ranDetailsTest() {
80                 endcSetup();
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>>() {
85                                 });
86                 Assertions.assertFalse(response.getBody().isEmpty());
87                 reset();
88         }
89
90         @Test
91         public void nodebListTest() {
92                 endcSetup();
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>>() {
97                                 });
98                 Assertions.assertFalse(response.getBody().isEmpty());
99                 reset();
100         }
101
102         @Test
103         public void nodebStatusTest() {
104                 endcSetup();
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());
110                 reset();
111         }
112
113         @Test
114         public void endcSetupTest() {
115                 ResponseEntity<Void> voidResponse = endcSetup();
116                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
117                 reset();
118         }
119
120         @Test
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,
127                                 Void.class);
128                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
129                 reset();
130         }
131
132         // Aka big--button test
133         @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());
140         }
141
142         @Test
143         public void resetTest() {
144                 ResponseEntity<Void> voidResponse = reset();
145                 logger.debug("resetTest: response {}", voidResponse);
146                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
147         }
148
149 }