Upgrade to E2Manager API version 4.4.4
[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, Void.class);
59                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
60         }
61
62         @Test
63         @Order(1)
64         public void versionTest() {
65                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
66                 logger.info("Invoking {}", uri);
67                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
68                 Assertions.assertFalse(st.getData().toString().isEmpty());
69         }
70
71         @Test
72         @Order(2)
73         public void healthTest() {
74                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
75                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.HEALTH_METHOD);
76                 logger.info("Invoking {}", uri);
77                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
78                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
79         }
80
81         @Test
82         @Order(3)
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         @Order(4)
95         public void nodebListTest() {
96                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
97                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_LIST_METHOD);
98                 logger.info("Invoking {}", uri);
99                 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
100                                 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
101                                 });
102                 Assertions.assertFalse(response.getBody().isEmpty());
103         }
104
105         @Test
106         @Order(5)
107         public void nodebStatusTest() {
108                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
109                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_PREFIX,
110                                 E2ManagerMockConfiguration.RAN_NAME_1);
111                 logger.info("Invoking {}", uri);
112                 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
113                 Assertions.assertNotNull(response.getRanName());
114         }
115
116         // Aka big--button test, run this last
117         @Test
118         @Order(6)
119         public void nodebShutdownPutTest() {
120                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.RIC_INSTANCE_KEY,
121                                 RICInstanceMockConfiguration.INSTANCE_KEY_1, E2ManagerController.NODEB_SHUTDOWN_METHOD);
122                 logger.info("Invoking {}", uri);
123                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.PUT, null, Void.class);
124                 logger.debug("nodebPutTest: response {}", voidResponse);
125                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
126         }
127
128 }