328a5ad53a037898531eb9c1318832f61f133007
[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.UpdateGnbRequest;
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         public void updateGnb() {
53                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
54                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX, "nobeb");
55                 logger.info("Invoking {}", uri);
56                 UpdateGnbRequest update = new UpdateGnbRequest();
57                 HttpEntity<UpdateGnbRequest> entity = new HttpEntity<>(update);
58                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, entity,
59                                 Void.class);
60                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
61         }
62
63         @Test
64         @Order(1)
65         public void versionTest() {
66                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
67                 logger.info("Invoking {}", uri);
68                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
69                 Assertions.assertFalse(st.getData().toString().isEmpty());
70         }
71
72         @Test
73         @Order(2)
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         @Order(3)
84         public void ranDetailsTest() {
85                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
86                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.RAN_METHOD);
87                 logger.info("Invoking {}", uri);
88                 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
89                                 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
90                                 });
91                 Assertions.assertFalse(response.getBody().isEmpty());
92         }
93
94         @Test
95         @Order(4)
96         public void nodebListTest() {
97                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
98                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_LIST_METHOD);
99                 logger.info("Invoking {}", uri);
100                 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
101                                 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
102                                 });
103                 Assertions.assertFalse(response.getBody().isEmpty());
104         }
105
106         @Test
107         @Order(5)
108         public void nodebStatusTest() {
109                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
110                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX,
111                                 E2ManagerMockConfiguration.RAN_NAME_1);
112                 logger.info("Invoking {}", uri);
113                 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
114                 Assertions.assertNotNull(response.getRanName());
115         }
116
117         // Aka big--button test, run this last
118         @Test
119         @Order(6)
120         public void nodebShutdownPutTest() {
121                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
122                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_SHUTDOWN_METHOD);
123                 logger.info("Invoking {}", uri);
124                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
125                 logger.debug("nodebPutTest: response {}", voidResponse);
126                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
127         }
128
129 }