Add tests to improve code-coverage stats in Sonar
[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.MethodOrderer;
28 import org.junit.jupiter.api.Order;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.TestMethodOrder;
31 import org.oransc.ric.portal.dashboard.DashboardConstants;
32 import org.oransc.ric.portal.dashboard.config.E2ManagerMockConfiguration;
33 import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
34 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
35 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
36 import org.oransc.ricplt.e2mgr.client.model.GetNodebResponse;
37 import org.oransc.ricplt.e2mgr.client.model.NodebIdentity;
38 import org.oransc.ricplt.e2mgr.client.model.ResetRequest;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.core.ParameterizedTypeReference;
42 import org.springframework.http.HttpEntity;
43 import org.springframework.http.HttpMethod;
44 import org.springframework.http.ResponseEntity;
45
46 @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
47 public class E2ManagerControllerTest extends AbstractControllerTest {
48
49         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
50
51         @Test
52         @Order(1)
53         public void versionTest() {
54                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
55                 logger.info("Invoking {}", uri);
56                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
57                 Assertions.assertFalse(st.getData().toString().isEmpty());
58         }
59
60         @Test
61         @Order(2)
62         public void healthTest() {
63                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
64                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.HEALTH_METHOD);
65                 logger.info("Invoking {}", uri);
66                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
67                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
68         }
69
70         @Test
71         @Order(3)
72         public void ranDetailsTest() {
73                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
74                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.RAN_METHOD);
75                 logger.info("Invoking {}", uri);
76                 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
77                                 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
78                                 });
79                 Assertions.assertFalse(response.getBody().isEmpty());
80         }
81
82         @Test
83         @Order(4)
84         public void nodebListTest() {
85                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
86                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_LIST_METHOD);
87                 logger.info("Invoking {}", uri);
88                 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
89                                 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
90                                 });
91                 Assertions.assertFalse(response.getBody().isEmpty());
92         }
93
94         @Test
95         @Order(5)
96         public void nodebStatusTest() {
97                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
98                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX,
99                                 E2ManagerMockConfiguration.RAN_NAME_1);
100                 logger.info("Invoking {}", uri);
101                 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
102                 Assertions.assertNotNull(response.getRanName());
103         }
104
105         // This empties the list of RAN elements
106         @Test
107         @Order(6)
108         public void resetTest() {
109                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
110                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX, "ignored",
111                                 E2ManagerController.RESET_METHOD);
112                 logger.info("Invoking {}", uri);
113                 ResetRequest reset = new ResetRequest();
114                 HttpEntity<ResetRequest> entity = new HttpEntity<>(reset);
115                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity, Void.class);
116                 logger.debug("resetTest: response {}", voidResponse);
117                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
118         }
119
120         // Aka big--button test, run this last
121         @Test
122         @Order(7)
123         public void nodebShutdownPutTest() {
124                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
125                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_SHUTDOWN_METHOD);
126                 logger.info("Invoking {}", uri);
127                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
128                 logger.debug("nodebPutTest: response {}", voidResponse);
129                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
130         }
131
132 }