Move mock configurations to test area
[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.SetupRequest;
31 import org.oransc.ric.portal.dashboard.model.RanDetailsTransport;
32 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.core.ParameterizedTypeReference;
36 import org.springframework.http.HttpEntity;
37 import org.springframework.http.HttpMethod;
38 import org.springframework.http.ResponseEntity;
39
40 public class E2ManagerControllerTest extends AbstractControllerTest {
41
42         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
43
44         @Test
45         public void versionTest() {
46                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.VERSION_METHOD);
47                 logger.info("Invoking {}", uri);
48                 SuccessTransport st = restTemplate.getForObject(uri, SuccessTransport.class);
49                 Assertions.assertFalse(st.getData().toString().isEmpty());
50         }
51
52         @Test
53         public void healthTest() {
54                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.HEALTH_METHOD);
55                 logger.info("Invoking {}", uri);
56                 ResponseEntity<Void> voidResponse = restTemplate.getForEntity(uri, Void.class);
57                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
58         }
59
60         @Test
61         public void ranDetailsTest() {
62                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.RAN_METHOD);
63                 logger.info("Invoking {}", uri);
64                 ResponseEntity<List<RanDetailsTransport>> response = testRestTemplateStandardRole().exchange(uri,
65                                 HttpMethod.GET, null, new ParameterizedTypeReference<List<RanDetailsTransport>>() {
66                                 });
67                 Assertions.assertFalse(response.getBody().isEmpty());
68         }
69
70         @Test
71         public void nodebListTest() {
72                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_LIST_METHOD);
73                 logger.info("Invoking {}", uri);
74                 ResponseEntity<List<NodebIdentity>> response = testRestTemplateStandardRole().exchange(uri, HttpMethod.GET,
75                                 null, new ParameterizedTypeReference<List<NodebIdentity>>() {
76                                 });
77                 Assertions.assertFalse(response.getBody().isEmpty());
78         }
79
80         @Test
81         public void nodebStatusTest() {
82                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_METHOD, "nodeb");
83                 logger.info("Invoking {}", uri);
84                 GetNodebResponse response = testRestTemplateStandardRole().getForObject(uri, GetNodebResponse.class);
85                 Assertions.assertNotNull(response.getRanName());
86         }
87
88         @Test
89         public void bigRedButtonTest() {
90                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.NODEB_METHOD);
91                 logger.info("Invoking {}", uri);
92                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.DELETE, null,
93                                 Void.class);
94                 Assertions.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 = testRestTemplateAdminRole().exchange(uri, HttpMethod.POST, entity,
104                                 Void.class);
105                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
106         }
107
108         @Test
109         public void x2SetupTest() {
110                 URI uri = buildUri(null, E2ManagerController.CONTROLLER_PATH, E2ManagerController.X2_SETUP_METHOD);
111                 logger.info("Invoking {}", uri);
112                 SetupRequest setup = new SetupRequest();
113                 HttpEntity<SetupRequest> entity = new HttpEntity<>(setup);
114                 ResponseEntity<Void> voidResponse = testRestTemplateAdminRole().exchange(uri, HttpMethod.POST, entity,
115                                 Void.class);
116                 Assertions.assertTrue(voidResponse.getStatusCode().is2xxSuccessful());
117         }
118
119 }