Add JUnit tests of backend controllers
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / 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;
21
22 import java.lang.invoke.MethodHandles;
23 import java.net.URI;
24 import java.util.List;
25
26 import org.junit.Assert;
27 import org.junit.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.SetupRequest;
31 import org.oransc.ric.portal.dashboard.controller.E2ManagerController;
32 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
33 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.core.ParameterizedTypeReference;
37 import org.springframework.http.HttpEntity;
38 import org.springframework.http.HttpMethod;
39 import org.springframework.http.ResponseEntity;
40
41 public class E2ManagerControllerTest extends AbstractControllerTest {
42
43         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
44
45         @Test
46         public void versionTest() {
47                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, DashboardConstants.VERSION_METHOD);
48                 logger.info("Invoking {}", uri);
49                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
50                 Assert.assertFalse(st.getData().toString().isEmpty());
51         }
52
53         @Test
54         public void healthTest() {
55                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.HEALTH_METHOD);
56                 logger.info("Invoking {}", uri);
57                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
58                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
59         }
60
61         @Test
62         public void ranDetailsTest() {
63                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.RAN_METHOD);
64                 logger.info("Invoking {}", uri);
65                 ResponseEntity<List<RanDetailsTransport>> response = restTemplate.exchange(uri, HttpMethod.GET, null,
66                                 new ParameterizedTypeReference<List<RanDetailsTransport>>() {
67                                 });
68                 Assert.assertFalse(response.getBody().isEmpty());
69         }
70
71         @Test
72         public void nodebListTest() {
73                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_LIST_METHOD);
74                 logger.info("Invoking {}", uri);
75                 ResponseEntity<List<NodebIdentity>> response = restTemplate.exchange(uri, HttpMethod.GET, null,
76                                 new ParameterizedTypeReference<List<NodebIdentity>>() {
77                                 });
78                 Assert.assertFalse(response.getBody().isEmpty());
79         }
80
81         @Test
82         public void nodebStatusTest() {
83                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_METHOD, "nodeb");
84                 logger.info("Invoking {}", uri);
85                 GetNodebResponse response = restTemplate.getForObject(uri, GetNodebResponse.class);
86                 Assert.assertNotNull(response.getRanName());
87         }
88
89         @Test
90         public void bigRedButtonTest() {
91                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_METHOD);
92                 logger.info("Invoking {}", uri);
93                 ResponseEntity<Void> voidResponse = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class);
94                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
95         }
96
97         @Test
98         public void endcSetupTest() {
99                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.ENDC_SETUP_METHOD);
100                 logger.info("Invoking {}", uri);
101                 SetupRequest setup = new SetupRequest();
102                 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
103                 ResponseEntity<Void> voidResponse = restTemplate.exchange(uri, HttpMethod.POST, entity, Void.class);
104                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
105         }
106
107         @Test
108         public void x2SetupTest() {
109                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.X2_SETUP_METHOD);
110                 logger.info("Invoking {}", uri);
111                 SetupRequest setup = new SetupRequest();
112                 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
113                 ResponseEntity<Void> voidResponse = restTemplate.exchange(uri, HttpMethod.POST, entity, Void.class);
114                 Assert.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
115         }
116
117 }